在内存中执行exe [英] execute exe in memory
问题描述
我正在尝试这段代码。
我遇到了错误实际和正式var参数的类型必须相同。在这方面的任何帮助都受到高度赞赏。
I am hitting on error "Types of actual and formal var parameters must be identical" . Any help in this regard is highly appreciated.
......
ReadProcessMemory(ProcInfo.hProcess, pointer(Context.Ebx + 8), @BaseAddress, 4, Bytes); <-- error is here
.......
and
.....
WriteProcessMemory(ProcInfo.hProcess, pointer(ImageNtHeaders.OptionalHeader.ImageBase), InjectMemory, InjectSize, Bytes); <---- error here
......
我正在使用Delphi XE2和Windows 7 64位。我的一些朋友能够在D7环境下进行编译。感谢您的帮助。
I am using Delphi XE2 and windows 7 64 bit. Some of my friends are able to compile it under D7 environment. Any help is appreciated.
推荐答案
该错误告诉您,作为参数传递的变量之一没有必需的类型。错误出现在 var
参数中。这两个函数的最后一个参数是唯一的var参数,因此显然 Bytes
不是必需的类型。
The error tells you that one of the variables you are passing as parameter does not have the required type. The error is in a var
parameter. The final parameter for both these functions is the only var parameter so clearly Bytes
is not the required type.
解决方案是使 Bytes
匹配 ReadProcessMemory
和 WriteProcessMemory 声明中指定的类型。 code>。在XE2中,该类型为
SIZE_T
。因此,您只需要将 Bytes
的定义更改为 SIZE_T
类型。
The solution is to make Bytes
match the type specified in the declaration of ReadProcessMemory
and WriteProcessMemory
. In XE2 that type is SIZE_T
. So you just need to change your definition of Bytes
to be of type SIZE_T
.
以下是XE2声明:
function ReadProcessMemory(hProcess: THandle; const lpBaseAddress: Pointer;
lpBuffer: Pointer; nSize: SIZE_T; var lpNumberOfBytesRead: SIZE_T): BOOL; stdcall;
function WriteProcessMemory(hProcess: THandle; const lpBaseAddress: Pointer;
lpBuffer: Pointer; nSize: SIZE_T; var lpNumberOfBytesWritten: SIZE_T): BOOL; stdcall;
这篇关于在内存中执行exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!