如何在每次击中时跳过windbg中执行的一行?

时间:2012-05-07 13:28:05

标签: windbg

假设我想在每次调用时跳过函数func的第3行

int func() {
     int a = 10, b =20;
     a = 25;
     b = 30;
     return a+b
}

所以每次它应该返回40(即不执行第3行a = 25) windbg中有类似的命令,比如gdb中的jmp吗?

3 个答案:

答案 0 :(得分:6)

又是一个非常晚的答案,但如果搞乱装配不是更好的 设置条件断点以跳过执行一行

在下面的示例中,401034是您不想执行的行 所以在该行上设置条件断点以跳过它

bp 401034 "r eip = @$eip + size of current instruction";gc"
7 在这种情况下gc = go来自conditionl break

jmptest:\>dir /b
jmptest.c

jmptest:\>type jmptest.c
#include <stdio.h>
int func()
{
    int a = 10 , b = 20;
    a = 25;
    b = 30;
    return a+b;
}
int main (void)
{
    int i , ret;
    for (i= 0; i< 10; i++)
    {
        ret = func();
        printf("we want 40 we get %d\n",ret);
    }
    return 0;
}
jmptest:\>cl /nologo /Zi jmptest.c
jmptest.c

jmptest:\>dir /b *.exe
jmptest.exe

jmptest:\>cdb -c "uf func;q" jmptest.exe | grep 401
00401020 55              push    ebp
00401021 8bec            mov     ebp,esp
00401023 83ec08          sub     esp,8
00401026 c745fc0a000000  mov     dword ptr [ebp-4],0Ah
0040102d c745f814000000  mov     dword ptr [ebp-8],14h
00401034 c745fc19000000  mov     dword ptr [ebp-4],19h
0040103b c745f81e000000  mov     dword ptr [ebp-8],1Eh
00401042 8b45fc          mov     eax,dword ptr [ebp-4]
00401045 0345f8          add     eax,dword ptr [ebp-8]
00401048 8be5            mov     esp,ebp
0040104a 5d              pop     ebp
0040104b c3              ret

jmptest:\>cdb -c "bp 401034 \"r eip = 0x40103b;gc\";g;q " jmptest.exe | grep wan
t
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40
we want 40 we get 40

jmptest:\>

答案 1 :(得分:3)

如果您熟悉程序集,可以使用 a 命令更改程序集(即将操作码转换为“a = 25;”进入所有NOP)。当我想要NOP输出或以其他方式更改指令流时,这就是我通常所做的事情。

有时人们会依赖NOP指令的字节代码为0x90并使用 e 命令编辑内存(例如“ew @eip 0x9090”)这一事实。这与使用 a 命令的结果相同。

最后,如果您不经常进行此操作并且只想手动跳过该指令,则可以使用“设置当前指令”GUI操作:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff542851(v=vs.85).aspx

答案 2 :(得分:2)

这里有一个教程解释了如何执行此操作,您可以设置偏移量以便跳过该行:http://cfc.kizzx2.com/index.php/tutorial-using-windbg-to-bypass-specific-functions-windbg-kung-fu-series/并将寄存器eip设置为此值。

此外,您可以设置断点并将命令放入断点以执行相同操作:http://japrogbits.blogspot.co.uk/2010/01/using-breakpoints-to-skip-function-in.html和另一个博客:http://www.shcherbyna.com/?p=1234并且您还可以使用.call来实现相同:http://blogs.msdn.com/b/oldnewthing/archive/2007/04/27/2292037.aspx

相关问题