植物大战僵尸辅助C/C++版

刚学完C语言基础语法,结合windows API 详解一书
另外 易语言做过一次 就用C语言写了个控制台版本
进程名取进程ID
内存读写操作
免冷却,加金币,加阳光…懒得用CE找了,就只整了这些.

植物大战僵尸辅助C/C++版_第1张图片

#include 
#include 
#include 
#include 
HANDLE hProcess = 0;
DWORD Process_ID;
void NotCool();
DWORD GetPrcsIDbyName(LPCWSTR PrcsName);
DWORD Add_Func(DWORD BaseAdd,DWORD EA1,DWORD EA2,DWORD Num);
int main(void)
{	
	HWND hGame = FindWindow(NULL,L"植物大战僵尸中文版");
	system("title 植物大战僵尸辅助V1.0");
	system("mode con cols=40 lines=20");
	//printf("游戏进程ID: %d\n", GetPrcsIDbyName(L"PlantsVsZombies.exe"));
	if (hGame <= 0)
	{
		printf("未检测到游戏运行,请先运行游戏.\n");
		exit(0);
	}else
	{
		GetWindowThreadProcessId(hGame,&Process_ID);
		hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,Process_ID);
		NotCool();
		if(Add_Func(0x006AA00C,0x768,0x5560,88888))
		{
			printf("阳光充值----------> 成功\n");
		}else{printf("阳光充值----------> 失败\n");}
		if(Add_Func(0x006A9EC0,0x82c,0x28,888888))
		{
			printf("金币充值----------> 成功\n");
		}else{printf("金币充值----------> 失败\n");}
	}
	CloseHandle(hProcess);
	system("pause");
	return 0;
}
void NotCool()
{
	DWORD FLoNum = 0x1477;
	if (WriteProcessMemory(hProcess,(LPVOID)0x00487296,&FLoNum,2,NULL))
	{
		printf("废掉冷却----------> 成功\n");
	}else{printf("废掉冷却----------> 失败\n");}
}
DWORD Add_Func(DWORD BaseAdd,DWORD EA1,DWORD EA2,DWORD Num)
{
	DWORD TmpAdd=0;
	ReadProcessMemory(hProcess,(LPVOID)BaseAdd,&TmpAdd,4,NULL);//基址
	BaseAdd=TmpAdd;
	ReadProcessMemory(hProcess,(LPVOID)(TmpAdd+EA1),&TmpAdd,4,NULL);//偏移1
	EA1=TmpAdd;
	ReadProcessMemory(hProcess,(LPVOID)(TmpAdd+EA2),&TmpAdd,4,NULL);	//偏移2
	EA2=EA1+EA2;
	if(WriteProcessMemory(hProcess,(LPVOID)(EA2),&Num,4,0))
	{return 1;}
	else{return 0;}
}
DWORD GetPrcsIDbyName(LPCWSTR PrcsName)
{
	HANDLE hSnapShot; 
	PROCESSENTRY32 PE32;
	ZeroMemory(&PE32,sizeof(PE32));
	PE32.dwSize=sizeof(PE32);
	hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
	if (hSnapShot == INVALID_HANDLE_VALUE)
	{
		return 0;
	}
	if (!Process32First(hSnapShot,&PE32))
	{
		return 0;
	}
	do 
	{
		if (lstrcmpi(PE32.szExeFile,PrcsName) == 0)
		{
			CloseHandle(hSnapShot);
			return PE32.th32ProcessID;
		}
	} while (Process32Next(hSnapShot,&PE32));
	CloseHandle(hSnapShot);
	return 0;
}

你可能感兴趣的:(C/C++)