Skip to content

Commit 13445ba

Browse files
committed
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)
1 parent 7a81803 commit 13445ba

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

lang/c/pseudoc.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,9 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
13101310
std::optional<string> assignUpdateOperator;
13111311
std::optional<HighLevelILInstruction> assignUpdateSource;
13121312
bool assignUpdateNegate = false;
1313-
const auto isSplit = destExpr.operation == HLIL_SPLIT;
1313+
const auto destIsSplit = destExpr.operation == HLIL_SPLIT;
13141314
std::optional<bool> assignSignedHint;
1315-
if (isSplit)
1315+
if (destIsSplit)
13161316
{
13171317
const auto high = destExpr.GetHighExpr<HLIL_SPLIT>();
13181318
const auto low = destExpr.GetLowExpr<HLIL_SPLIT>();
@@ -1328,6 +1328,23 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
13281328
tokens.NewLine();
13291329
GetExprTextInternal(low, tokens, settings, precedence);
13301330
}
1331+
else if (srcExpr.operation == HLIL_SPLIT)
1332+
{
1333+
const auto high = srcExpr.GetHighExpr<HLIL_SPLIT>();
1334+
const auto low = srcExpr.GetLowExpr<HLIL_SPLIT>();
1335+
GetExprTextInternal(destExpr, tokens, settings, precedence);
1336+
tokens.Append(OperationToken, " = ");
1337+
tokens.AppendOpenParen();
1338+
GetExprTextInternal(high, tokens, settings, precedence);
1339+
tokens.Append(OperationToken, " << ");
1340+
tokens.Append(IntegerToken, std::to_string(low.size * 8));
1341+
tokens.AppendCloseParen();
1342+
tokens.Append(OperationToken, " | ");
1343+
GetExprTextInternal(low, tokens, settings, precedence);
1344+
tokens.AppendSemicolon();
1345+
tokens.NewLine();
1346+
return;
1347+
}
13311348
else
13321349
{
13331350
// Check for assignment with an operator on the same variable as the destination
@@ -1454,7 +1471,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
14541471
appearsDead = false;
14551472
}
14561473

1457-
if (isSplit)
1474+
if (destIsSplit)
14581475
{
14591476
// const auto high = destExpr.GetHighExpr<HLIL_SPLIT>();
14601477
const auto low = destExpr.GetLowExpr<HLIL_SPLIT>();
@@ -1484,7 +1501,7 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H
14841501
GetExprTextInternal(srcExpr, tokens, settings, AssignmentOperatorPrecedence, false, assignSignedHint);
14851502
}
14861503

1487-
if (isSplit)
1504+
if (destIsSplit)
14881505
tokens.AppendCloseParen();
14891506

14901507
if (appearsDead)

lang/rust/pseudorust.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,9 +1371,9 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
13711371
std::optional<string> assignUpdateOperator;
13721372
std::optional<HighLevelILInstruction> assignUpdateSource;
13731373
bool assignUpdateNegate = false;
1374-
const auto isSplit = destExpr.operation == HLIL_SPLIT;
1374+
const auto destIsSplit = destExpr.operation == HLIL_SPLIT;
13751375
std::optional<bool> assignSignHint;
1376-
if (isSplit)
1376+
if (destIsSplit)
13771377
{
13781378
const auto high = destExpr.GetHighExpr<HLIL_SPLIT>();
13791379
const auto low = destExpr.GetLowExpr<HLIL_SPLIT>();
@@ -1389,6 +1389,23 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
13891389
tokens.NewLine();
13901390
GetExprText(low, tokens, settings, precedence);
13911391
}
1392+
else if (srcExpr.operation == HLIL_SPLIT)
1393+
{
1394+
const auto high = srcExpr.GetHighExpr<HLIL_SPLIT>();
1395+
const auto low = srcExpr.GetLowExpr<HLIL_SPLIT>();
1396+
GetExprText(destExpr, tokens, settings, precedence);
1397+
tokens.Append(OperationToken, " = ");
1398+
tokens.AppendOpenParen();
1399+
GetExprText(high, tokens, settings, precedence);
1400+
tokens.Append(OperationToken, " << ");
1401+
tokens.Append(IntegerToken, std::to_string(low.size * 8));
1402+
tokens.AppendCloseParen();
1403+
tokens.Append(OperationToken, " | ");
1404+
GetExprText(low, tokens, settings, precedence);
1405+
tokens.AppendSemicolon();
1406+
tokens.NewLine();
1407+
return;
1408+
}
13921409
else
13931410
{
13941411
// Check for assignment with an operator on the same variable as the destination
@@ -1515,7 +1532,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
15151532
appearsDead = false;
15161533
}
15171534

1518-
if (isSplit)
1535+
if (destIsSplit)
15191536
{
15201537
// const auto high = destExpr.GetHighExpr<HLIL_SPLIT>();
15211538
const auto low = destExpr.GetLowExpr<HLIL_SPLIT>();
@@ -1545,7 +1562,7 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe
15451562
GetExprText(srcExpr, tokens, settings, AssignmentOperatorPrecedence, InnerExpression, assignSignHint);
15461563
}
15471564

1548-
if (isSplit)
1565+
if (destIsSplit)
15491566
tokens.AppendCloseParen();
15501567

15511568
if (appearsDead)

0 commit comments

Comments
 (0)