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
|
#include <iostream>
#include <Windows.h>
BYTE gbuf_0040100A[] = { 0xE9, 0x77, 0x08, 0x00, 0x00, 0x90 };
BYTE gbuf_00401886[] = {
0x53, 0x51, 0x8B, 0xD8, 0x8B, 0x45, 0x08, 0x8B, 0x4D, 0x0C, 0x0F, 0xAF, 0xC1, 0x8B, 0xCB, 0x03,
0xC8, 0x90, 0x89, 0x4D, 0xFC, 0x59, 0x5B, 0x8B, 0x4D, 0xFC, 0xE9, 0x6B, 0xF7, 0xFF, 0xFF, 0x00 };
int main()
{
std::cout << "Hello World!\n";
//获取目标进程句柄
DWORD pid = 0, oldProtect1 = 0, oldProtect2=0;
printf("请手动输入进程pid");
scanf_s("%d", pid);
HANDLE hp = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
//更改页面属性为 PAGE_EXECUTE_READWRITE
VirtualProtectEx(hp, (PVOID)0x0040100A, 32, PAGE_EXECUTE_READWRITE, &oldProtect1);
VirtualProtectEx(hp, (PVOID)0x00401886, 32, PAGE_EXECUTE_READWRITE, &oldProtect2);
//写入hook代码
//memcpy_s((BYTE*)0x0040100A,6, gbuf_0040100A,6);//本地hook
//memcpy_s((BYTE*)0x00401886,32, gbuf_00401886, 32);
WriteProcessMemory(hp, (BYTE*)0x0040100A, gbuf_0040100A, 6,&pid);
WriteProcessMemory(hp, (BYTE*)0x00401886, gbuf_00401886, 32, &pid);
//恢复原页面属性
VirtualProtectEx(hp, (PVOID)0x0040100A, 32, oldProtect1, &oldProtect1);
VirtualProtectEx(hp, (PVOID)0x00401886, 32, oldProtect2, &oldProtect2);
}
|