Skip to content

Commit 7ce1b07

Browse files
committed
allow stack_change to be negative
1 parent 62a08ab commit 7ce1b07

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

angrop/gadget_finder/gadget_analyzer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,12 @@ def _check_if_stack_controls_ast(self, ast, initial_state, gadget_stack_change=N
628628

629629
return ans
630630

631+
def _to_signed(self, value):
632+
bits = self.project.arch.bits
633+
if value >> (bits-1): # if the MSB is 1, this value is negative
634+
value -= (1<<bits)
635+
return stack_change
636+
631637
def _compute_sp_change(self, init_state, final_state, gadget):
632638
"""
633639
Computes the change in the stack pointer for a gadget
@@ -655,7 +661,7 @@ def _compute_sp_change(self, init_state, final_state, gadget):
655661
if len(stack_changes) != 1:
656662
raise RopException("SP change is symbolic")
657663

658-
gadget.stack_change = stack_changes[0]
664+
gadget.stack_change = self._to_signed(stack_changes[0])
659665

660666
elif type(gadget) is PivotGadget:
661667
# FIXME: step_to_unconstrained_successor is not compatible with conditional_branches
@@ -673,7 +679,7 @@ def _compute_sp_change(self, init_state, final_state, gadget):
673679
break
674680
prev_act = act
675681
if last_sp is not None:
676-
gadget.stack_change = (last_sp - init_state.regs.sp).concrete_value
682+
gadget.stack_change = self._to_signed((last_sp - init_state.regs.sp).concrete_value)
677683
else:
678684
gadget.stack_change = 0
679685

0 commit comments

Comments
 (0)