62.网游逆向分析与插件开发-游戏增加自动化助手接口-游戏公告类的C++还原

内容来源于:易道云信息技术研究院VIP课

上一个内容:游戏红字公告功能的逆向分析-CSDN博客

码云地址(master分支):https://gitee.com/dye_your_fingers/sro_-ex.git

码云版本号:0888e34878d9e7dd0acd08ef045184a44c9ef567

代码下载地址,在 SRO_EX 目录下,文件名为:SRO_Ex-游戏公告类的C++还原.zip

链接:https://pan.baidu.com/s/1W-JpUcGOWbSJmMdmtMzYZg

提取码:q9n5

--来自百度网盘超级会员V4的分享

HOOK引擎,文件名为:黑兔sdk.zip

链接:https://pan.baidu.com/s/1IB-Zs6hi3yU8LC2f-8hIEw

提取码:78h8

--来自百度网盘超级会员V4的分享

游戏红字公告功能的逆向分析-CSDN博客它的代码为基础进行修改

根据之前的分析,发现一个新的类,现在有三个函数,848580黑色文字公告函数,844E40红色文字公告函数,844E80游戏聊天框打印文字(公告打印到聊天框)函数,详情看项目里的分析记录.txt文件

效果图:三个公告全部正常弹出

注意的点0x1256E3C这个地址是在游戏全部初始化完才有值的,所以根据现在的hook位置只有自动药水设定按钮才满足条件,之后再找更合适的初始化位置。

GameEx.cpp文件的修改,修改了 GameEx构造函数,ExitGame函数,AutoHelper函数

cpp 复制代码
#include "pch.h"
#include "GameEx.h"
#include "htdHook2.h"
#include "GameProtect.h"
#include "extern_all.h"

extern int client;
extern GameProtect* _protect;
extern unsigned _stdcall GetFunctionAddress(int index);
htd::hook::htdHook2 hooker;

#include <windows.h>
#include<stdio.h>
#include<TlHelp32.h>

/**
  声明要拦截的函数地址
*/
auto h = GetModuleHandle(NULL);
DWORD address = (DWORD)h;
DWORD addRExit = address + 0x88C77E;

size_t 被拦截修改的函数的地址 = (size_t)addRExit;

LONG NTAPI 异常回调(struct _EXCEPTION_POINTERS* Excep)
{
    printf("异常回调1\n");

    /**
      判断出异常的地方是否为 我们修改的地方
    */
    if ((size_t)Excep->ExceptionRecord->ExceptionAddress == 被拦截修改的函数的地址) {

        //const char* szStr = "nei Rong Bei Xiu Gai";
        //*(DWORD*)(Excep->ContextRecord->Esp + 0x8) = (DWORD)szStr;
        //szStr = "biao Ti Bei Xiu Gai";
        //*(DWORD*)(Excep->ContextRecord->Esp + 0xC) = (DWORD)szStr;

        AfxMessageBox(L"游戏退出!");
        DWORD* _esp = (DWORD*)Excep->ContextRecord->Esp;
        DWORD _val = _esp[1];

        if (_val == 0x1035D0C) {
            AfxMessageBox(L"游戏退出2!");
            auto hMuls = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, L"system_seamp");
            if (hMuls) ReleaseSemaphore(hMuls, 1, 0);
            ExitProcess(0);
        }

        Excep->ContextRecord->Eip = *(DWORD *) Excep->ContextRecord->Esp;
        Excep->ContextRecord->Esp += 8;
        return EXCEPTION_CONTINUE_EXECUTION;
    }
    else {
        /**
          防止被其它地方修改了函数地址
        */
        Excep->ContextRecord->Dr0 = 被拦截修改的函数的地址;
        Excep->ContextRecord->Dr7 = 0x405;
        return EXCEPTION_CONTINUE_SEARCH;
    }

}

