cheat-engine/dbvmPhysicalMemoryHandler.pas
cheatengine@gmail.com 4d297adfd2
2011-07-04 19:52:19 +00:00

62 lines
No EOL
2.1 KiB
ObjectPascal

unit dbvmPhysicalMemoryHandler;
{
implement replaced handlers for ReadProcssMemory and WriteProcessMemory so it
reads/writes to the physical memory instead
}
interface
uses windows;
function ReadProcessMemoryPhys(hProcess: THandle; const lpBaseAddress: Pointer; lpBuffer: Pointer; nSize: DWORD; var lpNumberOfBytesRead: DWORD): BOOL; stdcall;
function WriteProcessMemoryPhys(hProcess: THandle; const lpBaseAddress: Pointer; lpBuffer: Pointer; nSize: DWORD; var lpNumberOfBytesWritten: DWORD): BOOL; stdcall;
function VirtualQueryExPhys(hProcess: THandle; lpAddress: Pointer; var lpBuffer: TMemoryBasicInformation; dwLength: DWORD): DWORD; stdcall;
implementation
uses newkernelhandler;
function ReadProcessMemoryPhys(hProcess: THandle; const lpBaseAddress: Pointer; lpBuffer: Pointer; nSize: DWORD; var lpNumberOfBytesRead: DWORD): BOOL; stdcall;
begin
lpNumberOfBytesRead:=dbvm_read_physical_memory(uint64(lpBaseAddress),lpBuffer,nSize);
result:=lpNumberOfBytesRead>0;
end;
function WriteProcessMemoryPhys(hProcess: THandle; const lpBaseAddress: Pointer; lpBuffer: Pointer; nSize: DWORD; var lpNumberOfBytesWritten: DWORD): BOOL; stdcall;
begin
lpNumberOfBytesWritten:=dbvm_write_physical_memory(uint64(lpBaseAddress),lpBuffer,nSize);
result:=lpNumberOfBytesWritten>0;
end;
function VirtualQueryExPhys(hProcess: THandle; lpAddress: Pointer; var lpBuffer: TMemoryBasicInformation; dwLength: DWORD): DWORD; stdcall;
var filesize: uint64;
begin
filesize:=$100000000;
lpBuffer.BaseAddress:=pointer((dword(lpAddress) div $1000)*$1000);
lpbuffer.AllocationBase:=lpbuffer.BaseAddress;
lpbuffer.AllocationProtect:=PAGE_EXECUTE_READWRITE;
lpbuffer.RegionSize:=filesize-dword(lpBuffer.BaseAddress);
lpbuffer.RegionSize:=lpbuffer.RegionSize+($1000-lpbuffer.RegionSize mod $1000);
lpbuffer.State:=mem_commit;
lpbuffer.Protect:=PAGE_EXECUTE_READWRITE;
lpbuffer.Type_9:=MEM_PRIVATE;
if (dword(lpAddress)>filesize) //bigger than the file
then
begin
zeromemory(@lpbuffer,dwlength);
result:=0
end
else
result:=dwlength;
end;
end.