Advertisement
opexxx

execution_tracer.py

Apr 23rd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. import re
  2. import sys
  3. import pefile
  4. from pydbg import *
  5. from pydbg.defines import *
  6.  
  7. def parseidalog(file):
  8. all_funcs = []
  9. f = open(file)
  10. funcs = f.readlines()
  11. f.close()
  12. for func in funcs:
  13. if 'sub_' in func:
  14. m = re.search('.text .+ 0', func)
  15. addr = '0x'+m.group(0)[6:-2].replace('\n','')
  16. addr = int(addr, 16)
  17. all_funcs.append(addr)
  18. return all_funcs
  19. def printeip(dbg):
  20. eip = dbg.context.Eip
  21. if eip not in most_used_funcs:
  22. most_used_funcs.append(eip)
  23. print 'Break Point Hit ', hex(eip)
  24. return DBG_CONTINUE
  25. def setallbp(dbg):
  26. for fun in all_func:
  27. #print '[+] Setting soft bp on ',hex(fun)
  28. dbg.bp_set(fun,handler=printeip)
  29. return DBG_CONTINUE
  30. def main():
  31. global all_func
  32. global most_used_funcs
  33. most_used_funcs = []
  34. all_func = parseidalog('ida-export.txt')
  35. dbg = pydbg()
  36. exe_file = sys.argv[1]
  37. pe = pefile.PE(exe_file)
  38. dbg = pydbg()
  39. dbg.load(exe_file)
  40. entry = pe.OPTIONAL_HEADER.ImageBase + pe.OPTIONAL_HEADER.AddressOfEntryPoint
  41. dbg.bp_set(entry,handler=setallbp)
  42. dbg.run()
  43.  
  44. if __name__ == '__main__':
  45. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement