예제 #1
0
파일: cli.py 프로젝트: vijfhoek/debugger
def context_display(pkt_T=None):
	global adapter
	global context_last

	tid = adapter.thread_selected()
	print('thread 0x%X:' % tid)

	def r(reg, fmt='%016X'):
		return (BROWN+reg+NORMAL+'='+fmt) % adapter.reg_read(reg.strip())
	def e(reg, fmt='%08X'):
		return (BROWN+reg+NORMAL+'='+fmt) % adapter.reg_read(reg.strip())

	arch = adapter.target_arch()
	if arch == 'x86_64':
		print(r('rax'), r('rbx'), r('rcx'), r('rdx'))
		print(r('rsi'), r('rdi'), r('rbp'), r('rsp'))
		print(r(' r8'), r(' r9'), r('r10'), r('r11'))
		print(r('r12'), r('r13'), r('r14'), r('r15'))
		print(r('rip'), end='')

		if 'rflags' in adapter.reg_list():
			print(r('rflags'))
		else:
			print(r('eflags'))
	elif arch == 'x86':
		print(e('eax'), e('ebx'), e('ecx'), e('edx'))
		print(e('esi'), e('edi'), e('ebp'), e('esp'))
		print(e('eip'), e('eflags'))
	elif arch == 'aarch64':
		print(r(' x0'), r(' x1'), r(' x2'), r(' x3'))
		print(r(' x4'), r(' x5'), r(' x6'), r(' x7'))
		print(r(' x8'), r(' x9'), r('x10'), r('x11'))
		print(r('x12'), r('x13'), r('x14'), r('x15'))
		print(r('x16'), r('x17'), r('x18'), r('x19'))
		print(r('x20'), r('x21'), r('x22'), r('x23'))
		print(r('x24'), r('x25'), r('x26'), r('x27'))
		print(r('x28'), r('x29'), r('x30'), r(' sp'))
		print(r('pc'), e('cpsr'))
	elif arch == 'arm':
		cpsr = adapter.reg_read('cpsr')
		print(e(' r0'), e(' r1'), e(' r2'), e(' r3'))
		print(e(' r4'), e(' r5'), e(' r6'), e(' r7'))
		print(e(' r8'), e(' r9'), e('r10'), e('r11'))
		print(e('r12'), e(' sp'), e(' lr'))
		print(e(' pc'), e(' cpsr'), cpsr_tostr(cpsr))

	pc_name = {'aarch64':'pc', 'arm':'pc', 'x86_64':'rip', 'x86':'eip'}[arch]
	pc_fmt = {'aarch64':'%016X', 'arm':'%08X', 'x86_64':'%016X', 'x86':'%08X'}[arch]
	pc = adapter.reg_read(pc_name)

	try:
		data = adapter.mem_read(pc, 16)
		if data:
			(asmstr, asmlen) = utils.disasm1(data, pc, get_arch_dis())
			print(('%s'+pc_fmt+'%s: %s\t%s') % \
				(GREEN, pc, NORMAL, hexlify(data[0:asmlen]).decode('utf-8'), asmstr))
	except DebugAdapter.GeneralError as e:
		print('%s%016X%s: couldn\'t read mem' % \
			(GREEN, pc, NORMAL))
