Skip to content

Commit

Permalink
example: ltrace
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrewh committed May 8, 2024
1 parent 6d00acf commit e5f3e22
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions examples/ltrace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from pyda import *
from pwnlib.elf.elf import ELF
from pwnlib.util.packing import u64
import string
import sys

p = process()

e = ELF(p.exe_path)
e.address = p.maps[p.exe_path].base

plt_map = { e.plt[x]: x for x in e.plt }

def guess_arg(x):
printable_chars = bytes(string.printable, 'ascii')

# Is pointer?
if x > 0x100000000:
try:
data = p.read(x, 0x20)
if all([c in printable_chars for c in data[:4]]):
return str(data[:data.index(0)])
except:
pass

return hex(x)

def lib_hook(p):
name = plt_map[p.regs.rip]
print(f"{name}(" + ", ".join([
f"rdi={guess_arg(p.regs.rdi)}",
f"rsi={guess_arg(p.regs.rsi)}",
f"rdx={guess_arg(p.regs.rdx)}",
f"rcx={guess_arg(p.regs.rcx)}",
]) + ")")

for x in e.plt:
p.hook(e.plt[x], lib_hook)

p.run()

0 comments on commit e5f3e22

Please sign in to comment.