Example #1
0
def test_vexpr_retval():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x40101b, "marker = vex('poi(ebp-0x4)')")
    result = dbg.run('hello.exe', locs)
    assert result is True
    assert locs['marker'] == 14
Example #2
0
def test_vexpr_alias():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x40101b, "marker = ?('poi(ebp-0x4)')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == 14
Example #3
0
def test_rundll_dll_intercept_CURRENTLY_FAILS():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query('dll.Add+0xd', "marker = r('eax')")
    result = dbg.run(r'rundll32.exe dll.dll,Add dummytext', locs)
    assert result is True
    assert locs['marker'] == 0
Example #4
0
def test_getsym_invalid():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401000, "marker = getsym('eip')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == '(unknown)'
Example #5
0
def test_getsym_alias_ln():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query('kernel32.GetCommandLineA', "marker = ln('eip')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == 'kernel32.GetCommandLineA'
Example #6
0
def test_getsym_valid():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query('kernel32.GetCommandLineA', "marker = getsym('eip')")
    result = dbg.run('hello.exe', locs)
    assert result is True
    assert locs['marker'] == 'kernel32.GetCommandLineA'
Example #7
0
def test_disas():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401000, "marker = disas(None, 1, False)")
    result = dbg.run('hello.exe', locs)
    assert result is True
    assert locs['marker'][0] == 'push ebp'
Example #8
0
def test_disas_alias_u():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401000, "marker = u(None, 1)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'][0] == 'push ebp'
Example #9
0
def test_initcode():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.setInitCode('marker = 12345')
    result = dbg.run(hello_exe_path, locs)
    assert locs['marker'] is not None
    assert locs['marker'] == 12345
Example #10
0
def test_dw():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401010, "marker = dw('poi(esp)', 1)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    # DWORD of beginning of "Hello, world!"
    assert locs['marker'][0] == struct.unpack('H', 'He')[0]
Example #11
0
def test_gu():
    dbg = Qdb()
    locs = {'location': None}
    dbg.add_query(0x401022, "print(hex(r('eip'))); gu(); location = r('eip'); print(hex(location))")  # At _printf
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['location']
    assert locs['location'] == 0x401015  # Right after call _printf
Example #12
0
def test_cond_false():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x40101b, "marker = vex('poi(ebp-0x4)')",
                  "0 || esp && eax!=14")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] is None
Example #13
0
def test_cond_true():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x40101b, "marker = vex('poi(ebp-0x4)')",
                  "0 or (esp and eax==14)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == 14
Example #14
0
def test_get_pc():
    dbg = Qdb()
    locs = {'marker': None}
    pc = 0x401000
    dbg.add_query(pc, 'marker = get_pc()')
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == pc
Example #15
0
def test_bp():
    """FIXME: This test will break if da breaks, which is confusing."""
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401000, "bp(0x401010, 'marker = da(\\\'poi(esp)\\\', 5)')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == 'Hello'
Example #16
0
def test_python_ctypes_dll_intercept():
    cmdline = (sys.executable +
               ' -c "import ctypes; ctypes.cdll.dll.Add(40, 2)"')
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query('dll.Add+0xd', "marker = r('eax')")
    result = dbg.run(cmdline, locs)
    assert result is True
    assert locs['marker'] == 42
Example #17
0
def test_stepo():
    dbg = Qdb()
    locs = {'location': None}
    dbg.add_query(0x401010, "stepo(); location = r('eip')")  # call _printf
    result = dbg.run(hello_exe_path, locs)

    assert result is True
    assert locs['location']
    assert locs['location'] == 0x401015  # Right after call _printf
Example #18
0
def test_da():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401010,
                  "marker = da('poi(esp)'); print('Marker = ' + str(marker))")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    # DWORD of beginning of "Hello, world!"
    assert locs['marker'] == 'Hello, world!\n\0'
Example #19
0
def test_retset():
    cmdline = (sys.executable +
               ' -c "import ctypes; ctypes.cdll.dll.Add(1, 1)"')
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query('dll.Add', "marker = retset('eax+1', 8)")
    result = dbg.run(cmdline, locs)
    assert result is True
    assert locs['marker'] == 3
