Run exe in memory

I tried this code.

execute exe from memory

I click on the error "The types of the actual and formal parameters of var must be the same." Any help in this regard is much 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 can compile it in a D7 environment. Any help is appreciated.

+4
source share
1 answer

The error tells you that one of the variables you pass as a parameter does not have the required type. The error is in the var parameter. The last parameter for both of these functions is the only var parameter, so it is clear that Bytes not the required type.

The solution is to make Bytes match the type specified in the ReadProcessMemory and WriteProcessMemory . In XE2, this type is SIZE_T . So you just need to change your Bytes definition to type SIZE_T .

Here are the XE2 announcements:

 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; 
+5
source

Source: https://habr.com/ru/post/1389065/


All Articles