假设我想在每次调用时跳过函数func的第3行
int func() {
int a = 10, b =20;
a = 25;
b = 30;
return a+b
}
Run Code Online (Sandbox Code Playgroud)
所以每次它应该返回40(即不执行第3行a = 25)在windbg中是否有类似的命令,如gdb中的jmp?
再一个非常晚的答案,但如果搞乱程序集是不可取的,
设置一个条件断点来跳过执行一行
在下面的示例中,401034是您不想执行的行,
因此在该行上设置条件断点以跳过它
bp 401034 "r eip = @$eip + size of current instruction";gc"
在这种情况下gc = go,7从条件休息
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:\>
Run Code Online (Sandbox Code Playgroud)
如果您熟悉汇编,则可以使用 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