--- trunk/reactos/lib/kernel32/mem/procmem.c 2005-10-24 17:50:14 UTC (rev 18752)
+++ trunk/reactos/lib/kernel32/mem/procmem.c 2005-10-24 17:54:55 UTC (rev 18753)
@@ -22,26 +22,26 @@
BOOL
STDCALL
ReadProcessMemory (
- HANDLE hProcess,
- LPCVOID lpBaseAddress,
- LPVOID lpBuffer,
- DWORD nSize,
- LPDWORD lpNumberOfBytesRead
- )
+ HANDLE hProcess,
+ LPCVOID lpBaseAddress,
+ LPVOID lpBuffer,
+ DWORD nSize,
+ LPDWORD lpNumberOfBytesRead
+ )
{
- NTSTATUS Status;
+ NTSTATUS Status;
- Status = NtReadVirtualMemory( hProcess, (PVOID)lpBaseAddress,lpBuffer, nSize,
- (PULONG)lpNumberOfBytesRead
- );
+ Status = NtReadVirtualMemory( hProcess, (PVOID)lpBaseAddress,lpBuffer, nSize,
+ (PULONG)lpNumberOfBytesRead
+ );
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return FALSE;
- }
- return TRUE;
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus (Status);
+ return FALSE;
+ }
+ return TRUE;
}
@@ -51,107 +51,107 @@
BOOL
STDCALL
WriteProcessMemory (
- HANDLE hProcess,
- LPVOID lpBaseAddress,
- LPCVOID lpBuffer,
- SIZE_T nSize,
- SIZE_T *lpNumberOfBytesWritten
- )
+ HANDLE hProcess,
+ LPVOID lpBaseAddress,
+ LPCVOID lpBuffer,
+ SIZE_T nSize,
+ SIZE_T *lpNumberOfBytesWritten
+ )
{
- NTSTATUS Status, ProtectStatus = STATUS_SUCCESS;
- MEMORY_BASIC_INFORMATION MemInfo;
- ULONG Length;
- BOOLEAN UnProtect;
+ NTSTATUS Status, ProtectStatus = STATUS_SUCCESS;
+ MEMORY_BASIC_INFORMATION MemInfo;
+ ULONG Length;
+ BOOLEAN UnProtect;
- if (lpNumberOfBytesWritten)
- {
- *lpNumberOfBytesWritten = 0;
- }
+ if (lpNumberOfBytesWritten)
+ {
+ *lpNumberOfBytesWritten = 0;
+ }
- while (nSize)
- {
- Status = NtQueryVirtualMemory(hProcess,
- lpBaseAddress,
- MemoryBasicInformation,
- &MemInfo,
- sizeof(MEMORY_BASIC_INFORMATION),
- NULL);
+ while (nSize)
+ {
+ Status = NtQueryVirtualMemory(hProcess,
+ lpBaseAddress,
+ MemoryBasicInformation,
+ &MemInfo,
+ sizeof(MEMORY_BASIC_INFORMATION),
+ NULL);
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus(Status);
- return FALSE;
- }
- Length = MemInfo.RegionSize - ((ULONG_PTR)lpBaseAddress - (ULONG_PTR)MemInfo.BaseAddress);
- if (Length > nSize)
- {
- Length = nSize;
- }
- UnProtect = MemInfo.Protect & (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY) ? FALSE : TRUE;
- if (UnProtect)
- {
- MemInfo.BaseAddress = lpBaseAddress;
- MemInfo.RegionSize = Length;
- if (MemInfo.Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ))
- {
- MemInfo.Protect &= ~(PAGE_EXECUTE|PAGE_EXECUTE_READ);
- MemInfo.Protect |= PAGE_EXECUTE_READWRITE;
- }
- else
- {
- MemInfo.Protect &= ~(PAGE_READONLY|PAGE_NOACCESS);
- MemInfo.Protect |= PAGE_READWRITE;
- }
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
+ Length = MemInfo.RegionSize - ((ULONG_PTR)lpBaseAddress - (ULONG_PTR)MemInfo.BaseAddress);
+ if (Length > nSize)
+ {
+ Length = nSize;
+ }
+ UnProtect = MemInfo.Protect & (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY) ? FALSE : TRUE;
+ if (UnProtect)
+ {
+ MemInfo.BaseAddress = lpBaseAddress;
+ MemInfo.RegionSize = Length;
+ if (MemInfo.Protect & (PAGE_EXECUTE|PAGE_EXECUTE_READ))
+ {
+ MemInfo.Protect &= ~(PAGE_EXECUTE|PAGE_EXECUTE_READ);
+ MemInfo.Protect |= PAGE_EXECUTE_READWRITE;
+ }
+ else
+ {
+ MemInfo.Protect &= ~(PAGE_READONLY|PAGE_NOACCESS);
+ MemInfo.Protect |= PAGE_READWRITE;
+ }
- ProtectStatus = NtProtectVirtualMemory(hProcess,
- &MemInfo.BaseAddress,
- &MemInfo.RegionSize,
- MemInfo.Protect,
- &MemInfo.Protect);
- if (!NT_SUCCESS(ProtectStatus))
- {
- SetLastErrorByStatus(ProtectStatus);
- return FALSE;
- }
- Length = MemInfo.RegionSize - ((ULONG_PTR)lpBaseAddress - (ULONG_PTR)MemInfo.BaseAddress);
- if (Length > nSize)
- {
- Length = nSize;
- }
- }
-
- Status = NtWriteVirtualMemory(hProcess,
- lpBaseAddress,
- (LPVOID)lpBuffer,
- Length,
- &Length);
- if (UnProtect)
- {
- ProtectStatus = NtProtectVirtualMemory(hProcess,
- &MemInfo.BaseAddress,
- &MemInfo.RegionSize,
- MemInfo.Protect,
- &MemInfo.Protect);
- }
- if (!NT_SUCCESS(Status))
- {
- SetLastErrorByStatus (Status);
- return FALSE;
- }
- if (UnProtect && !NT_SUCCESS(ProtectStatus))
- {
- SetLastErrorByStatus (ProtectStatus);
- return FALSE;
- }
- lpBaseAddress = (LPVOID)((ULONG_PTR)lpBaseAddress + Length);
- lpBuffer = (LPCVOID)((ULONG_PTR)lpBuffer + Length);
- nSize -= Length;
- if (lpNumberOfBytesWritten)
- {
- *lpNumberOfBytesWritten += Length;
- }
- }
- return TRUE;
+ ProtectStatus = NtProtectVirtualMemory(hProcess,
+ &MemInfo.BaseAddress,
+ &MemInfo.RegionSize,
+ MemInfo.Protect,
+ &MemInfo.Protect);
+ if (!NT_SUCCESS(ProtectStatus))
+ {
+ SetLastErrorByStatus(ProtectStatus);
+ return FALSE;
+ }
+ Length = MemInfo.RegionSize - ((ULONG_PTR)lpBaseAddress - (ULONG_PTR)MemInfo.BaseAddress);
+ if (Length > nSize)
+ {
+ Length = nSize;
+ }
+ }
+
+ Status = NtWriteVirtualMemory(hProcess,
+ lpBaseAddress,
+ (LPVOID)lpBuffer,
+ Length,
+ &Length);
+ if (UnProtect)
+ {
+ ProtectStatus = NtProtectVirtualMemory(hProcess,
+ &MemInfo.BaseAddress,
+ &MemInfo.RegionSize,
+ MemInfo.Protect,
+ &MemInfo.Protect);
+ }
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastErrorByStatus (Status);
+ return FALSE;
+ }
+ if (UnProtect && !NT_SUCCESS(ProtectStatus))
+ {
+ SetLastErrorByStatus (ProtectStatus);
+ return FALSE;
+ }
+ lpBaseAddress = (LPVOID)((ULONG_PTR)lpBaseAddress + Length);
+ lpBuffer = (LPCVOID)((ULONG_PTR)lpBuffer + Length);
+ nSize -= Length;
+ if (lpNumberOfBytesWritten)
+ {
+ *lpNumberOfBytesWritten += Length;
+ }
+ }
+ return TRUE;
}
/* EOF */