要解决这个问题,您需要了解如何通过 Windows API 加载资源。kernel32.dll 中的一些 API 是常用的,例如:
Kernel32.dll 中使用了许多 API,例如:
对于对话框/窗口,在 user32.dll 中使用了额外的 API,例如:
32 位代码中的简单 LoadString API 可能看起来像这样,其中 101 是字符串 ID。
mov DWORD PTR _stringID$[ebp], 101 ; string ID
mov DWORD PTR _pBuf$[ebp], 0
push 0
lea eax, DWORD PTR _pBuf$[ebp] ; put location to store result in eax
push eax
mov ecx, DWORD PTR _stringID$[ebp] ; string ID = 101
push ecx
mov edx, DWORD PTR _hInstance$[ebp] ; hInstance
push edx
call DWORD PTR __imp__LoadStringW@16
mov DWORD PTR _len$[ebp], eax ; eax holds length of string
在 64 位代码中可能如下所示:
mov DWORD PTR stringID$[rsp], 101 ; string ID
mov QWORD PTR pBuf$[rsp], 0
xor r9d, r9d
lea r8, QWORD PTR pBuf$[rsp] ; put location to store result in r8
mov edx, DWORD PTR stringID$[rsp] ; string ID = 101
mov rcx, QWORD PTR hInstance$[rsp] ; hInstance
call QWORD PTR __imp_LoadStringW
mov DWORD PTR len$[rsp], eax ; length of returned string in EAX
在 32 位中使用 FindResource 可能如下所示:
push 0
push 10 ; resource type ( 10 = RCDATA section)
push 100 ; 100 = resource ID
mov eax, DWORD PTR _hInstance$[ebp] ; hInstance to module containing resource in EAX
push eax
call DWORD PTR __imp__FindResourceExA@16
mov DWORD PTR _rc$[ebp], eax ; handle to the specified resource's information block returned in EAX
mov ecx, DWORD PTR _rc$[ebp] ; specify resource information block handle in ECX
push ecx
mov edx, DWORD PTR _hInstance$[ebp] ; hInstance module with resource
push edx
call DWORD PTR __imp__LoadResource@8
mov DWORD PTR _rcData$[ebp], eax ; hGlobal Handle returned in EAX
mov eax, DWORD PTR _rcData$[ebp] ; specify hGlobal handle in EAX
push eax
call DWORD PTR __imp__LockResource@4
mov DWORD PTR _data$[ebp], eax ; If the loaded resource is available, the return value in EAX is a pointer to the first byte of the resource
mov ecx, DWORD PTR _rc$[ebp] ; resource information block handle
push ecx
mov edx, DWORD PTR _hInstance$[ebp] ; hInstance module with resource
push edx
call DWORD PTR __imp__SizeofResource@8
mov DWORD PTR _size$[ebp], eax ; EAX contains size of resource in bytes
在 64 位中查找资源
xor r9d, r9d
mov r8d, 10 ; resource type = 10 = RCDATA
mov edx, 100 ; resource ID = 100
mov rcx, QWORD PTR hInstance$[rsp] ; hInstance to module containing resource
call QWORD PTR __imp_FindResourceExA
mov QWORD PTR rc$[rsp], rax ; handle to the specified resource's information block returned in RAX
mov rdx, QWORD PTR rc$[rsp] ; specify handle to resource information block in RDX
mov rcx, QWORD PTR hInstance$[rsp] ; specify hInstance in RCX
call QWORD PTR __imp_LoadResource
mov QWORD PTR rcData$[rsp], rax ; HGLOBAL returned in RAX
mov rcx, QWORD PTR rcData$[rsp] ; specify HGLOBAL in RCX
call QWORD PTR __imp_LockResource
mov QWORD PTR data$[rsp], rax ; If the loaded resource is available, the return value in RAX is a pointer to the first byte of the resource
mov rdx, QWORD PTR rc$[rsp] ; handle to the specified resource's information block
mov rcx, QWORD PTR hInstance$[rsp] ; hInstance for module containing resource
call QWORD PTR __imp_SizeofResource
mov DWORD PTR size$[rsp], eax ; size of data in bytes returned in EAX