コード例 #1
0
ファイル: Constants.py プロジェクト: uttaravadina/pwndra
    def getStackValue(self, func, call, param):

        inst = self.currentProgram.getListing().getInstructionAt(call)
        if inst is None:
            return None

        init = call
        curr = inst.getPrevious()

        while curr is not None:

            if self.monitor.isCancelled():
                return doCancel()

            if curr.getFlowType().toString() != 'FALL_THROUGH':
                break

            init = curr.getAddress()
            curr = curr.getPrevious()

        emulatorHelper = EmulatorHelper(self.currentProgram)
        emulatorHelper.setBreakpoint(call)
        emulatorHelper.writeRegister(emulatorHelper.getPCRegister(), int(init.toString(), 16))

        stackOffset = (call.getAddressSpace().getMaxAddress().getOffset() >> 1) -  0x7fff;
        emulatorHelper.writeRegister(emulatorHelper.getStackPointerRegister(), stackOffset)

        value = None
        last  = self.currentProgram.getListing().getCodeUnitAt(init).getPrevious().getAddress()
        while not self.monitor.isCancelled():

            emulatorHelper.step(self.monitor)

            if self.monitor.isCancelled():
                return doCancel()

            address = emulatorHelper.getExecutionAddress()
            current = self.currentProgram.getListing().getCodeUnitAt(address)

            if address.equals(last):

                # skip bad instructions
                goto = current.getMaxAddress().next()
                emulatorHelper.writeRegister(emulatorHelper.getPCRegister(), int(goto.toString(), 16))
                continue

            else:
                last = address

            if address.equals(call):

                start = param.getStackOffset() - param.getLength()
                value = emulatorHelper.readStackValue(start, param.getLength(), True)

                break

        emulatorHelper.clearBreakpoint(call)
        emulatorHelper.dispose()

        return value
コード例 #2
0
def getStackValue(start, call, param):

    inst = getInstructionAt(start)
    if inst is None:
        return None

    emulatorHelper = EmulatorHelper(currentProgram)
    emulatorHelper.setBreakpoint(call)
    emulatorHelper.writeRegister(emulatorHelper.getPCRegister(),
                                 int(start.toString(), 16))

    stackOffset = (
        call.getAddressSpace().getMaxAddress().getOffset() >> 1) - 0x7fff
    emulatorHelper.writeRegister(emulatorHelper.getStackPointerRegister(),
                                 stackOffset)
    listing = currentProgram.getListing()

    value = None
    last = listing.getCodeUnitAt(start).getPrevious().getAddress()
    while not monitor.isCancelled():

        emulatorHelper.step(monitor)

        if monitor.isCancelled():
            return doCancel()

        address = emulatorHelper.getExecutionAddress()
        current = currentProgram.getListing().getCodeUnitAt(address)

        if address.equals(last):

            goto = current.getMaxAddress().next()
            emulatorHelper.writeRegister(emulatorHelper.getPCRegister(),
                                         int(goto.toString(), 16))
            continue

        else:

            last = address

        if address.equals(call):

            width = currentProgram.getLanguage().getLanguageDescription(
            ).getSize() >> 3
            start = param.getStackOffset() - width
            value = emulatorHelper.readStackValue(start, width, True)

            break

    emulatorHelper.clearBreakpoint(call)
    emulatorHelper.dispose()

    return value