67
67
bv.get_symbol_by_raw_name(' __builtin_strncpy' ).address
68
68
]
69
69
70
- list (current_hlil.traverse(find_strcpy, t))
70
+ # Find the first call to a builtin:
71
+ for result in current_hlil.traverse(find_strcpy, t):
72
+ # Any logic should live here, not inside the callable which is just for
73
+ # matching. Because this is a generator, it can fail fast when used for
74
+ # search!
75
+ print (result)
76
+ break
71
77
72
78
73
79
def get_memcpy_data (i , t ) -> bytes :
@@ -77,7 +83,8 @@ def get_memcpy_data(i, t) -> bytes:
77
83
78
84
# Iterate through all instructions in the HLIL
79
85
t = bv.get_symbol_by_raw_name(' __builtin_memcpy' ).address
80
- list (current_hlil.traverse(get_memcpy_data, t))
86
+ for i in current_hlil.traverse(get_memcpy_data, t):
87
+ print (f " Found some memcpy data: { repr (i)} " )
81
88
82
89
83
90
# find all the calls to __builtin_strcpy and get their values
@@ -90,13 +97,20 @@ t = [
90
97
bv.get_symbol_by_raw_name(' __builtin_strcpy' ).address,
91
98
bv.get_symbol_by_raw_name(' __builtin_strncpy' ).address
92
99
]
93
- list (current_hlil.traverse(find_strcpy, t))
100
+
101
+ for i in current_hlil.traverse(find_strcpy, t):
102
+ print (i)
94
103
95
104
# collect the number of parameters for each function call
96
105
def param_counter (i ) -> int :
97
106
match i:
98
107
case HighLevelILCall():
99
108
return len (i.params)
109
+
110
+ # Note that the results are a generator and usually anything that is found
111
+ # should have processing done outside the callback, but you can always
112
+ # convert it to a list like this:
113
+
100
114
list (current_hlil.traverse(param_counter))
101
115
102
116
@@ -105,6 +119,7 @@ def collect_call_target(i) -> None:
105
119
match i:
106
120
case HighLevelILCall(dest = HighLevelILConstPtr(constant = c)):
107
121
return c
122
+
108
123
set ([hex (a) for a in current_hlil.traverse(collect_call_target)])
109
124
110
125
@@ -113,6 +128,7 @@ def collect_this_vars(i) -> Variable:
113
128
match i:
114
129
case HighLevelILVar(var = v) if v.name == ' this' :
115
130
return v
131
+
116
132
list (v for v in current_hlil.traverse(collect_this_vars))
117
133
118
134
```
0 commit comments