Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
256 commits
Select commit Hold shift + click to select a range
3a1d380
Add alloc_simplifier.py
bluesadi Dec 5, 2023
d945c7e
Fix some bugs
bluesadi Jan 24, 2024
6085b14
* Convert C infinite loops into Rust infinite loops
bluesadi Jan 30, 2024
2b40d59
Make RustSimType system compatible with original SimType system
bluesadi Jan 31, 2024
c329f5c
Fix some type translation problems
bluesadi Feb 1, 2024
8228586
Improve type translation further
bluesadi Feb 2, 2024
8f02e97
Add RustInfiniteLoop handler in StructuredCodeWalker
bluesadi Feb 2, 2024
697378f
Minor fix
bluesadi Feb 6, 2024
a6733a2
Add StringSimplifier
bluesadi Feb 11, 2024
e83eafa
Move optimization passes to angr/rust
bluesadi Feb 12, 2024
170805c
Move sim_type to angr/rust
bluesadi Feb 12, 2024
ae5624a
Move typehoon related files to angr/rust
bluesadi Feb 12, 2024
85949cd
Refine StringSimplifier
bluesadi Mar 12, 2024
3a320e9
Fix optimization_passes/init.py
bluesadi Mar 12, 2024
0a73b2a
Initial implementation of AllocaSimplifier
bluesadi Mar 23, 2024
78d0b10
Fix some bugs in alloc_simplifier.py
bluesadi Mar 26, 2024
6d12bde
Implemented AllocSimplifier
bluesadi Apr 2, 2024
ff73b80
Disable inlined_strcpy optimization for Rust binary
bluesadi Apr 3, 2024
301d684
Disable ReturnDuplicator for Rust decompilation
bluesadi Apr 3, 2024
e7cf97f
Separate RustSimTypeStr and RustSimTypeString
bluesadi Apr 3, 2024
a1db9f6
Move StringSimplifier before VariableRecovery
bluesadi Apr 3, 2024
8b227ff
Implement DeallocSimplifier
bluesadi Apr 3, 2024
772b463
Refactor AllocSimplifier
bluesadi Apr 15, 2024
aa05488
Add Vec recovery in AllocSimplifier
bluesadi Apr 15, 2024
c07a70a
Integrated RustCall statement into VariableRecoveryFast
bluesadi Apr 30, 2024
50f67bb
VariableRecovery and Typehoon now supports recover Rust types from fu…
bluesadi May 7, 2024
8c5f746
JunkRemover now removes alloc::alloc::handle_alloc_error and __rust_d…
bluesadi May 7, 2024
43d156b
Add LibFunctionIdentifier
bluesadi May 9, 2024
0ad3495
Remove RustCall
bluesadi May 9, 2024
0bfeb7f
Add pre-defined Rust standard function prototypes
bluesadi May 17, 2024
d8d7ae8
Start supporting array type for Rust
bluesadi May 27, 2024
a42427d
Add pre-defined prototypes with Struct arguments
bluesadi May 31, 2024
8e0ddef
Change RustSimTypePointer to RustSimTypeReference
bluesadi Jun 3, 2024
644ae05
Pre-define some structs
bluesadi Jun 3, 2024
208cfb4
Add ArrayReference and StrReference. RustCodeGenerator supports both …
bluesadi Jun 5, 2024
1700f33
Add None pointer support for Option
bluesadi Jun 6, 2024
1367edc
Support struct return value
bluesadi Jun 7, 2024
ce6bba2
Create new variables for stack arguments at the same location of diff…
bluesadi Jun 17, 2024
d2447bb
Recover struct instantiation
bluesadi Jun 18, 2024
2bbd6b1
Fix a Rust calling convention problem
bluesadi Jun 21, 2024
d65650a
Fix some bugs
bluesadi Jun 24, 2024
b461477
Refine JunkRemover and add TransformationPass as an extension of Opti…
bluesadi Jul 13, 2024
ccba730
Implement the prototype of OwnershipTransferSimplifier
bluesadi Jul 20, 2024
a12244c
Introduce better Rust demangler
bluesadi Jul 21, 2024
191546c
Improve AllocSimplifier
bluesadi Jul 26, 2024
29bb3e3
Create UnwrapSimplifier (But it's not completed yet)
bluesadi Aug 2, 2024
72f42c6
Add special handling for Rust calling convention - return type is struct
bluesadi Aug 2, 2024
a62fb78
Add special handling for Rust calling convention - class member function
bluesadi Aug 3, 2024
67193c8
Fix RustSimStruct with_arch bug
bluesadi Aug 3, 2024
5c1e6f7
Fix struct instantiation recovery
bluesadi Aug 4, 2024
db93c42
Reorganize some simplification passes
bluesadi Aug 7, 2024
0a96ee0
Rename CallsiteMaker to StructInstantiationSimplifier
bluesadi Aug 7, 2024
a5d13f3
Improve OwnershipSimplifier and create CallingConventionRecovery
bluesadi Aug 9, 2024
7e23415
Initial version of RetSiteSimplifier
bluesadi Aug 21, 2024
843ee1e
Fix some bug in AllocSimplifier
bluesadi Aug 21, 2024
71eb57a
Initial version of RustCallingConvention analysis
bluesadi Aug 26, 2024
a112e69
Fix a bug
bluesadi Aug 26, 2024
29e67e4
Enable alloc_simplifier
bluesadi Sep 5, 2024
09dc6c2
Refine Rust function name normalizing
bluesadi Sep 9, 2024
8324fe6
Reimplement struct_instantiation_simplifier.py based on SSA reaching …
bluesadi Sep 18, 2024
eda9ae5
StructInstantiationSimplifier now supports recursive simplification
bluesadi Sep 18, 2024
da870ea
Move StructInstantiationSimplifier to stage AFTER_GLOBAL_SIMPLIFICATION
bluesadi Sep 19, 2024
9f1ba27
Introduce CallsiteCorrector to fix function call with struct return type
bluesadi Sep 19, 2024
3793f4d
Implement DropSimplifier as a optimization pass after structuring
bluesadi Sep 20, 2024
b9be472
Introduce drop simplifier
bluesadi Sep 20, 2024
0a63e02
Fix UnwrapSimplifier and stack slots reuse problem
bluesadi Sep 25, 2024
64fbf17
Reimplemented OwnershipSimplifier
bluesadi Sep 26, 2024
7ad6005
Refine RustCallingConventionAnalysis
bluesadi Oct 1, 2024
71c3435
Reimplemented CleanupCodeRemover
bluesadi Oct 1, 2024
1a6a14d
Reimplemented AllocSimplifier
bluesadi Oct 3, 2024
db3da83
Remove error handling related blocks in AllocSimplifier
bluesadi Oct 7, 2024
4d59d58
Fix compatibility issues with decompilation preset feature
bluesadi Oct 7, 2024
9fb5145
Make CleanupCodeRemover able to handle for-loop-drop pattern
bluesadi Oct 7, 2024
25151d2
Fix the prototype definition for alloc::fmt::format::format_inner
bluesadi Oct 8, 2024
c7a2091
Introduce RustSimEnum (but it doesn't have a lot of impact now)
bluesadi Oct 8, 2024
c47a612
RustCallingConventionAnalysis now can infer function prototype based …
bluesadi Oct 9, 2024
5eac2e8
Reimplemented OwnershipSimplifier
bluesadi Oct 10, 2024
c7b15f3
Delete unused passes
bluesadi Oct 10, 2024
672b2e0
Fix some bugs in CleanupCodeRemover and OwnershipSimplifier
bluesadi Oct 11, 2024
83a7ec8
Fix a bug in RustCallingConventionRecovery
bluesadi Oct 12, 2024
29a9f05
Fix RustStructuredCodeGenerator compatability issue with VEXCCallExpr…
bluesadi Oct 19, 2024
1ef6280
Fix typo
bluesadi Oct 29, 2024
e29d8e1
Support let match operations on Option<T>
bluesadi Nov 7, 2024
9e47f05
Fix Rust empty string literal representation issue
bluesadi Nov 8, 2024
7f6c67a
Implement PrintMacroSimplifier
bluesadi Nov 10, 2024
c05340a
Fix: SRDA can't find vvar value
bluesadi Nov 10, 2024
2ff4778
Fix a Rust function prototype normalization bug
bluesadi Nov 11, 2024
823350c
Implement AllocSimplifier for vec!
bluesadi Nov 11, 2024
e78ad9c
Rust function prototype inference now infers types through paths in c…
bluesadi Nov 12, 2024
1f78d9b
Rust function prototype inference can infer Result<T, E> type now
bluesadi Nov 14, 2024
1df39bd
Fix some bugs after rebasing
bluesadi Nov 14, 2024
b979b7e
Implement Rust pattern match recovery
bluesadi Nov 16, 2024
ed7c67f
Fix some bugs in pattern match recovery and remove the old Option typ…
bluesadi Nov 16, 2024
faac2cd
RustSimTypeOption is not RustSimStruct
bluesadi Nov 16, 2024
abb88af
Fix some bugs
bluesadi Nov 18, 2024
bf03d7d
Implemented StrArgumentSimplifier
bluesadi Nov 19, 2024
7ca813c
Implemented SecurityCheckRemover
bluesadi Nov 19, 2024
c31f3b7
Remove Vec expression
bluesadi Nov 19, 2024
d9bc300
Implemented VecIndexingSimplifier
bluesadi Nov 21, 2024
9f39154
Implemented StructFieldAccessSimplifier, but I don't know if it works…
bluesadi Nov 24, 2024
1d22753
Initial version of StructReturnSimplifier
bluesadi Nov 25, 2024
343ff25
Initial version of DerefCoercionSimplifier
bluesadi Nov 25, 2024
ff9b730
DerefCoercionSimplifier now supports O3 optimization
bluesadi Nov 25, 2024
e975f45
Rewrite part of OwnershipSimplifier with mixins
bluesadi Nov 26, 2024
f7ff096
Extend PrintMacroSimplifier to eprint and format
bluesadi Nov 29, 2024
35d6c39
Enable CleanupCodeRemover for RustCallingConventionAnalysis
bluesadi Nov 29, 2024
8891d25
Fix a bug in StrArgumentSimplifier
bluesadi Dec 1, 2024
c9d5dbe
StructInstantiationSimplifier can infer potential concrete struct typ…
bluesadi Dec 3, 2024
2e97013
StructReturnSimplifier: Change to a post-structuring pass
bluesadi Dec 3, 2024
3c508d2
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
26fb5be
StructReturnSimplifier: Fix some bug
bluesadi Dec 4, 2024
332f76c
PrintMacroSimplifier: Add more target functions
bluesadi Dec 4, 2024
4baa0f8
Refine StructReturnSimplifier
bluesadi Dec 5, 2024
9c507d4
UnwrapSimplifier is back now
bluesadi Dec 6, 2024
31cd8af
Fix some bugs
bluesadi Dec 7, 2024
c4c07d3
OwnershipSimplifier: Add a workaround to handle the case where Store …
bluesadi Dec 12, 2024
fb1aff3
Fix some bugs caused by rebasing
bluesadi Dec 19, 2024
e806240
Implement VecMacroSimplifier
bluesadi Dec 19, 2024
cc77b10
Introduce IfLetNode
bluesadi Dec 21, 2024
ac672f1
Assign FunctionPrototypeInference result to function
bluesadi Dec 25, 2024
a0951c2
Introduce StringLiteral expression and fix DerefCoercionSimplifier
bluesadi Dec 31, 2024
4b981c4
Rewrite StructReturnSimplifier
bluesadi Jan 2, 2025
6d80e2d
StructReturnSimplifier: Support enum return type now
bluesadi Jan 2, 2025
7006eec
Fix some StructInstantiationSimplifier bug
bluesadi Jan 6, 2025
952c2e0
Some update
bluesadi Jan 6, 2025
2bb4877
SequenceWalker: Support if-let node
bluesadi Jan 6, 2025
fc2c002
Fix RustSimEnum size calculation bug
bluesadi Jan 7, 2025
e054bc5
Fix PrintMacroSimplifier
bluesadi Jan 7, 2025
1055ec5
Fix StrArgumentSimplifier decode string check problem
bluesadi Jan 7, 2025
450427c
Move some passes to RustSpecificSimplification
bluesadi Jan 8, 2025
9823b4b
Fix Struct size problem
bluesadi Jan 8, 2025
1cc2227
Fix a lot of bugs
bluesadi Jan 8, 2025
2a0d6bc
Add more security checks
bluesadi Jan 8, 2025
4b7ddd3
Fix SwitchCase code generation
bluesadi Jan 9, 2025
e93c3e1
Implement ShowMacroSimplifier
bluesadi Jan 9, 2025
c016f67
Fix phi issue
bluesadi Jan 9, 2025
363ca49
Remove the incorrect import of Conditional from sqlalchemy.
ltfish Jan 9, 2025
82a88f1
damn
ltfish Jan 9, 2025
473fda0
Fix some shit
bluesadi Jan 9, 2025
514bedb
Fix bugs in _update_phi_variables_after_removing_block.
ltfish Jan 9, 2025
7106de6
OwnershipSimplifier: ins_addrs of block statements must monotonically…
ltfish Jan 9, 2025
87832d8
Fix some shit
bluesadi Jan 9, 2025
85c69e9
Fix some shit
bluesadi Jan 10, 2025
e740cbd
Fix some shit
bluesadi Jan 10, 2025
f5c4050
Fix some shit
bluesadi Jan 10, 2025
da226ce
Fix some bugs caused by rebasing
bluesadi Feb 24, 2025
0f9e07d
Rewrite RustCallConvention analysis and delete two unused simplificat…
bluesadi Feb 26, 2025
65f087a
Introduce PrePatternMatchSimplifier to duplicate return blocks to pre…
bluesadi Feb 28, 2025
7f92769
Rewrite RustCallingConventionAnalysis
bluesadi Mar 22, 2025
3127f83
Introduce StructMemoryLayout analysis
bluesadi Mar 28, 2025
ca90cbd
Implement LayoutInference for Arguments & Fix some bugs after new ssa…
bluesadi Apr 2, 2025
8fcf1e8
Implement StructMemoryLayoutAnalysis and refactor PatternMatchSimplifier
bluesadi Apr 15, 2025
f6365b7
Fix error propagation simplifier(for now). We may need some refactor …
bluesadi Apr 16, 2025
cf39b17
Preparing for new better Rust calling convention analysis
bluesadi Apr 16, 2025
da11344
Remove breakpoints
bluesadi Apr 16, 2025
e3eb0a8
Move Rust-specific statements and expressions to ailment
bluesadi Apr 17, 2025
7848295
Fix decompiled function signature display
bluesadi Apr 17, 2025
fd2d1fb
Adjust calling conventions and RustTypeLifter for Rust types
bluesadi Apr 18, 2025
50e8d95
Exploring StructMemoryLayoutAnalysis
bluesadi Apr 24, 2025
8f953de
Support returning struct to multiple registers (still buggy though)
bluesadi Apr 26, 2025
6b98ed7
Remove dead assignments after ErrorPropagationSimplification
bluesadi Apr 28, 2025
bb09903
Put most Rust optimization passes to BEFORE_VARIABLE_RECOVERY stage a…
bluesadi May 2, 2025
cd751cc
Implement StringCmpOutliner
bluesadi May 3, 2025
fc78664
Do not replace the sizes of virtual variables used in references
bluesadi May 4, 2025
5fa53d6
Do not simplify if-else structure for Rust binaries
bluesadi May 4, 2025
530fd3c
A temporary fix for JumpTableProcessor
bluesadi May 4, 2025
19558b7
Fix some bugs in PatternMatchSimplifier and CallConventions
bluesadi May 5, 2025
802d54d
Refactor cleanup_code_remover.py and introduce RedundantBlockRemover …
bluesadi May 7, 2025
2e6cb49
Fix a bug in SLivenessAnalysis
bluesadi May 9, 2025
12779fa
Refactor RustCallingConventionAnalysis again (maybe we need to implem…
bluesadi May 9, 2025
2a172ba
Fix stack virtual variable uses after creating new vvars
bluesadi May 10, 2025
833a13b
Integrate Enum into type system!
bluesadi May 12, 2025
b4fa1dc
Copy both graph and nodes in pre_pattern_match_simplifier.py
bluesadi May 12, 2025
21c7687
Add a heuristics to infer Result<(), Error>
bluesadi May 12, 2025
3632b27
Recover IfLet in PatternMatchSimplifier
bluesadi May 12, 2025
f2a60ec
Fix an indent bug in RustStructuredCodeGenerator
bluesadi May 14, 2025
1be74f5
Fix some bugs related to PatternMatchSimplifier and typeconsts
bluesadi May 14, 2025
b9ea527
Implement UnwrapOutliner and fix some bugs
bluesadi May 14, 2025
f385f13
Working on Known Function Prototype Application now (everything is st…
bluesadi May 27, 2025
a9636a3
Equip Oxidizer with Rust standard library structs dataset
bluesadi May 28, 2025
d12829d
Implement generalized StructMemoryLayout analysis
bluesadi May 29, 2025
29526e7
Introduce Rust standard library function prototypes
bluesadi May 30, 2025
372e565
Merge ailment into angr
bluesadi May 30, 2025
ac49df5
Fix Rust standard library structs and prototypes datasets
bluesadi May 30, 2025
772c126
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
871e113
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
4d5f623
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
2170145
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
20fe337
Start testing struct memory layout ground truth parser
bluesadi May 30, 2025
ff1ba2e
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 1, 2025
d676ae2
Fix some bugs in control flow optimization passes after introducing R…
bluesadi Jun 1, 2025
c9cd14e
Fix some bugs for malware samples
bluesadi Jun 2, 2025
685f929
Remove ipdb.set_trace()
bluesadi Jun 2, 2025
04e4c00
Implement constraint-based StructMemoryLayout analysis
bluesadi Jun 4, 2025
53e37e1
Remove redundant code in known_structs.py
bluesadi Jun 4, 2025
45df3b1
Refine StructMemoryLayout recovery to make it choose the first struct…
bluesadi Jun 5, 2025
2b867bb
Working on type hints collection
bluesadi Jun 28, 2025
a55221a
Sync
bluesadi Jun 28, 2025
6e3cca9
Refine _group_move_stmts_for_block
bluesadi Jun 29, 2025
507a5ad
Support translate typeconsts.Enum
bluesadi Jul 7, 2025
e6bb04f
Support Int128 in RustTypeLifter
bluesadi Jul 11, 2025
24408fd
Clean unused files and add known types database
bluesadi Jul 16, 2025
7017302
Improving type recovery
bluesadi Jul 18, 2025
ca70022
Support combo reg variable in function arguments
bluesadi Jul 25, 2025
e5e1d0c
Fix a return-by-memcpy bug in RustCallingConvention
bluesadi Jul 25, 2025
f6b7001
Fix some bugs
bluesadi Jul 28, 2025
08e4141
Upload type database
bluesadi Jul 28, 2025
c635b14
Update RustPseudocodeGenerator
bluesadi Jul 28, 2025
bcf7107
Add __init__.py to known_types
bluesadi Jul 29, 2025
0567a04
Fix unwrap_outliner.py
bluesadi Aug 3, 2025
c851bbe
Fix a rebasing bug in typeconsts.py
bluesadi Oct 5, 2025
f315ded
Implement PrintMacroSimplifier for uninlined situations
bluesadi Oct 20, 2025
ea89af6
Support recover str reference function arguments
bluesadi Oct 22, 2025
0ef6cc1
Simplify explicit deref coercion operations that have not been inlined.
bluesadi Oct 22, 2025
7993055
Fix a bug in StrArgumentSimplifier.try_str_literal
bluesadi Oct 22, 2025
85b1c83
Fix a bug in calculating Enum size
bluesadi Oct 28, 2025
47b30bb
Fix a bug in calculating Enum size
bluesadi Oct 28, 2025
24ba828
Support recovering Result<(), std::io::error::Error>
bluesadi Oct 28, 2025
9edd4e9
Support recovering Result<(), std::io::error::Error>
bluesadi Oct 28, 2025
728f047
CleanupCodeRemover now doesn't rely on symbols
bluesadi Oct 29, 2025
09c03ef
Implement FlirtSigPropagation
bluesadi Oct 31, 2025
49461f6
Fix parsing FLIRT signature bug
bluesadi Oct 31, 2025
c506bf6
Fix some rebase issues and implement CleanupFunctionIdentification
bluesadi Nov 3, 2025
afbcf94
Make CompleteCallingConventions selectively recover calling conventions
bluesadi Nov 4, 2025
feef33f
Support simplify write! and writeln!
bluesadi Nov 7, 2025
506d621
Support simplify write! and writeln! (fix some bug)
bluesadi Nov 7, 2025
ea581e4
Infer general enum types
bluesadi Nov 7, 2025
e90dc9f
Fix uninlined macro recovery
bluesadi Nov 7, 2025
f562fca
Fix const value collection bug in RustCallingConventionAnalysis
bluesadi Nov 7, 2025
5438a3d
Fix memcpy handling
bluesadi Nov 7, 2025
b1dcb6d
Do not aggressively remove functions
bluesadi Nov 7, 2025
87ba9d6
Apply Fish's fix in AILSimplifier
bluesadi Nov 7, 2025
093d19a
Propagate target function names in FormatMacroSimplifier
bluesadi Nov 8, 2025
551301e
Support another unlined format-like macro call pattern
bluesadi Nov 9, 2025
7b2402b
Fix a bug in deref coercion simplifier
bluesadi Nov 9, 2025
612acf0
Add a new pattern for FormatMacroSimplifier
bluesadi Nov 10, 2025
262d8ef
Implement a better pattern matching algorithm for FormatMacroSimplifier
bluesadi Nov 10, 2025
d2ad680
Implement a better pattern matching algorithm for FormatMacroSimplifier
bluesadi Nov 10, 2025
8229215
Implement a better pattern matching algorithm for FormatMacroSimplifier
bluesadi Nov 10, 2025
4471de4
Implement a better pattern matching algorithm for FormatMacroSimplifier
bluesadi Nov 10, 2025
01d5870
Fix a bug in RustStructuredCodeGenerator
bluesadi Nov 10, 2025
c0292a9
Fix the case when args structs are packed into one struct in FormatMa…
bluesadi Nov 10, 2025
134499c
Try to reduce enum recovery false positives
bluesadi Nov 10, 2025
c23dc24
Try to reduce enum recovery false positives
bluesadi Nov 10, 2025
14bef62
Implement RustcVersionIdentification
bluesadi Nov 11, 2025
351a2e2
Refine enum recovery
bluesadi Nov 11, 2025
36a542a
Refine enum recovery
bluesadi Nov 11, 2025
797cb79
Fix a bug in FormatMacroSimplifier
bluesadi Nov 14, 2025
7ceb1d0
Fix a bug in FormatMacroSimplifier
bluesadi Nov 14, 2025
47184a3
rust: bump pyo3 from 0.27.1 to 0.27.2
dependabot[bot] Dec 1, 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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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