import sys
def makeBasePh(self, pType, pFlag, align = 0): ph = Ph() ph.set('segment_type', pType) ph.set('permission_flag', pFlag) ph.set('offset', 0) # dummy ph.set('virtual_addr', 0) # dummy ph.set('physical_addr', 0) # dummy ph.set('filesize', 0) # dummy ph.set('memory_size', 0) # dummy ph.set('align', align) # dummy return ph
def makePh(self, sectionManager): phList = [] for key in orderList: seg = self.getSegment(key) if seg == None: continue offset = self.getOffset(key, seg, sectionManager) ph = Ph() ph.set("segment_type", seg.getType()) ph.set("permission_flag", seg.getFlag()) ph.set("offset", offset) ph.set("virtual_addr", self.getAddr(key, offset)) ph.set("physical_addr", self.getAddr(key, offset)) ph.set("filesize", self.getSize(key, seg, sectionManager)) ph.set("memory_size", self.getSize(key, seg, sectionManager)) ph.set("align", seg.getAlign()) phList.append(ph) return phList
def setPhSegment(self, phList, phNum): ph = Ph() ph.set('segment_type', pType['PHDR']) ph.set('permission_flag', 6) ph.set('offset', 0x40) ph.set('virtual_addr', self.orgAddr + 0x40) ph.set('physical_addr', self.orgAddr + 0x40) ph.set('filesize', 56*phNum) ph.set('memory_size', 56*phNum) ph.set('align', 8) bodyList = [] for p in phList: bodyList += p.output() bodyList += ph.output() return Segment(ph, bodyList)
def makeSegment(self, sctList): # separate sections by flag value and sort section order segBaseTbl = {} for sct in sctList: name = sct.getName() try: segBaseTbl[sct.getSh().get('flag')].append((getOrder(name), sct)) except: segBaseTbl[sct.getSh().get('flag')] = [] segBaseTbl[sct.getSh().get('flag')].append((getOrder(name), sct)) segTbl = {} for (flag, segList) in segBaseTbl.items(): segTbl[flag] = sorted(segList, key=lambda x: x[0]) # set base position offset = 64 + 56 + 56 * len(segTbl) # EH + PHDR + PHs offset addr = self.orgAddr + offset phList = [] for (flag, contentList) in segTbl.items(): bodyList = [] sctOff = offset sctAddr = addr for (order, sct) in contentList: sct.getSh().set('address', sctAddr) sct.getSh().set('offset', sctOff) bodyList += sct.getBodyList() align = sct.getSh().get('address_align') if sct.getName() == '.text': self.startAddr = addr # padding 0x00 if len(sct.getBodyList()) % align > 0: bodyList += [0x0 for x in range(align - len(sct.getBodyList()) % align)] sctOff = offset + len(bodyList) sctAddr = addr + len(bodyList) ph = Ph() #ph.set('segment_type', getPhFlag(flag)) ph.set('segment_type', 1) ph.set('permission_flag', flag) ph.set('offset', offset) ph.set('virtual_addr', addr) ph.set('physical_addr', addr) ph.set('filesize', len(bodyList)) ph.set('memory_size', len(bodyList)) ph.set('align', self.loadAlign) self.segmentList.append(Segment(ph, bodyList)) phList.append(ph) offset += len(bodyList) addr += offset # make PHDR self.phSegment = self.setPhSegment([s.getPh() for s in self.segmentList], len(phList)) return sctList
def makePh(self, sectionManager): phList = [] for key in orderList: seg = self.getSegment(key) if seg == None: continue offset = self.getOffset(key, seg, sectionManager) ph = Ph() ph.set('segment_type', seg.getType()) ph.set('permission_flag', seg.getFlag()) ph.set('offset', offset) ph.set('virtual_addr', self.getAddr(key, offset)) ph.set('physical_addr', self.getAddr(key, offset)) ph.set('filesize', self.getSize(key, seg, sectionManager)) ph.set('memory_size', self.getSize(key, seg, sectionManager)) ph.set('align', seg.getAlign()) phList.append(ph) return phList