Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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)
Пример #4
0
    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)