예제 #2
0
def context_display(pkt_T=None):
    global adapter
    global context_last

    tid = adapter.thread_selected()
    print('thread 0x%X:' % tid)

    rax = adapter.reg_read('rax')
    rbx = adapter.reg_read('rbx')
    rcx = adapter.reg_read('rcx')
    rdx = adapter.reg_read('rdx')
    rsi = adapter.reg_read('rsi')
    rdi = adapter.reg_read('rdi')
    rip = adapter.reg_read('rip')
    rsp = adapter.reg_read('rsp')
    rbp = adapter.reg_read('rbp')
    r8 = adapter.reg_read('r8')
    r9 = adapter.reg_read('r9')
    r10 = adapter.reg_read('r10')
    r11 = adapter.reg_read('r11')
    r12 = adapter.reg_read('r12')
    r13 = adapter.reg_read('r13')
    r14 = adapter.reg_read('r14')
    r15 = adapter.reg_read('r15')

    print("%srax%s=%016X %srbx%s=%016X %srcx%s=%016X" % \
     (BROWN, NORMAL, rax, BROWN, NORMAL, rbx, BROWN, NORMAL, rcx))
    print("%srdx%s=%016X %srsi%s=%016X %srdi%s=%016X" %
          (BROWN, NORMAL, rdx, BROWN, NORMAL, rsi, BROWN, NORMAL, rdi))
    print("%srip%s=%016X %srsp%s=%016X %srbp%s=%016X" % \
     (BROWN, NORMAL, rip, BROWN, NORMAL, rsp, BROWN, NORMAL, rbp))
    print(" %sr8%s=%016X  %sr9%s=%016X %sr10%s=%016X" % \
     (BROWN, NORMAL, r8, BROWN, NORMAL, r9, BROWN, NORMAL, r10))
    print("%sr11%s=%016X %sr12%s=%016X %sr13%s=%016X" % \
     (BROWN, NORMAL, r11, BROWN, NORMAL, r12, BROWN, NORMAL, r13))
    print("%sr14%s=%016X %sr15%s=%016X" % \
     (BROWN, NORMAL, r14, BROWN, NORMAL, r15))

    try:
        data = adapter.mem_read(rip, 16)
        if data:
            (asmstr, asmlen) = utils.disasm1(data, rip)
            print('%s%016X%s: %s\t%s' % \
             (GREEN, rip, NORMAL, hexlify(data[0:asmlen]).decode('utf-8'), asmstr))
    except DebugAdapter.GeneralError as e:
        print('%s%016X%s: couldn\'t read mem' % \
         (GREEN, rip, NORMAL))
예제 #3
0
        adapter.breakpoint_set(entry)

        # proceed to breakpoint
        print('going')
        (reason, extra) = go_initial(adapter, testbin)
        assert reason == DebugAdapter.STOP_REASON.BREAKPOINT

        assert adapter.reg_read(xip) == entry
        adapter.breakpoint_clear(entry)

        # single step until it wasn't over a call
        while 1:
            addr = adapter.reg_read(xip)
            data = adapter.mem_read(addr, 15)
            assert len(data) == 15
            (asmstr, asmlen) = utils.disasm1(data, 0)
            print('%s: 0x%X %s' % (xip, addr, asmstr))

            (reason, info) = adapter.step_into()
            expect_single_step(reason)
            if asmstr.startswith('call'): continue
            if asmstr.startswith('jmp'): continue
            break

        addr2 = adapter.reg_read(xip)
        print('%s: 0x%X' % (xip, addr2))
        assert addr + asmlen == addr2

        print('registers')
        for (ridx, rname) in enumerate(adapter.reg_list()):
            width = adapter.reg_bits(rname)
예제 #4
0
파일: test.py 프로젝트: joshwatson/debugger
			adapter.breakpoint_clear(entry)
			print('setting breakpoint at 0x%X' % entry)
			adapter.breakpoint_set(entry)

			# proceed to breakpoint
			print('going')
			(reason, info) = adapter.go()
			assert reason == DebugAdapter.STOP_REASON.SIGNAL_TRAP
			rip = adapter.reg_read('rip')
			print('rip: 0x%X' % rip)
			assert rip == entry

			# single step
			data = adapter.mem_read(rip, 15)
			assert len(data) == 15
			(asmstr, asmlen) = utils.disasm1(data, 0)
			adapter.breakpoint_clear(entry)
			(reason, info) = adapter.step_into()
			assert reason == DebugAdapter.STOP_REASON.SIGNAL_TRAP
			rip2 = adapter.reg_read('rip')
			print('rip2: 0x%X' % rip2)
			assert rip + asmlen == rip2

			print('registers')
			for (ridx,rname) in enumerate(adapter.reg_list()):
				width = adapter.reg_bits(rname)
				#print('%d: %s (%d bits)' % (ridx, rname, width))
			assert adapter.reg_bits('rax') == 64
			assert adapter.reg_bits('rbx') == 64
			assert_general_error(lambda: adapter.reg_bits('rzx'))