def parse_stream(stream): dbihdr = DBIHeader.parse_stream(stream) dbi_size = dbihdr._end - dbihdr._start dbiexhdr_data = stream.read(dbihdr.module_size) dbiexhdrs = [] while dbiexhdr_data: dbiexhdrs.append(DBIExHeader.parse(dbiexhdr_data)) sz = aligned4(get_parsed_size(dbiexhdrs[-1])) dbiexhdr_data = dbiexhdr_data[sz:] offdata = OffsetData(dbihdr.offset_size).parse_stream(stream) hashdata = HashData(dbihdr.hash_size).parse_stream(stream) srcmoduledata = SrcModuleData(dbihdr.srcmodule_size).parse_stream(stream) pdbimportdata = PdbImportData(dbihdr.pdbimport_size).parse_stream(stream) unknown2data = Unknown2Data(dbihdr.unk2_size).parse_stream(stream) import psi streamindexesdata = psi.parse_stream(stream) return Container(DBIHeader=dbihdr, DBIExHeaders=ListContainer(dbiexhdrs), OffsetData=offdata, HashData=hashdata, SrcModuleData=srcmoduledata, PdbImportData=pdbimportdata, StreamIndexesData=streamindexesdata)
}, default = Pass, ), ) """ GlobalsData = GreedyRange( Tunnel( PascalString('globals', length_field=ULInt16('len')), gsym, ) ) """ GlobalsData = GreedyRange(Struct("globals", ULInt16("length"), Value("sizeof", lambda ctx: ctx.length > 0 and aligned4(ctx.length)-2 or 0), Tunnel( Field('globals', lambda ctx: ctx.sizeof), gsym, ), )) def parse(data, offset=0): return parse_stream(StringIO(data), offset) def parse_stream(stream, offset=0): if offset > 0: stream.seek(offset, 1) con = GlobalsData.parse_stream(stream) for sc in con: merge_subcon(sc, 'globals')