Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
5c023fc
Make decompiler.py more generic
bluesadi Nov 2, 2023
cc2838b
Merge with latest angr
bluesadi Feb 1, 2024
cd91e17
Add type translator for Rust
bluesadi Nov 21, 2023
0b360ff
Add function type translation
bluesadi Nov 21, 2023
d1d10de
Working on type translation
bluesadi Nov 22, 2023
1af36db
Fix some bugs in type translation
bluesadi Nov 26, 2023
0461eab
Add alloc_simplifier.py
bluesadi Dec 5, 2023
04dd47f
Fix some bugs
bluesadi Jan 24, 2024
c81ff53
* Convert C infinite loops into Rust infinite loops
bluesadi Jan 30, 2024
9d4d4d2
Make RustSimType system compatible with original SimType system
bluesadi Jan 31, 2024
5944989
Fix some type translation problems
bluesadi Feb 1, 2024
d9054af
Improve type translation further
bluesadi Feb 2, 2024
c3524ab
Add RustInfiniteLoop handler in StructuredCodeWalker
bluesadi Feb 2, 2024
d888d51
Minor fix
bluesadi Feb 6, 2024
65a036e
Add StringSimplifier
bluesadi Feb 11, 2024
e203995
Move optimization passes to angr/rust
bluesadi Feb 12, 2024
b206f6b
Move sim_type to angr/rust
bluesadi Feb 12, 2024
bccfbdd
Move typehoon related files to angr/rust
bluesadi Feb 12, 2024
2ac4ea5
Refine StringSimplifier
bluesadi Mar 12, 2024
f4224e8
Fix optimization_passes/init.py
bluesadi Mar 12, 2024
762c797
Initial implementation of AllocaSimplifier
bluesadi Mar 23, 2024
789ba9f
Fix some bugs in alloc_simplifier.py
bluesadi Mar 26, 2024
53ed97d
Implemented AllocSimplifier
bluesadi Apr 2, 2024
eef6a2d
Disable inlined_strcpy optimization for Rust binary
bluesadi Apr 3, 2024
d2e03ac
Disable ReturnDuplicator for Rust decompilation
bluesadi Apr 3, 2024
1b12954
Separate RustSimTypeStr and RustSimTypeString
bluesadi Apr 3, 2024
ca03df1
Move StringSimplifier before VariableRecovery
bluesadi Apr 3, 2024
f5119aa
Implement DeallocSimplifier
bluesadi Apr 3, 2024
2799513
Refactor AllocSimplifier
bluesadi Apr 15, 2024
0c44e6a
Add Vec recovery in AllocSimplifier
bluesadi Apr 15, 2024
f614a76
Integrated RustCall statement into VariableRecoveryFast
bluesadi Apr 30, 2024
6b6b6ee
VariableRecovery and Typehoon now supports recover Rust types from fu…
bluesadi May 7, 2024
4417bb0
JunkRemover now removes alloc::alloc::handle_alloc_error and __rust_d…
bluesadi May 7, 2024
736e1ce
Add LibFunctionIdentifier
bluesadi May 9, 2024
4c10042
Remove RustCall
bluesadi May 9, 2024
2f23e4d
Add pre-defined Rust standard function prototypes
bluesadi May 17, 2024
b34bd4f
Start supporting array type for Rust
bluesadi May 27, 2024
881a030
Add pre-defined prototypes with Struct arguments
bluesadi May 31, 2024
79f0aa7
Change RustSimTypePointer to RustSimTypeReference
bluesadi Jun 3, 2024
d8018c3
Pre-define some structs
bluesadi Jun 3, 2024
711e678
Add ArrayReference and StrReference. RustCodeGenerator supports both …
bluesadi Jun 5, 2024
f79b8b1
Add None pointer support for Option
bluesadi Jun 6, 2024
8376c78
Support struct return value
bluesadi Jun 7, 2024
4e3808a
Create new variables for stack arguments at the same location of diff…
bluesadi Jun 17, 2024
e1f3281
Recover struct instantiation
bluesadi Jun 18, 2024
7b17286
Fix a Rust calling convention problem
bluesadi Jun 21, 2024
d2873dd
Fix some bugs
bluesadi Jun 24, 2024
8a31f30
Refine JunkRemover and add TransformationPass as an extension of Opti…
bluesadi Jul 13, 2024
28a76f3
Implement the prototype of OwnershipTransferSimplifier
bluesadi Jul 20, 2024
ca2f00f
Introduce better Rust demangler
bluesadi Jul 21, 2024
6e4bb89
Improve AllocSimplifier
bluesadi Jul 26, 2024
d50b15e
Create UnwrapSimplifier (But it's not completed yet)
bluesadi Aug 2, 2024
a3dd028
Add special handling for Rust calling convention - return type is struct
bluesadi Aug 2, 2024
a658a99
Add special handling for Rust calling convention - class member function
bluesadi Aug 3, 2024
5d6095f
Fix RustSimStruct with_arch bug
bluesadi Aug 3, 2024
1ca46ab
Fix struct instantiation recovery
bluesadi Aug 4, 2024
8ff9823
Reorganize some simplification passes
bluesadi Aug 7, 2024
0df7b07
Rename CallsiteMaker to StructInstantiationSimplifier
bluesadi Aug 7, 2024
1b5fc7d
Improve OwnershipSimplifier and create CallingConventionRecovery
bluesadi Aug 9, 2024
c58c8d1
Initial version of RetSiteSimplifier
bluesadi Aug 21, 2024
0658f88
Fix some bug in AllocSimplifier
bluesadi Aug 21, 2024
80222d8
Initial version of RustCallingConvention analysis
bluesadi Aug 26, 2024
947e1e9
Fix a bug
bluesadi Aug 26, 2024
36bd1f1
Enable alloc_simplifier
bluesadi Sep 5, 2024
4d0e13a
Refine Rust function name normalizing
bluesadi Sep 9, 2024
af73c22
Reimplement struct_instantiation_simplifier.py based on SSA reaching …
bluesadi Sep 18, 2024
2196ddf
StructInstantiationSimplifier now supports recursive simplification
bluesadi Sep 18, 2024
e9a4d32
Move StructInstantiationSimplifier to stage AFTER_GLOBAL_SIMPLIFICATION
bluesadi Sep 19, 2024
c86c9d3
Introduce CallsiteCorrector to fix function call with struct return type
bluesadi Sep 19, 2024
1cad2ab
Implement DropSimplifier as a optimization pass after structuring
bluesadi Sep 20, 2024
5f8435a
Introduce drop simplifier
bluesadi Sep 20, 2024
dffc320
Fix UnwrapSimplifier and stack slots reuse problem
bluesadi Sep 25, 2024
8165c57
Reimplemented OwnershipSimplifier
bluesadi Sep 26, 2024
a44a9c6
Refine RustCallingConventionAnalysis
bluesadi Oct 1, 2024
ee96682
Reimplemented CleanupCodeRemover
bluesadi Oct 1, 2024
6d9e19b
Reimplemented AllocSimplifier
bluesadi Oct 3, 2024
8ccf206
Remove error handling related blocks in AllocSimplifier
bluesadi Oct 7, 2024
dd14420
Fix compatibility issues with decompilation preset feature
bluesadi Oct 7, 2024
4c52d0c
Make CleanupCodeRemover able to handle for-loop-drop pattern
bluesadi Oct 7, 2024
172b559
Fix the prototype definition for alloc::fmt::format::format_inner
bluesadi Oct 8, 2024
a11a3e3
Introduce RustSimEnum (but it doesn't have a lot of impact now)
bluesadi Oct 8, 2024
71e60f1
RustCallingConventionAnalysis now can infer function prototype based …
bluesadi Oct 9, 2024
843a9c7
Reimplemented OwnershipSimplifier
bluesadi Oct 10, 2024
555181a
Delete unused passes
bluesadi Oct 10, 2024
0789332
Fix some bugs in CleanupCodeRemover and OwnershipSimplifier
bluesadi Oct 11, 2024
8ded6ab
Fix a bug in RustCallingConventionRecovery
bluesadi Oct 12, 2024
5abae29
Fix RustStructuredCodeGenerator compatability issue with VEXCCallExpr…
bluesadi Oct 19, 2024
f1ddf14
Fix typo
bluesadi Oct 29, 2024
79e62e2
Support let match operations on Option<T>
bluesadi Nov 7, 2024
b6d999d
Fix Rust empty string literal representation issue
bluesadi Nov 8, 2024
3692c3d
Implement PrintMacroSimplifier
bluesadi Nov 10, 2024
178eeab
Fix: SRDA can't find vvar value
bluesadi Nov 10, 2024
998be1c
Fix a Rust function prototype normalization bug
bluesadi Nov 11, 2024
a2138ee
Implement AllocSimplifier for vec!
bluesadi Nov 11, 2024
1895f52
Rust function prototype inference now infers types through paths in c…
bluesadi Nov 12, 2024
288b6f5
Rust function prototype inference can infer Result<T, E> type now
bluesadi Nov 14, 2024
038f4c7
Fix some bugs after rebasing
bluesadi Nov 14, 2024
0237410
Implement Rust pattern match recovery
bluesadi Nov 16, 2024
c77fb2b
Fix some bugs in pattern match recovery and remove the old Option typ…
bluesadi Nov 16, 2024
cb81139
RustSimTypeOption is not RustSimStruct
bluesadi Nov 16, 2024
ef0cfb5
Fix some bugs
bluesadi Nov 18, 2024
fde2720
Implemented StrArgumentSimplifier
bluesadi Nov 19, 2024
4bc4d43
Implemented SecurityCheckRemover
bluesadi Nov 19, 2024
6efdf8f
Remove Vec expression
bluesadi Nov 19, 2024
8d12824
Implemented VecIndexingSimplifier
bluesadi Nov 21, 2024
4eb3af7
Implemented StructFieldAccessSimplifier, but I don't know if it works…
bluesadi Nov 24, 2024
2227dae
Initial version of StructReturnSimplifier
bluesadi Nov 25, 2024
776af5f
Initial version of DerefCoercionSimplifier
bluesadi Nov 25, 2024
a352096
DerefCoercionSimplifier now supports O3 optimization
bluesadi Nov 25, 2024
b7d40f6
Rewrite part of OwnershipSimplifier with mixins
bluesadi Nov 26, 2024
859a196
Extend PrintMacroSimplifier to eprint and format
bluesadi Nov 29, 2024
5f39a4d
Enable CleanupCodeRemover for RustCallingConventionAnalysis
bluesadi Nov 29, 2024
d5f751f
Fix a bug in StrArgumentSimplifier
bluesadi Dec 1, 2024
e3b62ae
StructInstantiationSimplifier can infer potential concrete struct typ…
bluesadi Dec 3, 2024
470383a
StructReturnSimplifier: Change to a post-structuring pass
bluesadi Dec 3, 2024
d6921ab
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
d2b58d8
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
b0229bd
PrintMacroSimplifier: Add more target functions
bluesadi Dec 4, 2024
cae84c8
Refine StructReturnSimplifier
bluesadi Dec 5, 2024
509ce5a
UnwrapSimplifier is back now
bluesadi Dec 6, 2024
5af375c
Fix some bugs
bluesadi Dec 7, 2024
41ff4a3
OwnershipSimplifier: Add a workaround to handle the case where Store …
bluesadi Dec 12, 2024
6b8eff5
Fix some bugs caused by rebasing
bluesadi Dec 19, 2024
061c6d5
Implement VecMacroSimplifier
bluesadi Dec 19, 2024
7c73866
Introduce IfLetNode
bluesadi Dec 21, 2024
880ead7
Assign FunctionPrototypeInference result to function
bluesadi Dec 25, 2024
cff6018
Introduce StringLiteral expression and fix DerefCoercionSimplifier
bluesadi Dec 31, 2024
24e4364
Rewrite StructReturnSimplifier
bluesadi Jan 2, 2025
786a036
StructReturnSimplifier: Support enum return type now
bluesadi Jan 2, 2025
47c49e3
Fix some StructInstantiationSimplifier bug
bluesadi Jan 6, 2025
ccef75d
Some update
bluesadi Jan 6, 2025
74e6d1a
SequenceWalker: Support if-let node
bluesadi Jan 6, 2025
fbee733
Fix RustSimEnum size calculation bug
bluesadi Jan 7, 2025
f741fdb
Fix PrintMacroSimplifier
bluesadi Jan 7, 2025
6c03c78
Fix StrArgumentSimplifier decode string check problem
bluesadi Jan 7, 2025
551725e
Move some passes to RustSpecificSimplification
bluesadi Jan 8, 2025
9854e78
Fix Struct size problem
bluesadi Jan 8, 2025
5b9253d
Fix a lot of bugs
bluesadi Jan 8, 2025
8964e75
Add more security checks
bluesadi Jan 8, 2025
730e79d
Fix SwitchCase code generation
bluesadi Jan 9, 2025
df43a16
Implement ShowMacroSimplifier
bluesadi Jan 9, 2025
dcf47d8
Fix phi issue
bluesadi Jan 9, 2025
3c95dd9
Remove the incorrect import of Conditional from sqlalchemy.
ltfish Jan 9, 2025
86e0a00
damn
ltfish Jan 9, 2025
fec02ef
Fix some shit
bluesadi Jan 9, 2025
fd83a4a
Fix bugs in _update_phi_variables_after_removing_block.
ltfish Jan 9, 2025
4dabb0d
OwnershipSimplifier: ins_addrs of block statements must monotonically…
ltfish Jan 9, 2025
6220727
Fix some shit
bluesadi Jan 9, 2025
26b6212
Fix some shit
bluesadi Jan 10, 2025
40536fc
Fix some shit
bluesadi Jan 10, 2025
c26aae0
Fix some shit
bluesadi Jan 10, 2025
cf76a06
Fix some bugs caused by rebasing
bluesadi Feb 24, 2025
be6d8ce
Rewrite RustCallConvention analysis and delete two unused simplificat…
bluesadi Feb 26, 2025
24f9ea7
Introduce PrePatternMatchSimplifier to duplicate return blocks to pre…
bluesadi Feb 28, 2025
de24c7f
Rewrite RustCallingConventionAnalysis
bluesadi Mar 22, 2025
25f749a
Introduce StructMemoryLayout analysis
bluesadi Mar 28, 2025
6498c0f
Implement LayoutInference for Arguments & Fix some bugs after new ssa…
bluesadi Apr 2, 2025
dc4437e
Implement StructMemoryLayoutAnalysis and refactor PatternMatchSimplifier
bluesadi Apr 15, 2025
6dd5ddf
Fix error propagation simplifier(for now). We may need some refactor …
bluesadi Apr 16, 2025
50f660f
Preparing for new better Rust calling convention analysis
bluesadi Apr 16, 2025
d1479db
Remove breakpoints
bluesadi Apr 16, 2025
41e8622
Move Rust-specific statements and expressions to ailment
bluesadi Apr 17, 2025
dd51c6d
Fix decompiled function signature display
bluesadi Apr 17, 2025
cc5cbf7
Adjust calling conventions and RustTypeLifter for Rust types
bluesadi Apr 18, 2025
471b645
Exploring StructMemoryLayoutAnalysis
bluesadi Apr 24, 2025
91a0540
Support returning struct to multiple registers (still buggy though)
bluesadi Apr 26, 2025
2e1d555
Remove dead assignments after ErrorPropagationSimplification
bluesadi Apr 28, 2025
5192fc7
Put most Rust optimization passes to BEFORE_VARIABLE_RECOVERY stage a…
bluesadi May 2, 2025
7a5e584
Implement StringCmpOutliner
bluesadi May 3, 2025
9198ae0
Do not replace the sizes of virtual variables used in references
bluesadi May 4, 2025
0235041
Do not simplify if-else structure for Rust binaries
bluesadi May 4, 2025
4c6d034
A temporary fix for JumpTableProcessor
bluesadi May 4, 2025
3e6e8f8
Fix some bugs in PatternMatchSimplifier and CallConventions
bluesadi May 5, 2025
33eccd5
Refactor cleanup_code_remover.py and introduce RedundantBlockRemover …
bluesadi May 7, 2025
46be93d
Fix a bug in SLivenessAnalysis
bluesadi May 9, 2025
b1174ad
Refactor RustCallingConventionAnalysis again (maybe we need to implem…
bluesadi May 9, 2025
9a9f8fa
Fix stack virtual variable uses after creating new vvars
bluesadi May 10, 2025
8b833c8
Integrate Enum into type system!
bluesadi May 12, 2025
be20115
Copy both graph and nodes in pre_pattern_match_simplifier.py
bluesadi May 12, 2025
84c3306
Add a heuristics to infer Result<(), Error>
bluesadi May 12, 2025
93bd4d4
Recover IfLet in PatternMatchSimplifier
bluesadi May 12, 2025
0dd4758
Fix an indent bug in RustStructuredCodeGenerator
bluesadi May 14, 2025
d9f0305
Fix some bugs related to PatternMatchSimplifier and typeconsts
bluesadi May 14, 2025
a3ec46f
Implement UnwrapOutliner and fix some bugs
bluesadi May 14, 2025
04ffc1b
Working on Known Function Prototype Application now (everything is st…
bluesadi May 27, 2025
fce1cf9
Equip Oxidizer with Rust standard library structs dataset
bluesadi May 28, 2025
80badab
Implement generalized StructMemoryLayout analysis
bluesadi May 29, 2025
0aa4d7f
Introduce Rust standard library function prototypes
bluesadi May 30, 2025
d267cff
Merge ailment into angr
bluesadi May 30, 2025
beb9177
Fix Rust standard library structs and prototypes datasets
bluesadi May 30, 2025
1a434bb
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
32398a6
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
4887efa
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
f058253
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
b75a590
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
dc728c3
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 1, 2025
005a15c
Fix some bugs in control flow optimization passes after introducing R…
bluesadi Jun 1, 2025
3cf754a
Fix some bugs for malware samples
bluesadi Jun 2, 2025
0559f54
Remove ipdb.set_trace()
bluesadi Jun 2, 2025
3df254e
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 4, 2025
93b63df
Remove redundant code in known_structs.py
bluesadi Jun 4, 2025
c77a688
Refine StructMemoryLayout recovery to make it choose the first struct…
bluesadi Jun 5, 2025
b519831
Working on type hints collection
bluesadi Jun 28, 2025
2926084
Sync
bluesadi Jun 28, 2025
5e7eae3
Refine _group_move_stmts_for_block
bluesadi Jun 29, 2025
337efdb
Support translate typeconsts.Enum
bluesadi Jul 7, 2025
79eb83e
Support Int128 in RustTypeLifter
bluesadi Jul 11, 2025
ba87053
Clean unused files and add known types database
bluesadi Jul 16, 2025
260a990
Improving type recovery
bluesadi Jul 18, 2025
98acee0
Support combo reg variable in function arguments
bluesadi Jul 25, 2025
3c3b296
Fix a return-by-memcpy bug in RustCallingConvention
bluesadi Jul 25, 2025
41051f3
ci: bump astral-sh/setup-uv from 6.3.1 to 6.4.3
dependabot[bot] Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1
if: startsWith(runner.os, 'windows')
- uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6
- uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6
- name: Sync dependencies
run: uv sync -p 3.10
- name: Collect tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
repository: angr/binaries
path: binaries
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1
- uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6
- uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6
- name: Sync dependencies
run: uv --directory angr sync -p 3.10
- name: Run pytest
Expand All @@ -52,7 +52,7 @@ jobs:
with:
repository: angr/binaries
path: binaries
- uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6
- uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6
- name: Sync dependencies
run: uv --directory angr sync -p 3.10
- name: Run pytest
Expand Down
1 change: 1 addition & 0 deletions angr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
from .sim_manager import SimulationManager
from .analyses import Analysis, register_analysis
from . import analyses
from .rust.analyses import *
from . import knowledge_plugins
from . import exploration_techniques
from .exploration_techniques import ExplorationTechnique
Expand Down
187 changes: 186 additions & 1 deletion angr/ailment/block_walker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint:disable=unused-argument,no-self-use
# pyright: reportIncompatibleMethodOverride=false
from __future__ import annotations
from collections import OrderedDict
from typing import Any
from collections.abc import Callable

Expand All @@ -16,6 +17,7 @@
Jump,
DirtyStatement,
WeakAssignment,
FunctionLikeMacro,
)
from .expression import (
Load,
Expand All @@ -33,6 +35,11 @@
MultiStatementExpression,
VirtualVariable,
Phi,
Enum,
Struct,
Array,
StringLiteral,
ComboRegister,
)


Expand Down Expand Up @@ -65,11 +72,17 @@ def __init__(self, stmt_handlers=None, expr_handlers=None):
VEXCCallExpression: self._handle_VEXCCallExpression,
Tmp: self._handle_Tmp,
Register: self._handle_Register,
ComboRegister: self._handle_ComboRegister,
Reinterpret: self._handle_Reinterpret,
Const: self._handle_Const,
MultiStatementExpression: self._handle_MultiStatementExpression,
VirtualVariable: self._handle_VirtualVariable,
Phi: self._handle_Phi,
Enum: self._handle_Enum,
Struct: self._handle_Struct,
Array: self._handle_Array,
FunctionLikeMacro: self._handle_FunctionLikeMacroExpr,
StringLiteral: self._handle_StringLiteral,
}

self.stmt_handlers: dict[type, Callable] = stmt_handlers if stmt_handlers else _default_stmt_handlers
Expand Down Expand Up @@ -207,6 +220,12 @@ def _handle_Tmp(self, expr_idx: int, expr: Tmp, stmt_idx: int, stmt: Statement,
def _handle_Register(self, expr_idx: int, expr: Register, stmt_idx: int, stmt: Statement, block: Block | None):
pass

def _handle_ComboRegister(
self, expr_idx: int, expr: ComboRegister, stmt_idx: int, stmt: Statement, block: Block | None
):
for idx, reg in enumerate(expr.registers):
self._handle_expr(idx, reg, stmt_idx, stmt, block)

def _handle_Const(self, expr_idx: int, expr: Const, stmt_idx: int, stmt: Statement, block: Block | None):
pass

Expand Down Expand Up @@ -241,6 +260,35 @@ def _handle_VEXCCallExpression(
for idx, operand in enumerate(expr.operands):
self._handle_expr(idx, operand, stmt_idx, stmt, block)

def _handle_Enum(self, expr_idx: int, expr: Enum, stmt_idx: int, stmt: Statement, block: Block | None):
for idx, field in enumerate(expr.fields):
self._handle_expr(idx, field, stmt_idx, stmt, block)

def _handle_Struct(self, expr_idx: int, expr: Struct, stmt_idx: int, stmt: Statement, block: Block | None):
for idx, field in enumerate(expr.fields.values()):
self._handle_expr(idx, field, stmt_idx, stmt, block)

def _handle_Array(self, expr_idx: int, expr: Array, stmt_idx: int, stmt: Statement, block: Block | None):
for idx, ele in enumerate(expr.elements):
self._handle_expr(idx, ele, stmt_idx, stmt, block)

def _handle_FunctionLikeMacro(self, stmt_idx: int, stmt: FunctionLikeMacro, block: Block | None):
if stmt.args:
for i, arg in enumerate(stmt.args):
self._handle_expr(i, arg, stmt_idx, stmt, block)

def _handle_FunctionLikeMacroExpr(
self, expr_idx: int, expr: FunctionLikeMacro, stmt_idx: int, stmt: Statement, block: Block | None
):
if expr.args:
for i, arg in enumerate(expr.args):
self._handle_expr(i, arg, stmt_idx, stmt, block)

def _handle_StringLiteral(
self, expr_idx: int, expr: StringLiteral, stmt_idx: int, stmt: Statement, block: Block | None
):
pass


class AILBlockWalker(AILBlockWalkerBase):
"""
Expand Down Expand Up @@ -466,14 +514,20 @@ def _handle_Call(self, stmt_idx: int, stmt: Call, block: Block | None):
new_args.append(arg)
i += 1

new_ret_expr = None
if stmt.ret_expr is not None:
new_ret_expr = self._handle_expr(-1, stmt.ret_expr, stmt_idx, stmt, block)
if new_ret_expr is not None and new_ret_expr is not stmt.ret_expr:
changed = True

if changed:
new_stmt = Call(
stmt.idx,
new_target if new_target is not None else stmt.target,
calling_convention=stmt.calling_convention,
prototype=stmt.prototype,
args=new_args,
ret_expr=stmt.ret_expr,
ret_expr=new_ret_expr or stmt.ret_expr,
**stmt.tags,
)
if self._update_block and block is not None:
Expand Down Expand Up @@ -622,6 +676,27 @@ def _handle_DirtyStatement(self, stmt_idx: int, stmt: DirtyStatement, block: Blo
# Expression handlers
#

def _handle_ComboRegister(
self, expr_idx: int, expr: ComboRegister, stmt_idx: int, stmt: Statement, block: Block | None
):
changed = False
new_regs = []

for idx, reg in enumerate(expr.registers):
new_reg = self._handle_expr(idx, reg, stmt_idx, stmt, block)
if new_reg and new_reg is not reg:
changed = True
new_regs.append(new_reg)
else:
new_regs.append(reg)

if changed:
new_expr = expr.copy()
new_expr.registers = new_regs
return new_expr

return None

def _handle_Load(self, expr_idx: int, expr: Load, stmt_idx: int, stmt: Statement, block: Block | None):
addr = self._handle_expr(0, expr.addr, stmt_idx, stmt, block)

Expand Down Expand Up @@ -843,3 +918,113 @@ def _handle_MultiStatementExpression(
expr_.stmts = new_statements
return expr_
return None

def _handle_Enum(self, expr_idx: int, expr: Enum, stmt_idx: int, stmt: Statement, block: Block | None):
changed = False
new_fields = []
for idx, field in enumerate(expr.fields):
new_field = self._handle_expr(idx, field, stmt_idx, stmt, block)
if new_field is not None and new_field is not field:
changed = True
new_fields.append(new_field)
else:
new_fields.append(field)

if changed:
new_expr = expr.copy()
new_expr.fields = tuple(new_fields)
return new_expr
return None

def _handle_Struct(self, expr_idx: int, expr: Struct, stmt_idx: int, stmt: Statement, block: Block | None):
changed = False
new_fields = OrderedDict()
for idx, (offset, field) in enumerate(expr.fields.items()):
new_field = self._handle_expr(idx, field, stmt_idx, stmt, block)
if new_field is not None and new_field is not field:
changed = True
new_fields[offset] = new_field
else:
new_fields[offset] = field

if changed:
new_expr = expr.copy()
new_expr.fields = new_fields
return new_expr
return None

def _handle_Array(self, expr_idx: int, expr: Array, stmt_idx: int, stmt: Statement, block: Block | None):
changed = False
new_elements = []
for idx, ele in enumerate(expr.elements):
new_ele = self._handle_expr(idx, ele, stmt_idx, stmt, block)
if new_ele is not None and new_ele is not ele:
changed = True
new_elements.append(new_ele)
else:
new_elements.append(ele)

if changed:
new_expr = expr.copy()
new_expr.elements = tuple(new_elements)
return new_expr
return None

def _handle_FunctionLikeMacro(self, stmt_idx: int, stmt: FunctionLikeMacro, block: Block | None):
changed = False

new_args = None
if stmt.args is not None:
new_args = []

i = 0
while i < len(stmt.args):
arg = stmt.args[i]
new_arg = self._handle_expr(i, arg, stmt_idx, stmt, block)
if new_arg is not None and new_arg is not arg:
if not changed:
# initialize new_args
new_args = list(stmt.args[:i])
new_args.append(new_arg)
changed = True
else:
if changed:
new_args.append(arg)
i += 1

if changed:
new_stmt = stmt.copy()
new_stmt.args = new_args
if self._update_block and block is not None:
block.statements[stmt_idx] = new_stmt
return new_stmt
return None

def _handle_FunctionLikeMacroExpr(
self, expr_idx: int, expr: FunctionLikeMacro, stmt_idx: int, stmt: Statement, block: Block | None
):
changed = False

new_args = None
if expr.args is not None:
i = 0
new_args = []
while i < len(expr.args):
arg = expr.args[i]
new_arg = self._handle_expr(i, arg, stmt_idx, stmt, block)
if new_arg is not None and new_arg is not arg:
if not changed:
# initialize new_args
new_args = list(expr.args[:i])
new_args.append(new_arg)
changed = True
else:
if changed:
new_args.append(arg)
i += 1

if changed:
expr = expr.copy()
expr.args = new_args
return expr
return None
Loading