1+ from typing import Any , Union , List , Optional , Iterable , Callable
2+ import z3 # Assuming Z3 is imported for type annotations
3+
4+
5+ class SpaceInfo :
6+ # Placeholder for SpaceInfo class
7+ ...
8+
9+ class VarNode :
10+ def __init__ (self , space_index : int , offset : int , size : int ) -> None : ...
11+
12+ class RawVarNodeDisplay :
13+ def __init__ (self , offset : int , size : int , space_info : SpaceInfo ) -> None : ...
14+
15+ class VarNodeDisplay :
16+ def __init__ (self , raw : RawVarNodeDisplay = ..., register : tuple [str , VarNode ] = ...) -> None : ...
17+ # Represents the enum variants Raw and Register
18+ raw : RawVarNodeDisplay
19+ register : tuple [str , VarNode ]
20+
21+
22+ class ResolvedIndirectVarNode :
23+ def __init__ (self , pointer : Any , pointer_space_info : SpaceInfo , access_size_bytes : int ) -> None : ...
24+
25+ def pointer_bv (self ) -> z3 .BitVecRef : ...
26+ def space_name (self ) -> str : ...
27+ def access_size (self ) -> int : ...
28+
29+
30+ class ResolvedVarNode :
31+ """
32+ Represents the PythonResolvedVarNode enum with two variants:
33+ - Direct: Contains a VarNodeDisplay
34+ - Indirect: Contains a ResolvedIndirectVarNode
35+ """
36+ def __init__ (self , value : Union [VarNodeDisplay , ResolvedIndirectVarNode ]) -> None : ...
37+ value : Union [VarNodeDisplay , ResolvedIndirectVarNode ]
38+
39+
40+ class PcodeOperation :
41+ pass
42+
43+
44+ class Instruction :
45+ """
46+ Represents a Python wrapper for a Ghidra instruction.
47+ """
48+ disassembly : str
49+ def pcode (self ) -> List [PcodeOperation ]: ...
50+
51+ class State :
52+ def __init__ (self , jingle : JingleContext ) -> State : ...
53+
54+ def varnode (self , varnode : ResolvedVarNode ) -> z3 .BitVecRef : ...
55+ def register (self , name : str ) -> z3 .BitVecRef : ...
56+ def ram (self , offset : int , length : int ) -> z3 .BitVecRef : ...
57+
58+ class ModeledInstruction :
59+ original_state : State
60+ final_state : State
61+
62+ def get_input_vns (self ) -> Iterable [ResolvedVarNode ]: ...
63+ def get_output_vns (self ) -> Iterable [ResolvedVarNode ]: ...
64+
65+ class ModeledBlock :
66+ original_state : State
67+ final_state : State
68+ def get_input_vns (self ) -> Iterable [ResolvedVarNode ]: ...
69+ def get_output_vns (self ) -> Iterable [ResolvedVarNode ]: ...
70+
71+ class JingleContext :
72+ def __init__ (self , binary_path : str , ghidra : str ) -> JingleContext : ...
73+ def model_instruction_at (self , offset : int ) -> ModeledInstruction : ...
74+ def model_block_at (self , offset : int , max_instrs : int ) -> ModeledBlock : ...
75+
76+ class SleighContext :
77+ """
78+ Represents a Sleigh context in python.
79+ """
80+ def __init__ (self , binary_path : str , ghidra : str ) -> SleighContext : ...
81+ base_address : int
82+ def instruction_at (self , offset : int ) -> Optional [Instruction ]: ...
83+ def make_jingle_context (self ) -> JingleContext : ...
84+
85+
86+ """
87+ Begin crackers types
88+ """
89+
90+ class CrackersLogLevel :
91+ Debug = CrackersLogLevel .Debug
92+ Error = CrackersLogLevel .Error
93+ Info = CrackersLogLevel .Info
94+ Trace = CrackersLogLevel .Trace
95+ Warn = CrackersLogLevel .Warn
96+
97+ class MetaConfig :
98+ seed : int
99+ log_level : CrackersLogLevel
100+
101+ class SpecificationConfig :
102+ path : str
103+ max_instructions : int
104+ base_address : Optional [int ]
105+
106+ class GadgetLibraryConfig :
107+ max_gadget_length : int
108+ path : str
109+ sample_size : Optional [int ]
110+ base_address : Optional [int ]
111+
112+ class SleighConfig :
113+ ghidra_path : str
114+
115+ class SynthesisSelectionStrategy :
116+ SatStrategy = SynthesisSelectionStrategy .SatStrategy
117+ OptimizeStrategy = SynthesisSelectionStrategy .OptimizeStrategy
118+
119+ class SynthesisConfig :
120+ strategy : SynthesisSelectionStrategy
121+ max_candidates_per_slot : int
122+ parallel : int
123+ combine_instructions : bool
124+
125+ class MemoryEqualityConstraint :
126+ space : str
127+ address : int
128+ size : int
129+ value : int
130+
131+ class StateEqualityConstraint :
132+ register : Optional [dict [str , int ]]
133+ pointer : Optional [dict [str , str ]]
134+ memory : Optional [MemoryEqualityConstraint ]
135+
136+ class PointerRange :
137+ min : int
138+ max : int
139+ class PointerRangeConstraints :
140+ read : Optional [list [PointerRange ]]
141+ class ConstraintConfig :
142+ precondition : Optional [StateEqualityConstraint ]
143+ postcondition : Optional [StateEqualityConstraint ]
144+ pointer : Optional [PointerRangeConstraints ]
145+
146+
147+ class CrackersConfig :
148+ meta : MetaConfig
149+ spec : SpecificationConfig
150+ library : GadgetLibraryConfig
151+ sleigh : SleighConfig
152+ synthesis : SynthesisConfig
153+ constraint : ConstraintConfig
154+
155+ @classmethod
156+ def from_toml (cls , path : str ) -> CrackersConfig : ...
157+
158+ def resolve_config (self ) -> SynthesisParams : ...
159+
160+ class AssignmentModel :
161+ def eval_bv (self , bv : z3 .BitVecRef , model_completion : bool ) -> z3 .BitVecRef : ...
162+ def initial_state (self ) -> Optional [State ]: ...
163+ def final_state (self ) -> Optional [State ]: ...
164+ def gadgets (self ) -> list [ModeledBlock ]: ...
165+ def inputs (self ) -> Iterable [ResolvedVarNode ]: ...
166+ def outputs (self ) -> Iterable [ResolvedVarNode ]: ...
167+ def input_summary (self , model_completion : bool ): Iterable [tuple [str , z3 .BitVecRef ]]
168+ def output_summary (self , model_completion : bool ): Iterable [tuple [str , z3 .BitVecRef ]]
169+
170+
171+ class PythonDecisionResult_AssignmentFound (DecisionResult ):
172+ _0 : AssignmentModel
173+ __match_args__ = ('_0' ,)
174+
175+
176+ class SelectionFailure :
177+ indices : list [int ]
178+
179+ class PythonDecisionResult_Unsat (DecisionResult ):
180+ _0 : SelectionFailure
181+ pass
182+
183+ class DecisionResult :
184+ AssignmentFound : PythonDecisionResult_AssignmentFound
185+ Unsat : PythonDecisionResult_Unsat
186+
187+ DecisionResultType = Union [DecisionResult .AssignmentFound , DecisionResult .Unsat ]
188+
189+ type StateConstraintGenerator = Callable [[State , int ], z3 .BitVecRef ]
190+ type TransitionConstraintGenerator = Callable [[ModeledBlock ], z3 .BitVecRef ]
191+ class SynthesisParams :
192+ def run (self ) -> DecisionResultType : ...
193+ def add_precondition (self , fn : StateConstraintGenerator ): ...
194+ def add_postcondition (self , fn : StateConstraintGenerator ): ...
195+ def add_transition_constraint (self , fn : TransitionConstraintGenerator ): ...
196+ pass
0 commit comments