Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # >> IMPORTS
- # =============================================================================
- # Python
- from __future__ import with_statement
- import os
- import pprint
- import time
- from path import path
- # binutils
- import binutils
- # =============================================================================
- # >> CONSTANTS
- # =============================================================================
- # On Linux it's 4 bytes bigger
- NEXT_DESC_OFFSET = 52 if os.name == 'nt' else 56
- # =============================================================================
- # >> FUNCTIONS
- # =============================================================================
- def symbol_is_datamap(symbol):
- return not symbol.startswith('_GLOBAL') and '9m_DataMapE' in symbol
- def dump_datamap(datamap):
- dump = {}
- # Get the data map's name
- classname = datamap.get_string(8)
- def dump_dmap(proppath, dmap, offset=0):
- # Get the base description
- basedesc = dmap.get_ptr()
- # Loop through all properties in this data map
- for x in xrange(dmap.get_int(4)):
- # Get the current description
- desc = basedesc + (NEXT_DESC_OFFSET * x)
- # Get the property's name
- name = desc.get_string(4)
- # Does the property have no name or is it a function?
- if not name or desc.get_ptr(28):
- continue
- temppath = proppath + '.' + name
- # Calculate the current offset
- tempoffset = offset + desc.get_int(8)
- # Is there no embedded datamap?
- td = desc.get_ptr(32)
- if not td:
- dump[temppath] = (
- tempoffset,
- desc.get_string(20),
- desc.get_int()
- )
- else:
- # Dump the embedded data map, too!
- dump_dmap(temppath, td, tempoffset)
- # Dump the data map and its subclasses
- while datamap:
- dump_dmap(datamap.get_string(8), datamap)
- datamap = datamap.get_ptr(12)
- return classname, dump
- def dump_file(dump_file, output_file):
- binary = binutils.find_binary(dump_file, False)
- with open(output_file, 'w') as f:
- f.write('# Created at: %s\n'% time.ctime())
- f.write('# File: %s\n'% dump_file)
- f.write('# <property path>: (<Linux offset>, <external name>, <field type>)\n')
- f.write('# Estimated Windows offset: <Linux offset> - 20\n\n')
- datamap_count = 0
- # Loop through all symbols of the file
- for symbol_info in os.popen('nm %s'% dump_file).read().split('\n'):
- if not symbol_info:
- continue
- symbol = symbol_info.rsplit(' ', 1)[1]
- # Is the the symbol no data map?
- if not symbol_is_datamap(symbol):
- continue
- datamap_count += 1
- classname, dump = dump_datamap(binary[symbol])
- f.write('# Class: %s\n'% classname)
- f.write(pprint.pformat(dump, width=200) + '\n\n')
- f.write('# Dumped a total of %s data maps!'% datamap_count)
- # =============================================================================
- # >> START DUMPING
- # =============================================================================
- dump_file('cstrike/bin/server_srv.so', path(__file__).parent.joinpath('output.txt'))
Add Comment
Please, Sign In to add comment