mirror of
https://github.com/vivisect/vivisect
synced 2026-06-08 18:04:23 +00:00
80de840881
A lot of cleanup things in prep for a python 3 transition. Getting rid of the old exception syntax, converting prints over to logging, cutting random scraps of code to be proper unit tests, cut away some older bits of code, etc. This still works in python2. It's just a lot of tidying up. There are no major functionality changes.
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import sys
|
|
import argparse
|
|
|
|
import PE
|
|
import vtrace.platforms.win32 as vt_win32
|
|
|
|
|
|
def setup():
|
|
ap = argparse.ArgumentParser(help='Dump PE structures')
|
|
ap.add_argument('file')
|
|
return ap
|
|
|
|
|
|
def main(argv):
|
|
opts = setup().parse_args(argv)
|
|
with open(opts.file, 'rb') as f:
|
|
p = PE.PE(f)
|
|
baseaddr = p.IMAGE_NT_HEADERS.OptionalHeader.ImageBase
|
|
osmajor = p.IMAGE_NT_HEADERS.OptionalHeader.MajorOperatingSystemVersion
|
|
osminor = p.IMAGE_NT_HEADERS.OptionalHeader.MinorOperatingSystemVersion
|
|
machine = p.IMAGE_NT_HEADERS.FileHeader.Machine
|
|
|
|
vsver = p.getVS_VERSIONINFO()
|
|
|
|
archname = PE.machine_names.get(machine)
|
|
|
|
parser = vt_win32.Win32SymbolParser(0xffffffff, opts.file, baseaddr)
|
|
parser.parse()
|
|
|
|
t = parser._sym_types.values()
|
|
e = parser._sym_enums.values()
|
|
builder = VStructBuilder(defs=t, enums=e)
|
|
|
|
print('# Version: %d.%d' % (osmajor, osminor))
|
|
print('# Architecture: %s' % archname)
|
|
if vsver is not None:
|
|
keys = vsver.getVersionKeys()
|
|
keys.sort()
|
|
for k in keys:
|
|
val = vsver.getVersionValue(k)
|
|
if type(val) == unicode:
|
|
val = val.encode('ascii','ignore')
|
|
print('# %s: %s' % (k,val))
|
|
print(builder.genVStructPyCode())
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main(sys.argv[1:]))
|