Skip to content

Commit 30c34b7

Browse files
committed
Fix ROP.call(Function(...)) breaking dump()
Fixes #770
1 parent 6c304d3 commit 30c34b7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

pwnlib/elf/elf.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Exposes functionality for manipulating ELF files
22
"""
3+
import codecs
34
import mmap
45
import os
56
import subprocess
@@ -30,7 +31,18 @@
3031

3132
__all__ = ['load', 'ELF']
3233

33-
Function = namedtuple('Function', 'address size')
34+
class Function(object):
35+
def __init__(self, name, address, size):
36+
self.name = name
37+
self.address = address
38+
self.size = size
39+
def __repr__(self):
40+
return '%s(name=%r, address=%#x, size=%#x)' % (
41+
self.__class__.__name__,
42+
self.name,
43+
self.address,
44+
self.size
45+
)
3446

3547
def load(*args, **kwargs):
3648
"""Compatibility wrapper for pwntools v1"""
@@ -348,11 +360,15 @@ def _populate_functions(self):
348360
continue
349361
if sym.entry.st_info['type'] == 'STT_FUNC' and sym.entry.st_size != 0:
350362
name = sym.name
363+
try:
364+
name = codecs.encode(name, 'latin-1')
365+
except Exception:
366+
pass
351367
if name not in self.symbols:
352368
continue
353369
addr = self.symbols[name]
354370
size = sym.entry.st_size
355-
self.functions[name] = Function(addr, size)
371+
self.functions[name] = Function(name, addr, size)
356372

357373
def _populate_symbols(self):
358374
"""

pwnlib/rop/rop.py

+3
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@ def call(self, resolvable, arguments = (), abi = None, **kwargs):
700700
# If we can find a function with that name, just call it
701701
if isinstance(resolvable, str):
702702
addr = self.resolve(resolvable)
703+
elif hasattr(resolvable, 'name') and hasattr(resolvable, 'address'):
704+
addr = resolvable.address
705+
resolvable = str(resolvable.name)
703706
else:
704707
addr = resolvable
705708
resolvable = ''

0 commit comments

Comments
 (0)