def test_file_readwrite(): data = 'A'*512 with temporaryname() as filename: f = open(filename, 'wb') f.write(data) f.seek(0) f.close() z = provider.file(filename, mode='rw') z.store(data) z.seek(0) a = z.consume(len(data)) assert a == data z.close() raise Success
def test_file_writeonly(): data = 'A'*512 with temporaryname() as filename: f = open(filename, 'wb') f.write(data) f.seek(0) f.close() z = provider.file(filename, mode='w') z.store(data) z.seek(0) try: a = z.consume(len(data)) assert a == data except: raise Success finally: z.close() return
def test_file_readonly(): data = 'A'*512 with temporaryname() as filename: f = open(filename, 'wb') f.write(data) f.seek(0) f.close() z = provider.file(filename, mode='r') a = z.consume(len(data)) assert a == data try: z.store('nope') except: raise Success finally: z.close() raise Failure
('WIN_CERT_TYPE_X509', 0x0001), ('WIN_CERT_TYPE_PKCS7_SIGNED_DATA', 0x0002), ('WIN_CERT_TYPE_RESERVED_1', 0x0003), ('WIN_CERT_TYPE_TS_STACK_SIGNED', 0x0004), ] _fields_ = [ (uint32, 'dwLength'), (wRevision, 'wRevision'), (wCertificateType, 'wCertificateType'), (lambda s: dyn.block(s['dwLength'].li.int() - 8), 'bCertificate'), ] if __name__ == '__main__': from ptypes import provider import pecoff x = pecoff.Executable.IMAGE_DOS_HEADER() x.source = provider.file('./python.exe') offset = x.load()['e_lfanew'] print x # x = FileHeader() # x.source = provider.file('./python.exe') # x.setoffset( int(offset) ) # print x.load() x = pecoff.Executable.Portable() x.setoffset( int(offset) ) x.source = provider.file('./python.exe') print x.load()
('WIN_CERT_TYPE_X509', 0x0001), ('WIN_CERT_TYPE_PKCS7_SIGNED_DATA', 0x0002), ('WIN_CERT_TYPE_RESERVED_1', 0x0003), ('WIN_CERT_TYPE_TS_STACK_SIGNED', 0x0004), ] _fields_ = [ (uint32, 'dwLength'), (wRevision, 'wRevision'), (wCertificateType, 'wCertificateType'), (lambda s: dyn.block(s['dwLength'].li.int() - 8), 'bCertificate'), ] if __name__ == '__main__': from ptypes import provider import pecoff x = pecoff.Executable.Dos() x.source = provider.file('./python.exe') offset = x.load()['e_lfanew'] print x # x = FileHeader() # x.source = provider.file('./python.exe') # x.setoffset( int(offset) ) # print x.load() x = pecoff.Executable.Portable() x.setoffset( int(offset) ) x.source = provider.file('./python.exe') print x.load()
("WIN_CERT_TYPE_RESERVED_1", 0x0003), ("WIN_CERT_TYPE_TS_STACK_SIGNED", 0x0004), ] _fields_ = [ (uint32, "dwLength"), (wRevision, "wRevision"), (wCertificateType, "wCertificateType"), (lambda s: dyn.block(s["dwLength"].li.num() - 8), "bCertificate"), ] if __name__ == "__main__": from ptypes import provider import pecoff x = pecoff.Executable.Dos() x.source = provider.file("./python.exe") offset = x.load()["e_lfanew"] print x # x = FileHeader() # x.source = provider.file('./python.exe') # x.setoffset( int(offset) ) # print x.load() x = pecoff.Executable.Portable() x.setoffset(int(offset)) x.source = provider.file("./python.exe") print x.load()
return result _fields_ = [ (portable.FileHeader, 'Header'), (lambda s: ptypes.dynamic.clone(portable.SectionTableArray, length=s['Header'].li['NumberOfSections'].num()), 'Sections'), (__Data, 'Data'), ] if __name__ == '__main__': ## parse the file import sys, pecoff, ptypes from ptypes import provider print '-'*20 + 'loading file..' coff = pecoff.Object.File() coff.source = provider.file('../../obj/test.obj') coff.load() print coff['Header'] print coff['Sections'] ### check everything from the symbol table's perspective sst = coff['Header'].getsymbols() sst.load() symboltable = sst['Symbols'] print '-'*20 + 'printing external symbols' ## build list of external symbols sym_external = {} for name in sst.names(): v = sst.getSymbol(name)
return self['Header']['Machine'] if sig.isImportSignature( ) else sig['Machine'] def isImportLibrary(self): sig = self['Signature'] return sig.isImportSignature() if __name__ == '__main__': ## parse the file import sys, pecoff, ptypes from ptypes import provider import logging print('-' * 20 + 'loading file..') coff = pecoff.Object.File(source=provider.file(sys.argv[1])) coff.load() __name__ = 'ImportLibrary' if coff.isImportLibrary() else 'CoffObject' if __name__ == 'ImportLibrary': print(coff['Signature']) print(coff['Header']) print(coff['Data']) if __name__ == 'CoffObject': print(coff['Signature']) print(coff['Header']) print(coff['Sections']) ### check everything from the symbol table's perspective
def Machine(self): sig = self['Signature'] return self['Header']['Machine'] if sig.isImportSignature() else sig['Machine'] def isImportLibrary(self): sig = self['Signature'] return sig.isImportSignature() if __name__ == '__main__': ## parse the file import sys, pecoff, ptypes from ptypes import provider import logging print '-'*20 + 'loading file..' coff = pecoff.Object.File(source=provider.file(sys.argv[1])) coff.load() __name__ = 'ImportLibrary' if coff.isImportLibrary() else 'CoffObject' if __name__ == 'ImportLibrary': print coff['Signature'] print coff['Header'] print coff['Data'] if __name__ == 'CoffObject': print coff['Signature'] print coff['Header'] print coff['Sections'] ### check everything from the symbol table's perspective