def extract(self): shSize = self.eh.get('sh_size') shNum = self.eh.get('sh_num') shOff = self.eh.get('sh_offset') strTab = self.retrieveStringTable() result = [] for idx in range(1, shNum): if idx == self.eh.get('shstrndx'): continue shStart = shOff + shSize * idx sh = Sh() sh.retrieve(self.byteList[shStart:shStart+shSize]) name = retrieveStr(strTab, sh.get('name_index')) body = self.byteList[sh.get('offset'):sh.get('offset')+sh.get('size')] if name == '.symtab' or name == '.strtab': continue result.append((name, body, sh)) return result
def getSectionList(self): nullSh = Sh() nullSh.retrieve([0x00 for i in range(56)]) nullSection = Section([], '', nullSh) strSection = self.makeShStrSection() return (nullSection, self.sectionList, strSection)
def retrieveStringTable(self): shSize = self.eh.get('sh_size') shNum = self.eh.get('sh_num') shOff = self.eh.get('sh_offset') # get string table section header start position shStrStart = shOff + shSize * self.eh.get('shstrndx') strSh = Sh() strSh.retrieve(self.byteList[shStrStart:shStrStart+shSize]) strOff = strSh.get('offset') strSize = strSh.get('size') strTab = ''.join(map(chr, self.byteList[strOff:strOff+strSize])) return strTab
f = open('test.out') byteList = map(lambda x: int(ord(x)), f.read()) # get ELF header eh = Eh() eh.retrieve(byteList[0:64]) shSize = eh.get('sh_size') shNum = eh.get('sh_num') shOff = eh.get('sh_offset') # get sh string table shStrStart = shOff + shSize * eh.get('shstrndx') strSh = Sh() strSh.retrieve(byteList[shStrStart:shStrStart+shSize]) strOff = strSh.get('offset') strSize= strSh.get('size') strTab = ''.join(map(chr, byteList[strOff:strOff+strSize])) # get sections secAggr = SectionAggregator() for idx in range(1, shNum): if idx == eh.get('shstrndx'): continue shStart = shOff + shSize * idx sh = Sh()
import sys