Skip to content

Commit 33d14b7

Browse files
committed
04简单DLL注入游戏
1 parent a782bfb commit 33d14b7

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

04简单DLL注入游戏/Injecter.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// 04简单DLL注入游戏(注入器EXE部分)
3+
// C/C++
4+
//
5+
// Created by luguanxing.
6+
// Copyright @2016 LGX. All rights reserved.
7+
//
8+
#include <windows.h>
9+
#include <string.h>
10+
#include <string>
11+
#include <iostream>
12+
using namespace std;
13+
14+
HWND hwnd = NULL;
15+
DWORD processid = NULL;
16+
HANDLE hprocess = NULL;
17+
PVOID procdlladdr = NULL;
18+
19+
char dllname[25] = "cheatDLL";
20+
char loadfunc[25] = "LoadLibraryA";
21+
FARPROC loadfuncaddr = NULL;
22+
HANDLE hfile;
23+
24+
void getwindow() {
25+
hwnd = ::FindWindow(NULL, "Super Mario XP");
26+
if (hwnd == NULL)
27+
MessageBox(NULL, "找不到游戏", "错误", MB_OK);
28+
GetWindowThreadProcessId(hwnd, &processid);
29+
hprocess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,processid);
30+
if (hprocess == NULL)
31+
MessageBox(NULL, "打开游戏失败", "错误", MB_OK);
32+
}
33+
34+
35+
void inject() {
36+
int size = strlen(dllname)+5;
37+
procdlladdr = ::VirtualAllocEx(hprocess, NULL, size, MEM_COMMIT, PAGE_READWRITE); //向目标申请空间,得到新空间地址
38+
if (procdlladdr == NULL)
39+
MessageBox(NULL, "申请空间失败", "错误", MB_OK);
40+
DWORD writenum;
41+
::WriteProcessMemory(hprocess, procdlladdr, dllname, size, &writenum); //向新空间写入要注入的DLL名称
42+
loadfuncaddr = ::GetProcAddress(::GetModuleHandle("kernel32.dll"), loadfunc); //获得LoadLibraryA的地址,在任何进程空间都一样
43+
HANDLE hthread = ::CreateRemoteThread(hprocess, NULL, 0, (LPTHREAD_START_ROUTINE)loadfuncaddr, (LPVOID)procdlladdr, 0, NULL);
44+
//新建线程执行LoadLibrary参数是已在目标进程新空间写入的DLL名称,注意这个函数在64位下无法成功
45+
::WaitForSingleObject(hthread, INFINITE);
46+
::CloseHandle(hthread);
47+
::CloseHandle(hprocess);
48+
}
49+
50+
int main() {
51+
getwindow();
52+
inject();
53+
return 0;
54+
}

04简单DLL注入游戏/cheatDLL.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// 04简单DLL注入游戏(作弊模块DLL部分)
3+
// C/C++
4+
//
5+
// Created by luguanxing.
6+
// Copyright @2016 LGX. All rights reserved.
7+
//
8+
#include <windows.h>
9+
#define Dllfunciton extern "C" __declspec(dllexport) //以C方式导出
10+
11+
Dllfunciton void lockdata();
12+
Dllfunciton DWORD WINAPI inject(LPVOID);
13+
14+
void lockdata() {
15+
while (true) {
16+
DWORD hp = 10;
17+
DWORD heart = 99;
18+
DWORD life = 99;
19+
20+
DWORD addr = 0x00428282;
21+
DWORD addr2 = 0x00428292;
22+
DWORD addr3 = 0x004282a2;
23+
24+
DWORD res = WriteProcessMemory(INVALID_HANDLE_VALUE, (LPVOID)addr, &hp, 4, 0); //写入自身修改游戏数据
25+
DWORD res2 = WriteProcessMemory(INVALID_HANDLE_VALUE, (LPVOID)addr2, &heart, 4, 0);
26+
DWORD res3 = WriteProcessMemory(INVALID_HANDLE_VALUE, (LPVOID)addr3, &life, 4, 0);
27+
28+
Sleep(1000);
29+
}
30+
}
31+
32+
DWORD WINAPI inject(LPVOID) {
33+
lockdata();
34+
return true;
35+
}
36+
37+
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
38+
switch(ul_reason_for_call) {
39+
case DLL_PROCESS_ATTACH: {
40+
::DisableThreadLibraryCalls(hModule); //创建线程包含死循环,为防卡死必须设置
41+
CreateThread(NULL, 0, inject, NULL, 0, NULL);
42+
}
43+
break;
44+
case DLL_THREAD_ATTACH:
45+
case DLL_THREAD_DETACH:
46+
case DLL_PROCESS_DETACH:
47+
break;
48+
default:;
49+
}
50+
return true;
51+
}

0 commit comments

Comments
 (0)