Skip to content

Commit b3a31e6

Browse files
committed
Migrate away from deprecated angr CFG model API
1 parent cf3a298 commit b3a31e6

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

patcherex/techniques/stackretencryption.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def add_stackretencryption_to_function(self,start,ends):
176176

177177
tailp = []
178178
for i,e in enumerate(ends):
179-
bb_addr = self.patcher.cfg.get_any_node(e,anyaddr=True).addr
179+
bb_addr = self.patcher.cfg.model.get_any_node(e,anyaddr=True).addr
180180
code = self.add_patch_at_bb(bb_addr,is_tail=True)
181181
tailp.append(InsertCodePatch(e,code,name="stackretencryption_tail_%d_%d_%#x"%(self.npatch,i,start),priority=100))
182182

@@ -216,7 +216,7 @@ def function_to_patch_locations(self,ff):
216216
return None, None
217217

218218
def is_last_returning_block(self,node):
219-
node = self.patcher.cfg.get_any_node(node.addr)
219+
node = self.patcher.cfg.model.get_any_node(node.addr)
220220
try:
221221
function = self.patcher.cfg.functions[node.function_address]
222222
except KeyError:
@@ -227,7 +227,7 @@ def is_last_returning_block(self,node):
227227
return False
228228

229229
def last_block_to_return_locations(self,addr):
230-
node = self.patcher.cfg.get_any_node(addr)
230+
node = self.patcher.cfg.model.get_any_node(addr)
231231
if node == None:
232232
return []
233233
function = self.patcher.cfg.functions[node.function_address]
@@ -236,8 +236,8 @@ def last_block_to_return_locations(self,addr):
236236

237237
return_locations = []
238238
for site in self.inv_callsites[function.addr]:
239-
node = self.patcher.cfg.get_any_node(site)
240-
nlist = self.patcher.cfg.get_successors_and_jumpkind(node, excluding_fakeret=False)
239+
node = self.patcher.cfg.model.get_any_node(site)
240+
nlist = self.patcher.cfg.model.get_successors_and_jumpkind(node, excluding_fakeret=False)
241241
return_locations.extend([n[0] for n in nlist if n[1]=='Ijk_FakeRet'])
242242
return return_locations
243243

@@ -264,7 +264,7 @@ def get_reg_free_map(self):
264264
# map all basic block addresses in the function to which regs are read or written
265265
reg_free_map = dict()
266266
reg_not_free_map = dict()
267-
for n in self.patcher.cfg.nodes():
267+
for n in self.patcher.cfg.model.nodes():
268268

269269
if self.patcher.project.is_hooked(n.addr):
270270
continue
@@ -302,7 +302,7 @@ def get_reg_free_map(self):
302302

303303
def get_all_succ(self,addr):
304304
cfg = self.patcher.cfg
305-
all_nodes = cfg.get_all_nodes(addr)
305+
all_nodes = cfg.model.get_all_nodes(addr)
306306
if len(all_nodes) != 1:
307307
raise CfgError()
308308
n = all_nodes[0]
@@ -312,7 +312,7 @@ def get_all_succ(self,addr):
312312
return [n.addr for n in self.last_block_to_return_locations(addr)], False
313313

314314
all_succ = set()
315-
for s, jk in cfg.get_successors_and_jumpkind(n):
315+
for s, jk in cfg.model.get_successors_and_jumpkind(n):
316316
if not jk.startswith("Ijk_Sys"):
317317
all_succ.add(s.addr)
318318
# a syscall writes in eax, I do not handle it explicitly
@@ -370,7 +370,7 @@ def _func_is_safe(self, ident, func):
370370
return True
371371

372372
# skip functions that have enough predecessors
373-
if len(self.patcher.cfg.get_predecessors(self.patcher.cfg.get_any_node(func.addr))) > self.safe_calls_limit:
373+
if len(self.patcher.cfg.model.get_predecessors(self.patcher.cfg.model.get_any_node(func.addr))) > self.safe_calls_limit:
374374
return True
375375

376376
is_safe = True

tests/test_cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def last_block_to_callers(addr,cfg,inv_callsites):
5959
return_locations = []
6060
for site in inv_callsites[function.addr]:
6161
node = cfg.model.get_any_node(site)
62-
nlist = cfg.get_successors_and_jumpkind(node, excluding_fakeret=False)
62+
nlist = cfg.model.get_successors_and_jumpkind(node, excluding_fakeret=False)
6363
return_locations.extend([n[0] for n in nlist if n[1]=='Ijk_FakeRet'])
6464
return return_locations
6565

tests/test_techniques.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,8 @@ def test_countdown_1(BackendClass, data_fallback, try_pdf_removal):
13171317
pipe = subprocess.PIPE
13181318
p = subprocess.Popen([tmp_file], stdin=pipe, stdout=pipe, stderr=pipe)
13191319
res = p.communicate(b"foo\ntest\n")
1320+
print(f'got: {res[0]}')
1321+
print(f'expected: {expected_output}')
13201322
assert expected_output == res[0]
13211323

13221324

0 commit comments

Comments
 (0)