-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhack.cpp
More file actions
42 lines (29 loc) · 901 Bytes
/
hack.cpp
File metadata and controls
42 lines (29 loc) · 901 Bytes
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
#include <windows.h>
#include <iostream>
#include <string>
void LogError(std::string process){
std::cout << process << " failed. GetLastError = " << GetLastError() << std::endl;
}
int main(){
DWORD pid;
std::cout << "PID: ";
std::cin >> pid;
const auto handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(handle == NULL){
LogError("OpenProcess");
return EXIT_FAILURE;
}
uintptr_t memoryAddress;
std::cout << "Memory address of the integer to overwrite (in hexadecimal): 0x";
std::cin >> std::hex >> memoryAddress;
int value;
std::cout << "Integer to write (in decimal): ";
std::cin >> std::dec >> value;
auto written = WriteProcessMemory(handle, (LPVOID) memoryAddress, &value, sizeof(value), nullptr);
if(written == FALSE){
LogError("WriteProcessMemory");
return EXIT_FAILURE;
}
std::cout << "Overwritten successfully" << std::endl;
return EXIT_SUCCESS;
}