diff options
| author | Brandon Miller <brandon@vector35.com> | 2025-04-14 10:10:42 -0400 |
|---|---|---|
| committer | Brandon Miller <brandon@vector35.com> | 2025-04-15 15:10:16 -0400 |
| commit | 13445bad31b60db063d454fefa6d6697889f428d (patch) | |
| tree | 587f94fff698fc83c4c79ed5e7ef3f18eaaf250e | |
| parent | 7a818034c7952a7219043c6fd548b01c95495410 (diff) | |
Handle var assign with split src in pseudo C/Rust
Fixes issue with absent rhs when the instruction is HLIL_ASSIGN with a
source expression of HLIL_SPLIT (var_60.q = r1:r0)
| -rw-r--r-- | lang/c/pseudoc.cpp | 25 | ||||
| -rw-r--r-- | lang/rust/pseudorust.cpp | 25 |
2 files changed, 42 insertions, 8 deletions
diff --git a/lang/c/pseudoc.cpp b/lang/c/pseudoc.cpp index ac1fe3bb..55a3c2c1 100644 --- a/lang/c/pseudoc.cpp +++ b/lang/c/pseudoc.cpp @@ -1310,9 +1310,9 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H std::optional<string> assignUpdateOperator; std::optional<HighLevelILInstruction> assignUpdateSource; bool assignUpdateNegate = false; - const auto isSplit = destExpr.operation == HLIL_SPLIT; + const auto destIsSplit = destExpr.operation == HLIL_SPLIT; std::optional<bool> assignSignedHint; - if (isSplit) + if (destIsSplit) { const auto high = destExpr.GetHighExpr<HLIL_SPLIT>(); const auto low = destExpr.GetLowExpr<HLIL_SPLIT>(); @@ -1328,6 +1328,23 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H tokens.NewLine(); GetExprTextInternal(low, tokens, settings, precedence); } + else if (srcExpr.operation == HLIL_SPLIT) + { + const auto high = srcExpr.GetHighExpr<HLIL_SPLIT>(); + const auto low = srcExpr.GetLowExpr<HLIL_SPLIT>(); + GetExprTextInternal(destExpr, tokens, settings, precedence); + tokens.Append(OperationToken, " = "); + tokens.AppendOpenParen(); + GetExprTextInternal(high, tokens, settings, precedence); + tokens.Append(OperationToken, " << "); + tokens.Append(IntegerToken, std::to_string(low.size * 8)); + tokens.AppendCloseParen(); + tokens.Append(OperationToken, " | "); + GetExprTextInternal(low, tokens, settings, precedence); + tokens.AppendSemicolon(); + tokens.NewLine(); + return; + } else { // Check for assignment with an operator on the same variable as the destination @@ -1454,7 +1471,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H appearsDead = false; } - if (isSplit) + if (destIsSplit) { // const auto high = destExpr.GetHighExpr<HLIL_SPLIT>(); const auto low = destExpr.GetLowExpr<HLIL_SPLIT>(); @@ -1484,7 +1501,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H GetExprTextInternal(srcExpr, tokens, settings, AssignmentOperatorPrecedence, false, assignSignedHint); } - if (isSplit) + if (destIsSplit) tokens.AppendCloseParen(); if (appearsDead) diff --git a/lang/rust/pseudorust.cpp b/lang/rust/pseudorust.cpp index 300297dc..e3f661fa 100644 --- a/lang/rust/pseudorust.cpp +++ b/lang/rust/pseudorust.cpp @@ -1371,9 +1371,9 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe std::optional<string> assignUpdateOperator; std::optional<HighLevelILInstruction> assignUpdateSource; bool assignUpdateNegate = false; - const auto isSplit = destExpr.operation == HLIL_SPLIT; + const auto destIsSplit = destExpr.operation == HLIL_SPLIT; std::optional<bool> assignSignHint; - if (isSplit) + if (destIsSplit) { const auto high = destExpr.GetHighExpr<HLIL_SPLIT>(); const auto low = destExpr.GetLowExpr<HLIL_SPLIT>(); @@ -1389,6 +1389,23 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe tokens.NewLine(); GetExprText(low, tokens, settings, precedence); } + else if (srcExpr.operation == HLIL_SPLIT) + { + const auto high = srcExpr.GetHighExpr<HLIL_SPLIT>(); + const auto low = srcExpr.GetLowExpr<HLIL_SPLIT>(); + GetExprText(destExpr, tokens, settings, precedence); + tokens.Append(OperationToken, " = "); + tokens.AppendOpenParen(); + GetExprText(high, tokens, settings, precedence); + tokens.Append(OperationToken, " << "); + tokens.Append(IntegerToken, std::to_string(low.size * 8)); + tokens.AppendCloseParen(); + tokens.Append(OperationToken, " | "); + GetExprText(low, tokens, settings, precedence); + tokens.AppendSemicolon(); + tokens.NewLine(); + return; + } else { // Check for assignment with an operator on the same variable as the destination @@ -1515,7 +1532,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe appearsDead = false; } - if (isSplit) + if (destIsSplit) { // const auto high = destExpr.GetHighExpr<HLIL_SPLIT>(); const auto low = destExpr.GetLowExpr<HLIL_SPLIT>(); @@ -1545,7 +1562,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe GetExprText(srcExpr, tokens, settings, AssignmentOperatorPrecedence, InnerExpression, assignSignHint); } - if (isSplit) + if (destIsSplit) tokens.AppendCloseParen(); if (appearsDead) |
