Beispiel #1
0
def main():
    # parse arch from cmdline
    arch = i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch = archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv) < 2:
        print "%s [<%s>] <serial interface> [<elf file>]" % (
            sys.argv[0], '|'.join(archmap.keys()))
        sys.exit(1)

    elffile = sys.argv[2] if len(sys.argv) > 2 else None

    rsp = arch(sys.argv[1], elffile, verbose=False)

    if elffile:
        rsp.call()
    else:
        print hexdump(rsp.dump(2048, 0), 0)
        rsp.dump_regs()
        print rsp.get_thread_info()
        rsp.send('c')
Beispiel #2
0
def main():
    # parse arch from cmdline
    arch=i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch=archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv)<2:
        print "%s [<%s>] <serial interface> [<elf file>]" % (sys.argv[0],
                                                             '|'.join(archmap.keys()))
        sys.exit(1)

    elffile=sys.argv[2] if len(sys.argv)>2 else None

    rsp = arch(sys.argv[1], elffile, verbose=True)

    if elffile:
        rsp.call()
    else:
        print hexdump(rsp.dump(2048, 0),0)
        rsp.dump_regs()
        print rsp.get_thread_info()
        rsp.send('c')
Beispiel #3
0
    def dump_cb(self):
        """ rsp_dump callback, hit if rsp_dump is called. Outputs to
            stdout the source line, and a hexdump of the memory
            pointed by $r0 with a size of $r1 bytes. Then it resumes
            running.
        """
        src_line = self.get_src_line(int(self.regs['lr'],16) - 3)
        if src_line:
            print "%s:%s %s" % (src_line['file'], src_line['lineno'], src_line['line'])

        res_size = int(self.regs['r1'],16)
        if res_size < 1024: # for sanity
            ptr = int(self.regs['r0'],16)
            res = unhex(self.fetch('m%x,%x' % (ptr, res_size)))
            print hexdump(res, ptr)

        self.step_over_br()
Beispiel #4
0
def main():
    # parse arch from cmdline
    arch = i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch = archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv) < 2:
        print "%s [<%s>] <serial interface> [<elf file>]" % (
            sys.argv[0], '|'.join(archmap.keys()))
        sys.exit(1)

    elffile = sys.argv[2] if len(sys.argv) > 2 else None

    rsp = arch(sys.argv[1], elffile, verbose=False)

    if elffile:
        try:
            rsp.call()
        except KeyboardInterrupt:
            import traceback
            traceback.print_exc()

            res = None
            while not res:
                res = rsp.port.read()
            discards = []
            retries = 20
            while res != '+' and retries > 0:
                discards.append(res)
                retries -= 1
                res = rsp.port.read()
            if len(discards) > 0 and rsp.verbose:
                print 'send discards', discards

            rsp.port.close(rsp)
            sys.exit(1)
    else:
        print hexdump(rsp.dump(2048, 0), 0)
        rsp.dump_regs()
        print rsp.get_thread_info()
        rsp.send('c')
    rsp.port.close(rsp)
Beispiel #5
0
def main():
    # parse arch from cmdline
    arch=i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch=archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv)<2:
        print "%s [<%s>] <serial interface> [<elf file>]" % (sys.argv[0],
                                                             '|'.join(archmap.keys()))
        sys.exit(1)

    elffile=sys.argv[2] if len(sys.argv)>2 else None

    rsp = arch(sys.argv[1], elffile, verbose=False)

    if elffile:
        try:
            rsp.call()
        except KeyboardInterrupt:
            import traceback
            traceback.print_exc()

            res = None
            while not res:
                res = rsp.port.read()
            discards = []
            retries = 20
            while res!='+' and retries>0:
                discards.append(res)
                retries-=1
                res = rsp.port.read()
            if len(discards)>0 and rsp.verbose: print 'send discards', discards

            rsp.port.close(rsp)
            sys.exit(1)
    else:
        print hexdump(rsp.dump(2048, 0),0)
        rsp.dump_regs()
        print rsp.get_thread_info()
        rsp.send('c')
    rsp.port.close(rsp)
Beispiel #6
0
    def dump_cb(self):
        """ rsp_dump callback, hit if rsp_dump is called. Outputs to
            stdout the source line, and a hexdump of the memory
            pointed by $r0 with a size of $r1 bytes. Then it resumes
            running.
        """
        src_line = self.get_src_line(int(self.regs['lr'], 16) - 3)
        if src_line:
            print "%s:%s %s" % (src_line['file'], src_line['lineno'],
                                src_line['line'])

        res_size = int(self.regs['r1'], 16)
        if res_size <= 1024:  # for sanity
            ptr = int(self.regs['r0'], 16)
            res = unhex(self.fetch('m%x,%x' % (ptr, res_size)))
            print hexdump(res, ptr)

        self.step_over_br()
Beispiel #7
0
Datei: rsp.py Projekt: stef/pyrsp
def main():
    # parse arch from cmdline
    arch = i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch = archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv) < 2:
        print("%s [<%s>] <serial interface> [<elf file>]" %
              (sys.argv[0], '|'.join(archmap.keys())))
        sys.exit(1)

    elffile = sys.argv[2] if len(sys.argv) > 2 else None

    rsp = arch(sys.argv[1], elffile, verbose=False)

    if elffile:
        try:
            rsp.call()
        except KeyboardInterrupt:
            import traceback
            traceback.print_exc()

            rsp.read_ack(20)

            rsp.port.close(rsp)
            sys.exit(1)
    else:
        print(hexdump(rsp.dump(2048, 0), 0))
        rsp.dump_regs()
        print(rsp.get_thread_info())
        rsp.send(b'c')
    rsp.port.close(rsp)
Beispiel #8
0
Datei: rsp.py Projekt: stef/pyrsp
def main():
    # parse arch from cmdline
    arch=i386
    for i, arg in enumerate(sys.argv):
        if arg in archmap:
            arch=archmap[arg]
            del sys.argv[i]
            break
    # argv[1] should be the file to the debugger device, e.g: /dev/ttyACM0
    # argv[2] can be the elf file
    if len(sys.argv)<2:
        print("%s [<%s>] <serial interface> [<elf file>]" % (sys.argv[0],
                                                             '|'.join(archmap.keys())))
        sys.exit(1)

    elffile=sys.argv[2] if len(sys.argv)>2 else None

    rsp = arch(sys.argv[1], elffile, verbose=False)

    if elffile:
        try:
            rsp.call()
        except KeyboardInterrupt:
            import traceback
            traceback.print_exc()

            rsp.read_ack(20)

            rsp.port.close(rsp)
            sys.exit(1)
    else:
        print(hexdump(rsp.dump(2048, 0),0))
        rsp.dump_regs()
        print(rsp.get_thread_info())
        rsp.send(b'c')
    rsp.port.close(rsp)