Return 地址操作不起作用
Return Address Manipulation does not work
所以我的目标是改变return地址跳过一个字节0xE8。
调用这个函数后return地址在栈顶对吧?所以弹出,加 1 并推送值应该可以完成工作。
至少乍一看使用 OllyDbg 是这样,但实际上其余的代码 - 只是打印一个字符串 - 不会工作。
call manipulate
db 0xE8
push NULL
push dummy
push msg.len
push msg
push eax
call WriteConsoleA
push NULL
call ExitProcess
manipulate:
pop eax
add eax, 1
push eax
ret
那么为什么这不起作用?有更好的方法吗?
常见的例程是在过程调用后将BP register
的值存储在堆栈中。然后将 BP
设置为 top of stack
。之后,您可以使用 BP
.
访问堆栈中的元素
nameOfProc proc
push BP
mov BP,SP
堆栈看起来像这样:
ret address |
BP register | <-- BP / SP
然后您可以使用 BP register
访问 ret 地址,如下所示:
mov eax, [BP+4]
add eax, 1
mov [BP+4], eax
也可以在程序结束后标记您想要return的地方,例如
returnHere: some code
而且你可以简单地这样做:
mov [BP+4], offset returnHere
最后要这样弹出stored BP register
mov SP, BP
pop BP
ret ;if you use some arguments for procedure - you push them to stack before call than use ret numberOfBytesOfAllArguments
nameOfProc proc
我也不明白 manipulate:
- 这不是过程,但你用 call manipulate
调用它。
您对 manipulate
的调用会破坏 eax
中的值,然后将其用作 WriteConsoleA
.
的参数
所以我的目标是改变return地址跳过一个字节0xE8。 调用这个函数后return地址在栈顶对吧?所以弹出,加 1 并推送值应该可以完成工作。 至少乍一看使用 OllyDbg 是这样,但实际上其余的代码 - 只是打印一个字符串 - 不会工作。
call manipulate
db 0xE8
push NULL
push dummy
push msg.len
push msg
push eax
call WriteConsoleA
push NULL
call ExitProcess
manipulate:
pop eax
add eax, 1
push eax
ret
那么为什么这不起作用?有更好的方法吗?
常见的例程是在过程调用后将BP register
的值存储在堆栈中。然后将 BP
设置为 top of stack
。之后,您可以使用 BP
.
nameOfProc proc
push BP
mov BP,SP
堆栈看起来像这样:
ret address |
BP register | <-- BP / SP
然后您可以使用 BP register
访问 ret 地址,如下所示:
mov eax, [BP+4]
add eax, 1
mov [BP+4], eax
也可以在程序结束后标记您想要return的地方,例如
returnHere: some code
而且你可以简单地这样做:
mov [BP+4], offset returnHere
最后要这样弹出stored BP register
mov SP, BP
pop BP
ret ;if you use some arguments for procedure - you push them to stack before call than use ret numberOfBytesOfAllArguments
nameOfProc proc
我也不明白 manipulate:
- 这不是过程,但你用 call manipulate
调用它。
您对 manipulate
的调用会破坏 eax
中的值,然后将其用作 WriteConsoleA
.