-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproc.cpp
More file actions
87 lines (78 loc) · 2.11 KB
/
proc.cpp
File metadata and controls
87 lines (78 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Diablo Hacking Utility
*
* Copyright (C)1997 Trojan Consulting Ltd.
*
* andy@trojanco.demon.co.uk
*
* $Header: /diabhack/proc.cpp 1 2/03/99 21:21 Andy $
*/
#include "diabhack.h"
BOOL CProc::m_fReportMemIoErrors = TRUE;
HWND
CProc::GetWindowHandle(LPCSTR pszWindowName)
{
return ::FindWindowEx(NULL, NULL, NULL, pszWindowName);
}
HANDLE
CProc::Open(LPCSTR pszWindowName)
{
HANDLE hReturn = NULL;
HWND hwnd = GetWindowHandle(pszWindowName);
if (hwnd != NULL) {
DWORD dwProcId;
::GetWindowThreadProcessId(hwnd, &dwProcId);
hReturn = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
if (hReturn == NULL) {
::MsgBox(MB_ICONSTOP|MB_OK, "Unable to open process \"%s\"",
pszWindowName);
}
} else {
::MsgBox(MB_ICONSTOP|MB_OK, "Unable to locate process \"%s\"",
pszWindowName);
}
return hReturn;
}
void
CProc::Close(HANDLE &hProc)
{
if (hProc != NULL) {
::CloseHandle(hProc);
}
}
BOOL
CProc::Read(HANDLE hProc, DWORD dwOffset, LPBYTE pBuffer, DWORD dwLen)
{
BOOL fReturn = FALSE;
DWORD dwRead;
if (::ReadProcessMemory(hProc, (LPCVOID)dwOffset, pBuffer, dwLen,
&dwRead)) {
ASSERT(dwRead == dwLen);
fReturn = TRUE;
} else if (m_fReportMemIoErrors) {
if (::MsgBox(MB_ICONSTOP|MB_OKCANCEL,
"Failed to read from offset 0x%lx, len 0x%lx:\n%s",
dwOffset, dwLen, GetLastErrorText()) == IDCANCEL) {
ReportMemIoErrors(FALSE);
}
}
return fReturn;
}
BOOL
CProc::Write(HANDLE hProc, DWORD dwOffset, LPBYTE pBuffer, DWORD dwLen)
{
BOOL fReturn = FALSE;
DWORD dwWritten;
if (::WriteProcessMemory(hProc, (LPVOID)dwOffset, pBuffer, dwLen,
&dwWritten)) {
ASSERT(dwWritten == dwLen);
fReturn = TRUE;
} else if (m_fReportMemIoErrors) {
if (::MsgBox(MB_ICONSTOP|MB_OKCANCEL,
"Failed to write to offset 0x%lx, len 0x%lx:\n%s",
dwOffset, dwLen, GetLastErrorText()) == IDCANCEL) {
ReportMemIoErrors(FALSE);
}
}
return fReturn;
}