VOID 设置线程的dr寄存器(HANDLE 线程句柄) {

    printf("设置线程的dr寄存器1\n");
    CONTEXT ctx;
    ctx.ContextFlags = CONTEXT_ALL;
    GetThreadContext(线程句柄, &ctx);
    ctx.Dr0 = 被拦截修改的函数的地址;
    ctx.Dr7 = 0x1;
    SetThreadContext(线程句柄, &ctx);
    printf("设置线程的dr寄存器2\n");
}

VOID 使用dr寄存器拦截修改函数() {
    printf("使用dr寄存器拦截修改函数1\n");
    HANDLE 线程快照句柄 = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
    if (线程快照句柄 == INVALID_HANDLE_VALUE) {
        printf("线程快照创建失败");
        return;
    }

    THREADENTRY32* 线程结构体 = new THREADENTRY32;
    线程结构体->dwSize = sizeof(THREADENTRY32);

    /**
      Thread32First获取快照中第一个线程
       返回值bool类型
    */
    // Thread32First(线程快照句柄, &线程结构体);

    HANDLE 线程句柄 = NULL;

    printf("使用dr寄存器拦截修改函数2\n");

    /**
      Thread32Next获取线程快照中下一个线程
    */
    while (Thread32Next(线程快照句柄, 线程结构体))
    {
        if (线程结构体->th32OwnerProcessID == GetCurrentProcessId()) {
            printf("使用dr寄存器拦截修改函数3\n");
            线程句柄 = OpenThread(THREAD_ALL_ACCESS, FALSE, 线程结构体->th32ThreadID);
            printf("使用dr寄存器拦截修改函数4\n");
            设置线程的dr寄存器(线程句柄);
            printf("使用dr寄存器拦截修改函数5\n");
            CloseHandle(线程句柄);
        }
    }
}

SRO_String vip_notice;

bool AutoHelper(HOOKREFS2) {
    // 使用通过获取游戏中的sro_string结构
    //auto read = _pgamebase->SRO_Res->ReadTitle((wchar_t*)0xEBC968);
    // 使用自己创建的sro_string结构
    /**
        sro_string str;
        str.Ptitle = L"您还没有开通VIP服务,只能使用普通药水辅助功能,开通VIP可以使用更高级的自动化助手功能!";
        str.lenth = 47;
        str.size = 48 * 2 + 1;
        auto read = &str;
        unsigned* _ecx = (unsigned*)0x1256E3C;
        unsigned readEcx = _ecx[0];
        unsigned _call = 0x848580;
        _asm {
            mov ecx, readEcx
            push read
            call _call
        }
    */
    _pgamebase->Init();
    _pgamebase->SRO_Notice->NetNotice(&vip_notice);
    _pgamebase->SRO_Notice->ChatNotice(vip_notice.wcstr(), 0xFFFF0000);
    _pgamebase->SRO_Notice->NormalNotice(&vip_notice);

    bool vip = false;
    if (vip)return false;
    else return true;
}

bool ExitGame(HOOKREFS2) {
    //AfxMessageBox(L"ExitGame");
    //auto read = _pgamebase->SRO_Res->ReadTitle((wchar_t*)0xEBC968);
    //CString txt;
    //txt.Format(L"------ %s", read->wcstr());
     read->Ptitle = L"自动助手 [VIP] (%s)";
    //*read = L"自动助手 [VIP] (%s)";
    //AfxMessageBox(txt);

    // if (_protect->CheckDebugByNT())AfxMessageBox(L"检测到了DEBUG程序的存在");
	// AfxMessageBox(L"游戏退出2222!");
	DWORD* _esp = (DWORD*)_ESP;
	DWORD _val = _esp[1];

	if (_val == 0x1035D0C) {
		// AfxMessageBox(L"游戏退出!");
		auto hMuls = OpenSemaphore(SEMAPHORE_ALL_ACCESS, FALSE, L"system_seamp");
		if (hMuls) ReleaseSemaphore(hMuls, 1, 0);
        client--;
		ExitProcess(0);
	}
	return true;
}

GameEx::GameEx()
{
    vip_notice = L"(自动化助手公告)您还没有海通VIP服务,只能使用普通的药水设定功能,开通VIP后可以享受全自动辅助功能!";
	// AfxMessageBox(L"注册hook!");
	// auto h = GetModuleHandle(NULL);
	// DWORD address = (DWORD)h;
    // DWORD* addRExit = (DWORD*)(address + 0x88C77E);
    /**addRExit = 0;*/
	// CString txt;
    // txt.Format(L"addRExit[0]D:%d,addRExit[0]X:%X,addRExit:%X", addRExit[0], addRExit[0], addRExit);
    // AfxMessageBox(txt);

    // hooker.SetHook((LPVOID)addRExit, 3, ExitGame);
    //AddVectoredExceptionHandler(1, 异常回调);
    //设置线程的dr寄存器(GetCurrentThread());
}

void GameEx::InitInterface()
{
    unsigned addr_cps =  GetFunctionAddress(0);
    hooker.SetHook((LPVOID)(addr_cps + 0x30 - 2), 0x3, ExitGame);
    hooker.SetHook((LPVOID)(addr_cps + 0x51 - 2), 0x3, ExitGame);

    unsigned addr_autohelper = GetFunctionAddress(1);
    hooker.SetHook((LPVOID)(addr_autohelper), 0x03, AutoHelper, (LPVOID)(addr_autohelper + 0x90));
}

新加SRO_String.cpp文件

cpp 复制代码
#include "pch.h"
#include "SRO_String.h"

int SRO_String::stringlength(const wchar_t* str)
{
	for (lenth = 0; str[lenth]; lenth++);
	size = lenth * 2 + 1;
	return size;
}

wchar_t* SRO_String::wcstr()
{
	if (size < 0x8) {
		return title;
	}
	else {
		return Ptitle;
	}
}

SRO_String& SRO_String::operator=(const wchar_t* _txt)
{
	int _size = stringlength(_txt);

	if (_size > 8) {
		Ptitle = (wchar_t*)_txt;
	}
	else {
		memcpy(title, _txt, _size);
	}

	return *this;
}

新加SRO_String.h文件

cpp 复制代码
#pragma once

typedef class SRO_String
{
private:
	int un1;
	union {
		wchar_t title[0x4];
		wchar_t* Ptitle;
	};
	int un2[0x2];

	unsigned lenth;
	unsigned size;
	int stringlength(const wchar_t* str);
public:
	wchar_t* wcstr();
	SRO_String& operator=(const wchar_t* _txt);
}*PSROSTRING;

Res.cpp文件的修改,修改函数的返回值为PSROSTRING类型

cpp 复制代码
#include "pch.h"
#include "Res.h"
// 这里为了给 _ReadTitle 默认值,防止编译不通过
Res::PROC_WCHAR1 Res::_ReadTitle{};
PSROSTRING Res::ReadTitle(wchar_t* index)
{
	/**
		获取按钮文字通过逆向分析,看出是一个thiscall
		在调用获取文字函数时给ecx赋值了,这是典型的thiscall方式
		下方(this->*_ReadTitle)(index)写法翻译成汇编就会是
		mov ecx,this
		mov eax, [ecx+xxx];
		push index
		call eax
		大概就会变成上方四行代码,也就是一个thiscall
		如果穿插汇编代码,会很lou,这样用c++写就很优雅
	*/
	return (this->*_ReadTitle)(index);
}

Res.h文件的修改,新加SRO_String.h文件并使用

cpp 复制代码
#pragma once
#include "SRO_String.h"
// sro_string通过逆向分析,文字获取方式得到的一个结构体
typedef class Res
{
	// 定义一个函数指针
	typedef PSROSTRING(Res::* PROC_WCHAR1)(wchar_t*);
public:
	// 给函数指针声明一个变量
	static PROC_WCHAR1 _ReadTitle;
	// 封装 _ReadTitle 使用时比较好用
	PSROSTRING ReadTitle(wchar_t* index);

}*PRes;

新加Notice类

Notice.h文件

cpp 复制代码
#pragma once
#include "SRO_String.h"
typedef class Notice
{
	typedef void (Notice::* PROC_PSROSTR)(PSROSTRING);
	typedef void (Notice::* PROC_D_PWSTR_D_D)(int, wchar_t*, int, int);
public:
	static PROC_PSROSTR _NormalNotice;
	static PROC_PSROSTR _NetNotice;
	static PROC_D_PWSTR_D_D _ChatNotice;
public:
	void NormalNotice(PSROSTRING _txt);
	void NetNotice(PSROSTRING _txt);
	void ChatNotice(wchar_t* _txt, int color=0xFFFFAEC3, int type1=0x3, int type2=0x1);
}*PNotice;

Notice.cpp文件

cpp 复制代码
#include "pch.h"
#include "Notice.h"

Notice::PROC_PSROSTR Notice::_NormalNotice{};
Notice::PROC_PSROSTR Notice::_NetNotice{};
Notice::PROC_D_PWSTR_D_D Notice::_ChatNotice{};

void Notice::NormalNotice(PSROSTRING _txt)
{
	(this->*_NormalNotice)(_txt);
}

void Notice::NetNotice(PSROSTRING _txt)
{
	(this->*_NetNotice)(_txt);
}

/**
	type1 默认0x3
	type2 默认0x1
*/
void Notice::ChatNotice(wchar_t* _txt, int color, int type1, int type2)
{
	(this->*_ChatNotice)(type1, _txt, color, type2);
}

GameBase.cpp文件的修改,修改Init函数

cpp 复制代码
#include "pch.h"
#include "GameBase.h"

GameBase* _pgamebase;

void GameBase::Init()
{
	unsigned* addrRead = (unsigned*)0x1256E3C;

	SRO_Res = (PRes)0x1036518;
	SRO_Notice = (PNotice)addrRead[0];
	
	InitClassProc(&Res::_ReadTitle, 0x9A46C0);
	InitClassProc(&Notice::_NormalNotice, 0x848580);
	InitClassProc(&Notice::_NetNotice, 0x844E40);
	InitClassProc(&Notice::_ChatNotice, 0x844E80);

}

void GameBase::InitClassProc(LPVOID proc_addr, unsigned value)
{
	unsigned* uWrite = (unsigned*)proc_addr;
	uWrite[0] = value;
}

GameBase::GameBase()
{
	_pgamebase = this;
	// Init();// 初始化机制,完成游戏与我们dll的对接
}

GameBase.h文件的修改,修改了Init函数

cpp 复制代码
#pragma once
#include "Res.h"
#include "Notice.h"

class GameBase
{
	void InitClassProc(LPVOID proc_addr, unsigned value);
public:
	void Init();
	GameBase();
	PRes SRO_Res;
	PNotice SRO_Notice;
};
相关推荐
FairGuard手游加固6 小时前
Cocos资源加密方案解析
安全·游戏·cocos2d
UWA19 小时前
为什么Android游戏画面在30帧运行时有抖动现象
android·游戏
软件开发技术深度爱好者1 天前
python使用Pygame库实现避障小人行走游戏
python·游戏·pygame
星空露珠1 天前
数独生成题目lua脚本
数据结构·数据库·算法·游戏·lua
wanhengidc1 天前
云手机 基于云计算的虚拟手机
运维·服务器·游戏·智能手机·云计算
王火火(DDoS CC防护)2 天前
游戏盾是如何保障游戏安全稳定的?
游戏·网络安全·ddos攻击·sdk游戏盾
上海云盾第一敬业销售2 天前
高防CDN如何确保电商平台在购物节期间运转如常
安全·游戏·ddos
星空露珠2 天前
数独解题算法lua脚本
开发语言·数据结构·算法·游戏·lua
AA陈超2 天前
虚幻引擎5 GAS开发俯视角RPG游戏 P06-25 属性信息数据资产
c++·游戏·ue5·游戏引擎·虚幻
Hello123网站2 天前
h5游戏免费下载:小猪飞飞
游戏