from struct import pack class Pe(object): def __init__(self, xbe): self.xbe = xbe self.sections = [] for name, (flags, addr, size, data) in xbe.sections.items(): W = (flags & 0x1) != 0 X = (flags & 0x4) != 0 self.sections.append((name, addr, size, data, W, X)) self.sections = sorted(self.sections, lambda a, b: cmp(a[1], b[1])) last = self.sections[-1] self.stubLoc = highest = (last[1] + last[2] + 0x1000) & 0xFFFFE000 stub = '\x68' + pack(' len(data): w('\0' * (size - len(data))) pos += size if i < len(self.sections) - 1: temp = round(pos, 0x20) - pos if temp: w('\0' * temp) pos += temp #if len(data) < size: # w('\0' * (size - len(data))) print