繁体   English   中英

注入的DLL函数中的访问冲突异常(5)

[英]Access Violation Exception (5) in function of injected DLL

我正在使用代码注入扩展Windows组件的功能。 我覆盖了方法的说明,调用了自己的方法来完成原始方法的工作。 假设我们有:

void Target(HDC magic123)
{ ... }

以下是该方法的前几个说明:

push    rbx //
push    rbp // stores registers to recover later
...
sub     rsp, 0x260 // for all 7 pushes
...
mov     r12, [rsp+0x28] // stores a pointer to 'magic123'
...
...a lot more instructions

mov r12, [rsp+0x28] ,我立即用以下命令覆盖以下指令:

mov rcx, r12                // 1st parameter to pass to a called function goes in RCX
add rsp, 0x260              // restore the stack
push 0                      // create shadow space |EDIT: MISALIGNED STACK. WRONG.
mov rax, &DetouredFunction  // function in my injected DLL
call rax                    // call it with the HDC as parameter

我在DLL中的功能:

void DetouredFunction(uintptr_t hdcPointer)
{
uintptr_t hdcAddress = *(uintptr_t*)(hdcPointer); // convert pointer to address
HDC hdc = (HDC)hdcAddress; // create a HDC from the address


HBITMAP hBitmapWallpaper = (HBITMAP)LoadImage(NULL, L"C:\\Users\\<user>\\Desktop\\image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
SelectObject(hdc, hBitmapWallpaper);
}

一切正常,直到在注入的DLL函数中调用“ LoadImage”。 尝试读取不存在的地址0xFFFFFFFFFFFFFFFF时,抛出“访问冲突异常(5)”。

问题是什么? 如果其中有错误,请更正我上面的任何评论。 谢谢!

我的问题是未对齐堆栈。 在再次调用LoadImage之前,它没有任何明显的作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM