def __relocateblock(self, block, sourceaddress, destinationaddress): blocklength = len(block) result = [] sourceoffset = destoffset = 0 currentaddress = destinationaddress for sourceinstruction in ia32.disassemble(block): sourcelength = len(''.join(sourceinstruction)) destinstruction = sourceinstruction if ia32.isRelativeBranch(sourceinstruction) or ia32.isRelativeCall( sourceinstruction): branchoffset = ia32.getRelativeAddress( currentaddress, sourceinstruction) - currentaddress targetoffset = sourceoffset + branchoffset if (targetoffset < 0) or (targetoffset >= blocklength): operand = sourceaddress + targetoffset destinstruction = ia32.setRelativeAddress( currentaddress, sourceinstruction, operand) destinstruction = ia32.promoteBranch(destinstruction, 4) pass destinstruction = ''.join(destinstruction) result.append(destinstruction) destoffset += len(destinstruction) return ''.join(result)
def __relocateblock(self, block, sourceaddress, destinationaddress): ''' Will relocate all the instructions in a block. Will promote branch instructions that target an address outside the block ''' result = [] sourceoffset, destoffset = 0, 0 for n in ia32.disassemble(block): instructionlength = len(''.join(n)) if ia32.isRelativeBranch(n) or ia32.isRelativeCall(n): currentaddress = destinationaddress + len(''.join(result)) branchoffset = ia32.getRelativeAddress(currentaddress, n) - currentaddress o = sourceoffset + instructionlength + branchoffset if (o < 0) or (o >= len(block)): operand = sourceaddress + o n = self.__updatebranch(currentaddress, n, operand) pass n = ''.join(n) result.append(n) sourceoffset += instructionlength destoffset += len(n) return ''.join(result)
def __relocateblock(self, block, sourceaddress, destinationaddress): ''' Will relocate all the instructions in a block. Will promote branch instructions that target an address outside the block ''' result = [] sourceoffset,destoffset = 0,0 for n in ia32.disassemble(block): instructionlength = len(''.join(n)) if ia32.isRelativeBranch(n) or ia32.isRelativeCall(n): currentaddress = destinationaddress + len(''.join(result)) branchoffset = ia32.getRelativeAddress(currentaddress, n) - currentaddress o = sourceoffset + instructionlength + branchoffset if (o<0) or (o>=len(block)): operand = sourceaddress + o n = self.__updatebranch(currentaddress, n, operand) pass n = ''.join(n) result.append(n) sourceoffset += instructionlength destoffset += len(n) return ''.join(result)
def __calculateblocksize(self, block): '''return the maximum size required for a block''' result = 0 for n in ia32.disassemble(block): if ia32.isRelativeBranch(n) or ia32.isRelativeCall(n): n = ia32.promoteBranch(n, 4) instructionlength = len(''.join(n)) result += instructionlength return result
def __relocateblock(self, block, sourceaddress, destinationaddress): blocklength = len(block) result = [] sourceoffset = destoffset = 0 currentaddress = destinationaddress for sourceinstruction in ia32.disassemble(block): sourcelength = len(''.join(sourceinstruction)) destinstruction = sourceinstruction if ia32.isRelativeBranch(sourceinstruction) or ia32.isRelativeCall(sourceinstruction): branchoffset = ia32.getRelativeAddress(currentaddress, sourceinstruction) - currentaddress targetoffset = sourceoffset + branchoffset if (targetoffset < 0) or (targetoffset >= blocklength): operand = sourceaddress + targetoffset destinstruction = ia32.setRelativeAddress(currentaddress, sourceinstruction, operand) destinstruction = ia32.promoteBranch(destinstruction,4) pass destinstruction = ''.join(destinstruction) result.append(destinstruction) destoffset += len(destinstruction) return ''.join(result)