Example #20
0
def test_memcpy():
    """FIXME: This test will break if dd breaks, which is confusing."""
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(
        0x401010,
        "memcpy('poi(esp)', 'poi(esp)+4', 4); " + "marker = dd('poi(esp)', 1)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'][0] == struct.unpack('@I', 'Hello, world!'[4:8])[0]
Example #21
0
def test_callback_gets_context_with_pc_and_locals_as_arg(*args, **kwargs):
    dbg = Qdb()

    def callback(p, **kwargs):
        p['marker'] = True

    locs = {'marker': False}
    dbg.add_query(0x401010, callback)
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] is True
Example #22
0
def test_get_pcs():
    dbg = Qdb()
    locs = {'pcs': None, 'tid': None}
    pc = 0x401000
    dbg.add_query(pc, 'pcs = get_pcs(); tid = q._trace.getCurrentThread()')
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    # hello.exe is single-threaded
    for k, v in locs['pcs'].iteritems():
        assert k == locs['tid']
        assert v == pc
Example #23
0
def test_ea_and_da():
    """FIXME: This test depends on both ea and da, which makes it break
    when either piece breaks.
    """
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401010,
                  "ea('poi(esp)', 'Bye, world'); marker = da('poi(esp)')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == 'Bye, worldld!\n\0'
Example #24
0
def test_get_push_arg():
    cmdline = (sys.executable +
               ' -c "import ctypes; ctypes.cdll.dll.Add(12, 34)"')
    dbg = Qdb()
    locs = {'arg_12': None, 'arg_34': None}
    dbg.add_query('dll.Add',
                  "arg_12 = get_push_arg(0); arg_34 = get_push_arg(1)")
    result = dbg.run(cmdline, locs)
    assert result is True
    assert locs['arg_12'] == 12
    assert locs['arg_34'] == 34
Example #25
0
def test_eu_and_du():
    """FIXME: This test depends on both eu and du, which makes it break
    when either piece breaks.
    """
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401010,
                  "eu('poi(esp)', u'Bye, world'); marker = du('poi(esp)', 3)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == u'Bye'
Example #26
0
def test_rapid_fire_WILL_TAKE_A_LONG_TIME():
    runs_expected = 1
    # runs_expected = 1400
    runs_counted = 0

    locs = {'marker': runs_counted}
    dbg = Qdb()
    dbg.add_query(0x0401262, "marker += 1; kill()")
    for i in xrange(runs_expected):
        result = dbg.run(hello_exe_path, locs)
        assert result is True
    assert locs['marker'] == runs_expected
Example #27
0
def test_writemem():
    """FIXME: This test will break if da breaks, which is confusing."""
    dbg = Qdb()
    locs = {'marker': None}
    s = "Goodbye, world!"
    print("writemem('poi(esp)', '" + s + "'); marker = da('poi(esp)')")
    dbg.add_query(
        0x401010,
        "writemem('poi(esp)', '" + s + "\\x00'); marker = da('poi(esp)')")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'] == s + '\x00'
Example #28
0
def test_vexpr_nameerror():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401010, "marker = vex('poi(EXP)')")
    got_exception = False
    try:
        result = dbg.run(hello_exe_path, locs)
    except QdbBpException as e:
        got_exception = True
        ex_type_is_name_error = isinstance(e.exception, NameError)
    assert got_exception
    assert ex_type_is_name_error
    assert locs['marker'] is None
Example #29
0
def test_disas_alias_uf():
    dbg = Qdb()
    locs = {'marker': None}
    dbg.add_query(0x401000, "marker = uf(None)")
    result = dbg.run(hello_exe_path, locs)
    assert result is True
    assert locs['marker'][0].startswith('push ebp')
    assert locs['marker'][1].startswith('mov ebp,esp')
    assert locs['marker'][2].startswith('push ecx')
    assert locs['marker'][3].startswith('mov dword [ebp - 4],0')
    assert locs['marker'][4].startswith('push 0x0040c000')
    assert locs['marker'][5].startswith('call 0x00401022')
    assert locs['marker'][6].startswith('add esp,4')
    assert locs['marker'][7].startswith('mov dword [ebp - 4],eax')
    assert locs['marker'][8].startswith('mov eax,dword [ebp - 4]')
    assert locs['marker'][9].startswith('mov esp,ebp')
    assert locs['marker'][10].startswith('pop ebp')
    assert locs['marker'][11].startswith('ret')
Example #30
0
def test_syms():
    cmdline = 'cmd /c net helpmsg 0'
    dbg = Qdb()
    locs = {'marker1': None, 'marker2': None}
    bytevalue = 0xa5
    dbg.setInitCode("loadSyms(); eb('cmd.fDumpParse', %d)" % (bytevalue))
    dbg.add_query('cmd.Dispatch',
                  "marker1 = True; marker2 = db('cmd.fDumpParse', 1)[0]")
    dbg.run(cmdline, locs)
    assert locs['marker1'] is True
    assert locs['marker2'] == bytevalue