diff options
| author | Brandon Miller <brandon@vector35.com> | 2025-04-15 14:20:58 -0400 |
|---|---|---|
| committer | Brandon Miller <brandon@vector35.com> | 2025-04-15 15:10:16 -0400 |
| commit | 5e1a86395a959f9902d63c9504cdfc6cd07847a3 (patch) | |
| tree | a9566b6122e9c5a81d66e9be3b6a5443e0c4bfae /lang | |
| parent | a6f64bf19f966f5ecbaab0a9eff85ecbaa573317 (diff) | |
Cast on indexed array assignments in pseudo C/Rust
Diffstat (limited to 'lang')
| -rw-r--r-- | lang/c/pseudoc.cpp | 15 | ||||
| -rw-r--r-- | lang/rust/pseudorust.cpp | 23 |
2 files changed, 37 insertions, 1 deletions
diff --git a/lang/c/pseudoc.cpp b/lang/c/pseudoc.cpp index 8ab07a75..b91b8e71 100644 --- a/lang/c/pseudoc.cpp +++ b/lang/c/pseudoc.cpp @@ -1604,6 +1604,21 @@ void PseudoCFunction::GetExprTextInternal(const HighLevelILInstruction& instr, H } else { + if ((!settings || settings->IsOptionSet(ShowTypeCasts)) && srcExpr.operation == HLIL_ARRAY_INDEX) + { + auto arrayIndexExpr = srcExpr.GetSourceExpr<HLIL_ARRAY_INDEX>(); + if (arrayIndexExpr.operation == HLIL_VAR && + arrayIndexExpr.GetType()->GetChildType()->GetWidth() < instr.size) + { + tokens.Append(TextToken, "*"); + tokens.AppendOpenParen(); + AppendSizeToken(instr.size, false, tokens); + tokens.Append(TextToken, "*"); + tokens.AppendCloseParen(); + tokens.Append(OperationToken, "&"); + } + } + GetExprTextInternal(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence); } diff --git a/lang/rust/pseudorust.cpp b/lang/rust/pseudorust.cpp index 1aeae158..80858658 100644 --- a/lang/rust/pseudorust.cpp +++ b/lang/rust/pseudorust.cpp @@ -1670,7 +1670,28 @@ void PseudoRustFunction::GetExprText(const HighLevelILInstruction& instr, HighLe } else { - GetExprText(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence); + bool castedSrcExpr = false; + if ((!settings || settings->IsOptionSet(ShowTypeCasts)) && srcExpr.operation == HLIL_ARRAY_INDEX) + { + auto arrayIndexExpr = srcExpr.GetSourceExpr<HLIL_ARRAY_INDEX>(); + if (arrayIndexExpr.operation == HLIL_VAR && + arrayIndexExpr.GetType()->GetChildType()->GetWidth() < instr.size) + { + tokens.Append(TextToken, "*"); + tokens.AppendOpenParen(); + tokens.Append(OperationToken, "&"); + GetExprText(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence); + tokens.Append(KeywordToken, " as "); + tokens.Append(TextToken, "*"); + tokens.Append(KeywordToken, "mut "); + AppendSizeToken(instr.size, false, tokens); + tokens.AppendCloseParen(); + castedSrcExpr = true; + } + } + + if (!castedSrcExpr) + GetExprText(srcExpr, tokens, settings, MemberAndFunctionOperatorPrecedence); } AppendFieldTextTokens(srcExpr, fieldOffset, memberIndex, instr.size, tokens, false); |
