def linkDirectiveSection(self): sect = coffSection() sect.Name = '.drectve' sect.Flags = (SectionFlags.LNK_REMOVE | SectionFlags.LNK_INFO | SectionFlags.ALIGN_1BYTES) sect.RawData = self.directives sym = self.coff.Symbols.GetSymbol('.drectve') sym.RebuildAuxiliaries(len(sect.RawData),0,0,crc32(sect.RawData),0,0) return sect
def linkDirectiveSection(self): sect = coffSection() sect.Name = '.drectve' sect.Flags = (SectionFlags.LNK_REMOVE | SectionFlags.LNK_INFO | SectionFlags.ALIGN_1BYTES) sect.RawData = self.directives sym = self.coff.Symbols.GetSymbol('.drectve') sym.RebuildAuxiliaries(len(sect.RawData), 0, 0, crc32(sect.RawData), 0, 0) return sect
def rdataSection(self): sect = coffSection() sect.Name = '.rdata\x00\x00' sect.Flags = (SectionFlags.LNK_COMDAT | SectionFlags.CNT_INITIALIZED_DATA | SectionFlags.MEM_READ | SectionFlags.ALIGN_4BYTES) sect.RawData = self.cp.Data sym = self.coff.Symbols.GetSymbol('.rdata\x00\x00') sym.RebuildAuxiliaries(len(sect.RawData),0,0,crc32(sect.RawData),0,0) return sect
def rdataSection(self): sect = coffSection() sect.Name = '.rdata\x00\x00' sect.Flags = (SectionFlags.LNK_COMDAT | SectionFlags.CNT_INITIALIZED_DATA | SectionFlags.MEM_READ | SectionFlags.ALIGN_4BYTES) sect.RawData = self.cp.Data sym = self.coff.Symbols.GetSymbol('.rdata\x00\x00') sym.RebuildAuxiliaries(len(sect.RawData), 0, 0, crc32(sect.RawData), 0, 0) return sect
def textSection(self): sect = coffSection() sect.Name = '.text\x00\x00\x00' sect.Flags = (SectionFlags.CNT_CODE | SectionFlags.LNK_COMDAT | SectionFlags.MEM_EXECUTE | SectionFlags.MEM_READ | SectionFlags.ALIGN_16BYTES) sect.RawData = self.cp.Code for patchin in self.cp.CodePatchins: # How do I tell what type it is? addr = patchin[1] if patchin[2] == DIRECT: patchinType = RelocationTypes.I386_DIR32 elif patchin[2] == RELATIVE: patchinType = RelocationTypes.I386_REL32 else: raise RuntimeError("Invalid patchin type") try: loc = self.coff.Symbols.GetLocation(patchin[0]) r = coffRelocationEntry(addr,loc,typ=patchinType) except coffError: r = coffRelocationEntry(addr,0x0,typ=patchinType) sect.RelocationData.append(r) sym = self.coff.Symbols.GetSymbol('.text\x00\x00\x00') sym.RebuildAuxiliaries(len(sect.RawData),len(self.cp.CodePatchins),0, crc32(sect.RawData),0,0) # attempt to add line numbers for sym in self.cp.CodeSymbols: symLoc = self.coff.Symbols.GetLocation(sym[0]) sect.LineNumberData.append(coffLineNumberEntry(symLoc,0x0)) return sect
def textSection(self): sect = coffSection() sect.Name = '.text\x00\x00\x00' sect.Flags = (SectionFlags.CNT_CODE | SectionFlags.LNK_COMDAT | SectionFlags.MEM_EXECUTE | SectionFlags.MEM_READ | SectionFlags.ALIGN_16BYTES) sect.RawData = self.cp.Code for patchin in self.cp.CodePatchins: # How do I tell what type it is? addr = patchin[1] if patchin[2] == DIRECT: patchinType = RelocationTypes.I386_DIR32 elif patchin[2] == RELATIVE: patchinType = RelocationTypes.I386_REL32 else: raise RuntimeError("Invalid patchin type") try: loc = self.coff.Symbols.GetLocation(patchin[0]) r = coffRelocationEntry(addr, loc, typ=patchinType) except coffError: r = coffRelocationEntry(addr, 0x0, typ=patchinType) sect.RelocationData.append(r) sym = self.coff.Symbols.GetSymbol('.text\x00\x00\x00') sym.RebuildAuxiliaries(len(sect.RawData), len(self.cp.CodePatchins), 0, crc32(sect.RawData), 0, 0) # attempt to add line numbers for sym in self.cp.CodeSymbols: symLoc = self.coff.Symbols.GetLocation(sym[0]) sect.LineNumberData.append(coffLineNumberEntry(symLoc, 0x0)) return sect
# Copyright 2004-2010 Grant T. Olson. # See license.txt for terms. from pyasm.coff import coffFile, coffSection, coffRelocationEntry, coffSymbolEntry from pyasm.coffConst import * import time,os,sys """Creates a simple .objfile that should be good enough to link as a hello world program""" c = coffFile() c.MachineType = coffFile.I386MAGIC s1 = coffSection() s1.Name = ".drectve" s1.Flags = (SectionFlags.LNK_REMOVE | SectionFlags.LNK_INFO | SectionFlags.ALIGN_1BYTES) s1.RawData = '-defaultlib:LIBCMT -defaultlib:OLDNAMES ' c.Sections.append(s1) s2 = coffSection() s2.Name = ".text\x00\x00\x00" s2.Flags = (SectionFlags.CNT_CODE | SectionFlags.LNK_COMDAT | SectionFlags.MEM_EXECUTE | SectionFlags.MEM_READ | SectionFlags.ALIGN_16BYTES) s2.RawData = "\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x83\xC4\x04\x33\xC0\xC3"
# Copyright 2004-2010 Grant T. Olson. # See license.txt for terms. from pyasm.coff import coffFile, coffSection, coffRelocationEntry, coffSymbolEntry from pyasm.coffConst import * import time, os, sys """Creates a simple .objfile that should be good enough to link as a hello world program""" c = coffFile() c.MachineType = coffFile.I386MAGIC s1 = coffSection() s1.Name = ".drectve" s1.Flags = SectionFlags.LNK_REMOVE | SectionFlags.LNK_INFO | SectionFlags.ALIGN_1BYTES s1.RawData = "-defaultlib:LIBCMT -defaultlib:OLDNAMES " c.Sections.append(s1) s2 = coffSection() s2.Name = ".text\x00\x00\x00" s2.Flags = ( SectionFlags.CNT_CODE | SectionFlags.LNK_COMDAT | SectionFlags.MEM_EXECUTE | SectionFlags.MEM_READ | SectionFlags.ALIGN_16BYTES ) s2.RawData = "\x68\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x83\xC4\x04\x33\xC0\xC3"