Ayuto

Interface dumper

Dec 7th, 2013
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. # =============================================================================
  2. # >> IMPORTS
  3. # =============================================================================
  4. # Python
  5. from __future__ import with_statement
  6.  
  7. import pprint
  8. import os
  9. import time
  10.  
  11. from path import path
  12.  
  13. # EventScripts
  14. import es
  15.  
  16. # binutils
  17. import binutils
  18.  
  19.  
  20. # =============================================================================
  21. # >> FUNCTIONS
  22. # =============================================================================
  23. def get_interface_register(dump_file, allowed_ext=('.dll', '.so')):
  24.     if not dump_file.endswith(allowed_ext):
  25.         return None
  26.  
  27.     try:
  28.         binary = binutils.find_binary(dump_file, False)
  29.     except:
  30.         return None
  31.  
  32.     if os.name == 'posix':
  33.         ref = binary['_ZN12InterfaceReg16s_pInterfaceRegsE']
  34.     else:
  35.         ref = binary.find_pointer('\x55\x8B\xEC\x56\x8B\x35\x2A\x2A\x2A\x2A\x57\x85\xF6\x74\x2A\x8B\x7D\x08\x8B\x46\x04', 6)
  36.  
  37.     if not ref:
  38.         return None
  39.  
  40.     return ref.get_ptr()
  41.  
  42. def dump_interface(dump_file):
  43.     register = get_interface_register(dump_file)
  44.     if not register:
  45.         return None
  46.  
  47.     interfaces = set()
  48.  
  49.     # Loop through all interface versions and add them to the set
  50.     while register:
  51.         interfaces.add(register.get_string(4))
  52.         register = register.get_ptr(8)
  53.  
  54.     return sorted(interfaces)
  55.  
  56. def dump_interfaces(output_file):
  57.     with open(output_file, 'w') as f:
  58.         f.write('# Created at: %s\n\n'% time.ctime())
  59.  
  60.         for dump_file in path(os.getcwd()).joinpath('bin').files() + path(es.getString('eventscripts_gamedir')).joinpath('bin').files():
  61.             dump = dump_interface(str(dump_file))
  62.             if not dump:
  63.                 continue
  64.  
  65.             f.write('# %s\n'% dump_file.relpath().replace('\\', '/'))
  66.             f.write(pprint.pformat(dump))
  67.             f.write('\n\n')
  68.  
  69.  
  70. # =============================================================================
  71. # >> START DUMP
  72. # =============================================================================
  73. dump_interfaces(path(__file__).parent.joinpath('output.txt'))
Add Comment
Please, Sign In to add comment