Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
419feec
Make decompiler.py more generic
bluesadi Nov 2, 2023
608b8dd
Merge with latest angr
bluesadi Feb 1, 2024
1de9d60
Add type translator for Rust
bluesadi Nov 21, 2023
63e7290
Add function type translation
bluesadi Nov 21, 2023
8a93128
Working on type translation
bluesadi Nov 22, 2023
abeb3ac
Fix some bugs in type translation
bluesadi Nov 26, 2023
21233bd
Add alloc_simplifier.py
bluesadi Dec 5, 2023
9c9690a
Fix some bugs
bluesadi Jan 24, 2024
232f002
* Convert C infinite loops into Rust infinite loops
bluesadi Jan 30, 2024
37cd35d
Make RustSimType system compatible with original SimType system
bluesadi Jan 31, 2024
7c083e7
Fix some type translation problems
bluesadi Feb 1, 2024
da4c689
Improve type translation further
bluesadi Feb 2, 2024
c2d0398
Add RustInfiniteLoop handler in StructuredCodeWalker
bluesadi Feb 2, 2024
dd9b0e1
Minor fix
bluesadi Feb 6, 2024
21a11e0
Add StringSimplifier
bluesadi Feb 11, 2024
e86b51a
Move optimization passes to angr/rust
bluesadi Feb 12, 2024
08b7cb4
Move sim_type to angr/rust
bluesadi Feb 12, 2024
240daeb
Move typehoon related files to angr/rust
bluesadi Feb 12, 2024
a5699d4
Refine StringSimplifier
bluesadi Mar 12, 2024
5fdaecd
Fix optimization_passes/init.py
bluesadi Mar 12, 2024
f4b3cba
Initial implementation of AllocaSimplifier
bluesadi Mar 23, 2024
3a31aad
Fix some bugs in alloc_simplifier.py
bluesadi Mar 26, 2024
132e825
Implemented AllocSimplifier
bluesadi Apr 2, 2024
d13a05c
Disable inlined_strcpy optimization for Rust binary
bluesadi Apr 3, 2024
e29749a
Disable ReturnDuplicator for Rust decompilation
bluesadi Apr 3, 2024
24c0282
Separate RustSimTypeStr and RustSimTypeString
bluesadi Apr 3, 2024
541d105
Move StringSimplifier before VariableRecovery
bluesadi Apr 3, 2024
e419311
Implement DeallocSimplifier
bluesadi Apr 3, 2024
88a2f70
Refactor AllocSimplifier
bluesadi Apr 15, 2024
05dcb21
Add Vec recovery in AllocSimplifier
bluesadi Apr 15, 2024
30850f4
Integrated RustCall statement into VariableRecoveryFast
bluesadi Apr 30, 2024
cb49ea8
VariableRecovery and Typehoon now supports recover Rust types from fu…
bluesadi May 7, 2024
9413742
JunkRemover now removes alloc::alloc::handle_alloc_error and __rust_d…
bluesadi May 7, 2024
86056c7
Add LibFunctionIdentifier
bluesadi May 9, 2024
db2da96
Remove RustCall
bluesadi May 9, 2024
0913b85
Add pre-defined Rust standard function prototypes
bluesadi May 17, 2024
b5aa880
Start supporting array type for Rust
bluesadi May 27, 2024
1bec150
Add pre-defined prototypes with Struct arguments
bluesadi May 31, 2024
a2a64e5
Change RustSimTypePointer to RustSimTypeReference
bluesadi Jun 3, 2024
20d21be
Pre-define some structs
bluesadi Jun 3, 2024
87e5174
Add ArrayReference and StrReference. RustCodeGenerator supports both …
bluesadi Jun 5, 2024
f714b76
Add None pointer support for Option
bluesadi Jun 6, 2024
aa9a2f1
Support struct return value
bluesadi Jun 7, 2024
1baffb3
Create new variables for stack arguments at the same location of diff…
bluesadi Jun 17, 2024
fbf06ad
Recover struct instantiation
bluesadi Jun 18, 2024
f510b95
Fix a Rust calling convention problem
bluesadi Jun 21, 2024
6d53eba
Fix some bugs
bluesadi Jun 24, 2024
bb9eb79
Refine JunkRemover and add TransformationPass as an extension of Opti…
bluesadi Jul 13, 2024
7976a40
Implement the prototype of OwnershipTransferSimplifier
bluesadi Jul 20, 2024
39dab31
Introduce better Rust demangler
bluesadi Jul 21, 2024
3b9b414
Improve AllocSimplifier
bluesadi Jul 26, 2024
2838456
Create UnwrapSimplifier (But it's not completed yet)
bluesadi Aug 2, 2024
2f0de8c
Add special handling for Rust calling convention - return type is struct
bluesadi Aug 2, 2024
dd0f4b3
Add special handling for Rust calling convention - class member function
bluesadi Aug 3, 2024
fb271a5
Fix RustSimStruct with_arch bug
bluesadi Aug 3, 2024
20d1de4
Fix struct instantiation recovery
bluesadi Aug 4, 2024
6b9dbdf
Reorganize some simplification passes
bluesadi Aug 7, 2024
5e42c59
Rename CallsiteMaker to StructInstantiationSimplifier
bluesadi Aug 7, 2024
bd636c1
Improve OwnershipSimplifier and create CallingConventionRecovery
bluesadi Aug 9, 2024
8483e35
Initial version of RetSiteSimplifier
bluesadi Aug 21, 2024
56cb5fb
Fix some bug in AllocSimplifier
bluesadi Aug 21, 2024
3b96ef8
Initial version of RustCallingConvention analysis
bluesadi Aug 26, 2024
da7ed89
Fix a bug
bluesadi Aug 26, 2024
1dd6c7d
Enable alloc_simplifier
bluesadi Sep 5, 2024
e803e67
Refine Rust function name normalizing
bluesadi Sep 9, 2024
8b5fdec
Reimplement struct_instantiation_simplifier.py based on SSA reaching …
bluesadi Sep 18, 2024
9b9104d
StructInstantiationSimplifier now supports recursive simplification
bluesadi Sep 18, 2024
976f482
Move StructInstantiationSimplifier to stage AFTER_GLOBAL_SIMPLIFICATION
bluesadi Sep 19, 2024
6e1b4d9
Introduce CallsiteCorrector to fix function call with struct return type
bluesadi Sep 19, 2024
c161305
Implement DropSimplifier as a optimization pass after structuring
bluesadi Sep 20, 2024
f6dd80f
Introduce drop simplifier
bluesadi Sep 20, 2024
9866303
Fix UnwrapSimplifier and stack slots reuse problem
bluesadi Sep 25, 2024
d8abf44
Reimplemented OwnershipSimplifier
bluesadi Sep 26, 2024
60a287e
Refine RustCallingConventionAnalysis
bluesadi Oct 1, 2024
7a7e16d
Reimplemented CleanupCodeRemover
bluesadi Oct 1, 2024
8bfea35
Reimplemented AllocSimplifier
bluesadi Oct 3, 2024
a2c41b9
Remove error handling related blocks in AllocSimplifier
bluesadi Oct 7, 2024
325a7da
Fix compatibility issues with decompilation preset feature
bluesadi Oct 7, 2024
7e32fd0
Make CleanupCodeRemover able to handle for-loop-drop pattern
bluesadi Oct 7, 2024
76cf2ff
Fix the prototype definition for alloc::fmt::format::format_inner
bluesadi Oct 8, 2024
9fcb350
Introduce RustSimEnum (but it doesn't have a lot of impact now)
bluesadi Oct 8, 2024
d1060d0
RustCallingConventionAnalysis now can infer function prototype based …
bluesadi Oct 9, 2024
60cc248
Reimplemented OwnershipSimplifier
bluesadi Oct 10, 2024
8e250ee
Delete unused passes
bluesadi Oct 10, 2024
c1d20f2
Fix some bugs in CleanupCodeRemover and OwnershipSimplifier
bluesadi Oct 11, 2024
0b36ae4
Fix a bug in RustCallingConventionRecovery
bluesadi Oct 12, 2024
2351f1a
Fix RustStructuredCodeGenerator compatability issue with VEXCCallExpr…
bluesadi Oct 19, 2024
2733874
Fix typo
bluesadi Oct 29, 2024
675cca4
Support let match operations on Option<T>
bluesadi Nov 7, 2024
47beb08
Fix Rust empty string literal representation issue
bluesadi Nov 8, 2024
020a2ac
Implement PrintMacroSimplifier
bluesadi Nov 10, 2024
0436435
Fix: SRDA can't find vvar value
bluesadi Nov 10, 2024
047ae13
Fix a Rust function prototype normalization bug
bluesadi Nov 11, 2024
c018fe5
Implement AllocSimplifier for vec!
bluesadi Nov 11, 2024
0368c50
Rust function prototype inference now infers types through paths in c…
bluesadi Nov 12, 2024
0fbd0c2
Rust function prototype inference can infer Result<T, E> type now
bluesadi Nov 14, 2024
05b986c
Fix some bugs after rebasing
bluesadi Nov 14, 2024
5c2327b
Implement Rust pattern match recovery
bluesadi Nov 16, 2024
74294c9
Fix some bugs in pattern match recovery and remove the old Option typ…
bluesadi Nov 16, 2024
781e852
RustSimTypeOption is not RustSimStruct
bluesadi Nov 16, 2024
b6449ac
Fix some bugs
bluesadi Nov 18, 2024
c282774
Implemented StrArgumentSimplifier
bluesadi Nov 19, 2024
14c40ff
Implemented SecurityCheckRemover
bluesadi Nov 19, 2024
6920ed0
Remove Vec expression
bluesadi Nov 19, 2024
df25dc4
Implemented VecIndexingSimplifier
bluesadi Nov 21, 2024
76c3d60
Implemented StructFieldAccessSimplifier, but I don't know if it works…
bluesadi Nov 24, 2024
7b7e4d4
Initial version of StructReturnSimplifier
bluesadi Nov 25, 2024
89627c5
Initial version of DerefCoercionSimplifier
bluesadi Nov 25, 2024
0e120d9
DerefCoercionSimplifier now supports O3 optimization
bluesadi Nov 25, 2024
eac0094
Rewrite part of OwnershipSimplifier with mixins
bluesadi Nov 26, 2024
d9751a6
Extend PrintMacroSimplifier to eprint and format
bluesadi Nov 29, 2024
10bb596
Enable CleanupCodeRemover for RustCallingConventionAnalysis
bluesadi Nov 29, 2024
2c5b15a
Fix a bug in StrArgumentSimplifier
bluesadi Dec 1, 2024
61c5147
StructInstantiationSimplifier can infer potential concrete struct typ…
bluesadi Dec 3, 2024
4c8069b
StructReturnSimplifier: Change to a post-structuring pass
bluesadi Dec 3, 2024
6e1c64e
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
5a8fdf9
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
e4fd61a
PrintMacroSimplifier: Add more target functions
bluesadi Dec 4, 2024
3c7ab8e
Refine StructReturnSimplifier
bluesadi Dec 5, 2024
ab06eda
UnwrapSimplifier is back now
bluesadi Dec 6, 2024
102189f
Fix some bugs
bluesadi Dec 7, 2024
857c250
OwnershipSimplifier: Add a workaround to handle the case where Store …
bluesadi Dec 12, 2024
178688d
Fix some bugs caused by rebasing
bluesadi Dec 19, 2024
bcdb4e7
Implement VecMacroSimplifier
bluesadi Dec 19, 2024
359d7a2
Introduce IfLetNode
bluesadi Dec 21, 2024
f14a8e7
Assign FunctionPrototypeInference result to function
bluesadi Dec 25, 2024
da2f44b
Introduce StringLiteral expression and fix DerefCoercionSimplifier
bluesadi Dec 31, 2024
c9f27c4
Rewrite StructReturnSimplifier
bluesadi Jan 2, 2025
1e354ad
StructReturnSimplifier: Support enum return type now
bluesadi Jan 2, 2025
7aab9bd
Fix some StructInstantiationSimplifier bug
bluesadi Jan 6, 2025
dfbf482
Some update
bluesadi Jan 6, 2025
096354f
SequenceWalker: Support if-let node
bluesadi Jan 6, 2025
ddcf126
Fix RustSimEnum size calculation bug
bluesadi Jan 7, 2025
c31456a
Fix PrintMacroSimplifier
bluesadi Jan 7, 2025
f735c5f
Fix StrArgumentSimplifier decode string check problem
bluesadi Jan 7, 2025
8e1eb08
Move some passes to RustSpecificSimplification
bluesadi Jan 8, 2025
57d80d7
Fix Struct size problem
bluesadi Jan 8, 2025
d555214
Fix a lot of bugs
bluesadi Jan 8, 2025
316e259
Add more security checks
bluesadi Jan 8, 2025
0dd652c
Fix SwitchCase code generation
bluesadi Jan 9, 2025
00abc0b
Implement ShowMacroSimplifier
bluesadi Jan 9, 2025
2c55319
Fix phi issue
bluesadi Jan 9, 2025
d956b44
Remove the incorrect import of Conditional from sqlalchemy.
ltfish Jan 9, 2025
a2b23f4
damn
ltfish Jan 9, 2025
cccee73
Fix some shit
bluesadi Jan 9, 2025
ac06633
Fix bugs in _update_phi_variables_after_removing_block.
ltfish Jan 9, 2025
0b90b38
OwnershipSimplifier: ins_addrs of block statements must monotonically…
ltfish Jan 9, 2025
7cbb8c1
Fix some shit
bluesadi Jan 9, 2025
677fc55
Fix some shit
bluesadi Jan 10, 2025
8c936c6
Fix some shit
bluesadi Jan 10, 2025
898d1c0
Fix some shit
bluesadi Jan 10, 2025
891cc0d
Fix some bugs caused by rebasing
bluesadi Feb 24, 2025
0315d74
Rewrite RustCallConvention analysis and delete two unused simplificat…
bluesadi Feb 26, 2025
1bffe04
Introduce PrePatternMatchSimplifier to duplicate return blocks to pre…
bluesadi Feb 28, 2025
3424261
Rewrite RustCallingConventionAnalysis
bluesadi Mar 22, 2025
54a5f3f
Introduce StructMemoryLayout analysis
bluesadi Mar 28, 2025
303f17c
Implement LayoutInference for Arguments & Fix some bugs after new ssa…
bluesadi Apr 2, 2025
15cacd3
Implement StructMemoryLayoutAnalysis and refactor PatternMatchSimplifier
bluesadi Apr 15, 2025
daace03
Fix error propagation simplifier(for now). We may need some refactor …
bluesadi Apr 16, 2025
7ca6738
Preparing for new better Rust calling convention analysis
bluesadi Apr 16, 2025
14d200c
Remove breakpoints
bluesadi Apr 16, 2025
233f730
Move Rust-specific statements and expressions to ailment
bluesadi Apr 17, 2025
6777b56
Fix decompiled function signature display
bluesadi Apr 17, 2025
8f6d542
Adjust calling conventions and RustTypeLifter for Rust types
bluesadi Apr 18, 2025
0b6dbde
Exploring StructMemoryLayoutAnalysis
bluesadi Apr 24, 2025
4cf7770
Support returning struct to multiple registers (still buggy though)
bluesadi Apr 26, 2025
5e0e52a
Remove dead assignments after ErrorPropagationSimplification
bluesadi Apr 28, 2025
93a5a7e
Put most Rust optimization passes to BEFORE_VARIABLE_RECOVERY stage a…
bluesadi May 2, 2025
656d0b7
Implement StringCmpOutliner
bluesadi May 3, 2025
1ed8eaa
Do not replace the sizes of virtual variables used in references
bluesadi May 4, 2025
18b3221
Do not simplify if-else structure for Rust binaries
bluesadi May 4, 2025
2ade7cf
A temporary fix for JumpTableProcessor
bluesadi May 4, 2025
e3f07a1
Fix some bugs in PatternMatchSimplifier and CallConventions
bluesadi May 5, 2025
b41ea1d
Refactor cleanup_code_remover.py and introduce RedundantBlockRemover …
bluesadi May 7, 2025
e266f7a
Fix a bug in SLivenessAnalysis
bluesadi May 9, 2025
ba3a55a
Refactor RustCallingConventionAnalysis again (maybe we need to implem…
bluesadi May 9, 2025
67db3b0
Fix stack virtual variable uses after creating new vvars
bluesadi May 10, 2025
3c5b32d
Integrate Enum into type system!
bluesadi May 12, 2025
d010acd
Copy both graph and nodes in pre_pattern_match_simplifier.py
bluesadi May 12, 2025
912340c
Add a heuristics to infer Result<(), Error>
bluesadi May 12, 2025
c2108a6
Recover IfLet in PatternMatchSimplifier
bluesadi May 12, 2025
604a425
Fix an indent bug in RustStructuredCodeGenerator
bluesadi May 14, 2025
f34251e
Fix some bugs related to PatternMatchSimplifier and typeconsts
bluesadi May 14, 2025
7fd1021
Implement UnwrapOutliner and fix some bugs
bluesadi May 14, 2025
4cfed4a
Working on Known Function Prototype Application now (everything is st…
bluesadi May 27, 2025
b3be138
Equip Oxidizer with Rust standard library structs dataset
bluesadi May 28, 2025
6ce69ea
Implement generalized StructMemoryLayout analysis
bluesadi May 29, 2025
c45c676
Introduce Rust standard library function prototypes
bluesadi May 30, 2025
8695f0f
Merge ailment into angr
bluesadi May 30, 2025
dc1879f
Fix Rust standard library structs and prototypes datasets
bluesadi May 30, 2025
380bb72
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
409e4ad
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
96a2aa6
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
c7852b1
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
b0122e9
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
3f84d96
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 1, 2025
7fb3b4f
Fix some bugs in control flow optimization passes after introducing R…
bluesadi Jun 1, 2025
565e206
Fix some bugs for malware samples
bluesadi Jun 2, 2025
36152db
Remove ipdb.set_trace()
bluesadi Jun 2, 2025
4bf7fad
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 4, 2025
cdbca15
Remove redundant code in known_structs.py
bluesadi Jun 4, 2025
5fb5a47
Refine StructMemoryLayout recovery to make it choose the first struct…
bluesadi Jun 5, 2025
a642c34
Working on type hints collection
bluesadi Jun 28, 2025
371e70b
Sync
bluesadi Jun 28, 2025
72ca181
Refine _group_move_stmts_for_block
bluesadi Jun 29, 2025
c2ea0be
Support translate typeconsts.Enum
bluesadi Jul 7, 2025
a4117b5
Support Int128 in RustTypeLifter
bluesadi Jul 11, 2025
161d32f
Clean unused files and add known types database
bluesadi Jul 16, 2025
a829e51
Improving type recovery
bluesadi Jul 18, 2025
dcee9f9
Support combo reg variable in function arguments
bluesadi Jul 25, 2025
bd659fc
Fix a return-by-memcpy bug in RustCallingConvention
bluesadi Jul 25, 2025
4d89bfc
Fix some bugs
bluesadi Jul 28, 2025
b2b0704
Upload type database
bluesadi Jul 28, 2025
7239daf
Update RustPseudocodeGenerator
bluesadi Jul 28, 2025
ba65e93
Add __init__.py to known_types
bluesadi Jul 29, 2025
1cce14d
Fix unwrap_outliner.py
bluesadi Aug 3, 2025
8c2b4c9
ci: bump actions/checkout from 4.2.2 to 5.0.0
dependabot[bot] Aug 18, 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
- uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1
if: startsWith(runner.os, 'windows')
- uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6
Expand All @@ -32,7 +32,7 @@ jobs:
name: Rust Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
- uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 # v1
with:
components: clippy, rustfmt
Expand All @@ -45,7 +45,7 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
- uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 # v1
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jobs:
runner_id: [1, 2, 3, 4, 5]
fail-fast: false
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
with:
path: angr
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
with:
repository: angr/binaries
path: binaries
Expand All @@ -45,10 +45,10 @@ jobs:
runner_id: [1, 2, 3]
fail-fast: false
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
with:
path: angr
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v4
with:
repository: angr/binaries
path: binaries
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