Skip to content

Commit

Permalink
Fix ROP.call(Function(...)) breaking dump()
Browse files Browse the repository at this point in the history
Fixes #770
  • Loading branch information
zachriggle committed Nov 10, 2016
1 parent 6c304d3 commit 30c34b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Exposes functionality for manipulating ELF files
"""
import codecs
import mmap
import os
import subprocess
Expand Down Expand Up @@ -30,7 +31,18 @@

__all__ = ['load', 'ELF']

Function = namedtuple('Function', 'address size')
class Function(object):
def __init__(self, name, address, size):
self.name = name
self.address = address
self.size = size
def __repr__(self):
return '%s(name=%r, address=%#x, size=%#x)' % (
self.__class__.__name__,
self.name,
self.address,
self.size
)

def load(*args, **kwargs):
"""Compatibility wrapper for pwntools v1"""
Expand Down Expand Up @@ -348,11 +360,15 @@ def _populate_functions(self):
continue
if sym.entry.st_info['type'] == 'STT_FUNC' and sym.entry.st_size != 0:
name = sym.name
try:
name = codecs.encode(name, 'latin-1')
except Exception:
pass
if name not in self.symbols:
continue
addr = self.symbols[name]
size = sym.entry.st_size
self.functions[name] = Function(addr, size)
self.functions[name] = Function(name, addr, size)

def _populate_symbols(self):
"""
Expand Down
3 changes: 3 additions & 0 deletions pwnlib/rop/rop.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,9 @@ def call(self, resolvable, arguments = (), abi = None, **kwargs):
# If we can find a function with that name, just call it
if isinstance(resolvable, str):
addr = self.resolve(resolvable)
elif hasattr(resolvable, 'name') and hasattr(resolvable, 'address'):
addr = resolvable.address
resolvable = str(resolvable.name)
else:
addr = resolvable
resolvable = ''
Expand Down

0 comments on commit 30c34b7

Please sign in to comment.