execute exe in memory

给你一囗甜甜゛ 提交于 2020-01-02 06:30:12

问题


I was trying out this code.

execute EXE from memory

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
......

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.


回答1:


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.

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.

Here are the XE2 declarations:

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;


来源:https://stackoverflow.com/questions/8712290/execute-exe-in-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!