Skip to content

Commit 9bd77ec

Browse files
committed
Add cast to partial var accesses in pseudo C/Rust
Add casts to HLIL_STRUCT_FIELD expressions where the size of the source expression is greater than the size of access
1 parent a90cbb9 commit 9bd77ec

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lang/c/pseudoc.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,15 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
16181618
tokens.Append(OperationToken, "&");
16191619
}
16201620
}
1621+
else if ((!settings || settings->IsOptionSet(ShowTypeCasts)) && srcExpr.operation == HLIL_VAR)
1622+
{
1623+
if (srcExpr.GetType() && srcExpr.GetType()->GetClass() != StructureTypeClass && srcExpr.size > instr.size)
1624+
{
1625+
tokens.AppendOpenParen();
1626+
AppendSizeToken(instr.size, false, tokens);
1627+
tokens.AppendCloseParen();
1628+
}
1629+
}
16211630

16221631
GetExprTextInternal(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);
16231632
}

lang/rust/pseudorust.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,16 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
16891689
castedSrcExpr = true;
16901690
}
16911691
}
1692+
else if ((!settings || settings->IsOptionSet(ShowTypeCasts)) && srcExpr.operation == HLIL_VAR)
1693+
{
1694+
if (srcExpr.GetType() && srcExpr.GetType()->GetClass() != StructureTypeClass && srcExpr.size > instr.size)
1695+
{
1696+
GetExprText(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);
1697+
tokens.Append(KeywordToken, " as ");
1698+
AppendSizeToken(instr.size, false, tokens);
1699+
castedSrcExpr = true;
1700+
}
1701+
}
16921702

16931703
if (!castedSrcExpr)
16941704
GetExprText(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence);

0 commit comments

Comments
 (0)