Files
James Gross a7b5f8deef Py3 cutover (try number: who knows?) (#328)
Massive cutover to python3 (baseline is 3.9.1, but is also tested/working on 3.7.x). This merge is a breaking change for any downstream consumers, as the python 2->3 strings/bytes change is central. Most APIs should still work roughly as intended, as I didn't majorly re-organize the codebase, so most APIs live where they lived before. But a changelog/migration guide will be included in the next PR for this.

This PR will constitute most if not all of the v1.0.0 release that is forthcoming soon.
2021-02-03 14:37:09 -05:00

48 lines
1.3 KiB
Python

import sys
import argparse
import PE
import vtrace.platforms.win32 as vt_win32
import vstruct.builder as vs_builder
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 = vs_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)
print('# %s: %s' % (k, val))
print(builder.genVStructPyCode())
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))