Skip to content

Commit

Permalink
Better presentation for stack padding slots
Browse files Browse the repository at this point in the history
  • Loading branch information
zachriggle committed Oct 3, 2017
1 parent 66d8513 commit dbdc2ef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pwnlib/rop/rop.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class Padding(object):
"""
Placeholder for exactly one pointer-width of padding.
"""
def __init__(self, name='<pad>'):
self.name = name

class DescriptiveStack(list):
"""
Expand Down Expand Up @@ -483,14 +485,20 @@ def setRegisters(self, registers):
stack = []

for gadget in winner:
moved = 8 # Account for the gadget itself
goodregs = set(gadget.regs) & regset
name = ",".join(goodregs)
stack.append((gadget.address, gadget))
for r in gadget.regs:
moved += 8
if r in registers:
stack.append((registers[r], r))
else:
stack.append((Padding(), r))
stack.append((Padding('<pad %s>' % r), r))

for slot in range(moved, gadget.move, context.bytes):
left = gadget.move - slot
stack.append((Padding('<pad %#x>' % left), 'stack padding'))

return stack

Expand Down Expand Up @@ -717,7 +725,7 @@ def build(self, base = None, description = None):

elif isinstance(slot, Padding):
stack[i] = self.generatePadding(i * context.bytes, context.bytes)
stack.describe('<pad>', slot_address)
stack.describe(slot.name, slot_address)

elif isinstance(slot, Gadget):
stack[i] = slot.address
Expand Down

0 comments on commit dbdc2ef

Please sign in to comment.