簡體   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