免责声明:内容仅供学习参考,请合法利用知识,禁止进行违法犯罪活动!
内容参考于:易道云信息技术研究院
上一个内容:74.游戏分析工具的异常定位和修复
以 74.游戏分析工具的异常定位和修复 它的代码为基础进行修改
COBJContext.cpp文件的修改
void COBJContext::Set(const wchar_t* _name, const wchar_t* _address, DWORD _size, const wchar_t* _note, bool IsSet){
CString _txtName;
_txtName.Format(L"%s", _name);
txtAddress.Format(L"%s", _address);
txtNote.Format(L"%s", _note);
Size = _size;
if (_size > Size) {
if (data) delete[]data;
data = new char[Size];
}
Address = (LPVOID)wcstoul(_address, 0, 16);
if(_txtName!=txtName && IsSet){
DeleteFile(txtFile);
}
txtName = _txtName;
txtFile = txtFolder + txtName + L".ini";
Save();
}
CString& COBJContext::GetName()
{
// TODO: 在此处插入 return 语句
return txtName;
}
COBJContext::COBJContext(const wchar_t* folder, const wchar_t* _name) {
txtFolder = folder;
txtFile = txtFolder + _name + L".ini";
wchar_t _address[0xFF]{};
wchar_t _note[0xFF]{};
GetPrivateProfileString(L"main", L"address", L"0", _address, 0xFF, txtFile);
GetPrivateProfileString(L"main", L"note", L"", _note, 0xFF, txtFile);
DWORD _size = GetPrivateProfileInt(L"main", L"size", 0, txtFile);
Set(_name, _address, _size, _note, false);
}
COBJContext::COBJContext(const wchar_t* folder, const wchar_t* _name, const wchar_t* _address, DWORD _size, const wchar_t* _note)
{
txtFolder = folder;
txtFile = txtFolder + _name + L".ini";
Set(_name, _address, _size, _note, false);
}
COBJContext.h文件的修改
#pragma once
typedef class COBJContext
{
CString txtFolder;
CString txtFile;
CString txtName;
LPVOID Address;// 内存地址
/**
内存地址不是一个简单的数字,它有可能是一个 基址 加上 一个数字,有可能还是一个指针算出来的
然后这种的通过字符串进行记录,让它通过字符串可以算出内存地址
Address 与 txtAddress配套使用
*/
CString txtAddress;
DWORD Size{};
CString txtNote;
char* data{};
public:
COBJContext(const wchar_t* folder, const wchar_t* _name);
COBJContext(const wchar_t* folder, const wchar_t* _name, const wchar_t * _address, DWORD _size, const wchar_t* _note);
~COBJContext();
public:
void Save();
void Delete();
BOOL UpdateData(HANDLE _hProcess);
void Set(const wchar_t* _name, const wchar_t* _address, DWORD _size, const wchar_t* _note, bool IsSet=true);
public:
DWORD GetSize();
CString& GetAddress();
CString& GetNote();
CString& GetName();
}*PCOBJContext;
typedef struct TREE_DATA {
DWORD MenuId{};
LPVOID DATA_PTR{};
}*PTREE_DATA;
CwndRAN.cpp文件的修改
void CwndRAN::OnLoadGame()
{
if (wndSelProcess.DoModal() == IDOK) {
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, wndSelProcess.dPid);
if (hProcess) {
auto troot = InsertItemEx(wndSelProcess.wExe, 2, NULL);
InsertItemEx(L"公共数据",3, NULL ,troot);
InsertItemEx(L"公共函数",4, NULL ,troot);
InsertItemEx(L"HOOK分析",5, NULL ,troot);
/* mTree.InsertItem(L"公共数据", troot);
mTree.InsertItem(L"公共函数", troot);
mTree.InsertItem(L"HOOK分析", troot);*/
wAnlyData = wAnlyPath + wndSelProcess.wExe+L"\\";
if (!PathIsDirectory(wAnlyData)) {
if (!CreateDirectory(wAnlyData, NULL)) {
AfxMessageBox(L"创建文件夹失败!");
return;
}
}
// 遍历文件夹下的文件
WIN32_FIND_DATA fileData;
HANDLE hFind = FindFirstFile(wAnlyData + L"\\*.ini", &fileData);
while (hFind != INVALID_HANDLE_VALUE) {
CString _Name = fileData.cFileName;
_Name.Replace(L".ini", L"");
COBJContext* obj = new COBJContext(wAnlyData, _Name);
AddOBJHTree(obj);
/*auto hRoot = InsertItemEx(_Name, 6, obj, TVI_ROOT);
auto hBase = InsertItemEx(L"基本信息", 6, NULL, hRoot);
CString txtVal;
txtVal = L"内存地址:" + obj->GetAddress();
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal.Format(L"对象大小:[%d]", obj->GetSize());
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal = L"注释:" + obj->GetNote();
InsertItemEx(txtVal, 6, NULL, hBase);
InsertItemEx(L"成员变量", 6, NULL, hRoot);
InsertItemEx(L"成员函数", 6, NULL, hRoot);*/
if (!FindNextFile(hFind, &fileData))break;
}
FindClose(hFind);
}
else {
AfxMessageBox(L"游戏加载失败");
}
}
}
void CwndRAN::OnAddClass()
{
// TODO: 在此添加命令处理程序代码
if (!hProcess)return;
if (wndAddClass.DoModal() == IDOK) {
auto h = mTree.GetRootItem();
while (h)
{
h = mTree.GetNextSiblingItem(h);
auto txt = mTree.GetItemText(h);
if (txt == wndAddClass.txtName) {
AfxMessageBox(L"该对象已存在!请勿添加重名对象!");
return;
}
}
COBJContext* obj = new COBJContext(wAnlyData, wndAddClass.txtName, wndAddClass.txtAddress, wndAddClass.Size, wndAddClass.txtNote);
obj->Save();
AddOBJHTree(obj);
/*auto hRoot = InsertItemEx(wndAddClass.txtName, 6, obj, TVI_ROOT);
auto hBase = InsertItemEx(L"基本信息", 6, NULL, hRoot);
CString txtVal;
txtVal = L"内存地址:" + obj->GetAddress();
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal.Format(L"对象大小:[%d]", obj->GetSize());
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal = L"注释:" + obj->GetNote();
InsertItemEx(txtVal, 6, NULL, hBase);
InsertItemEx(L"成员变量", 6, NULL, hRoot);
InsertItemEx(L"成员函数", 6, NULL, hRoot);*/
}
}
void CwndRAN::OnSetClass()
{
// TODO: 在此添加命令处理程序代码
auto hSel = mTree.GetSelectedItem();
auto hRoot = mTree.GetRootItem();
if (hSel == hRoot)return;
auto h = GetFirstItem(hSel);
if (h) {
auto obj = GetOBJPtr(h);
// wndSelProcess.wExe = obj.get
wndAddClass.txtAddress = obj->GetAddress();
wndAddClass.txtNote = obj->GetNote();
wndAddClass.Size = obj->GetSize();
wndAddClass.txtName = mTree.GetItemText(h);
if (wndAddClass.DoModal() == IDOK) {
obj->Set(wndAddClass.txtName, wndAddClass.txtAddress, wndAddClass.Size, wndAddClass.txtNote);
SetOBJHTree(h, obj);
}
}
}
PCOBJContext CwndRAN::GetOBJPtr(HTREEITEM h)
{
PTREE_DATA val = (PTREE_DATA)mTree.GetItemData(h);
if (val) {
PCOBJContext obj = (PCOBJContext)val->DATA_PTR;
return obj;
}
return nullptr;
}
HTREEITEM CwndRAN::AddOBJHTree(PCOBJContext obj)
{
auto hRoot = InsertItemEx(obj->GetName(), 6, obj, TVI_ROOT);
auto hBase = InsertItemEx(L"基本信息", 6, NULL, hRoot);
CString txtVal;
txtVal = L"内存地址:" + obj->GetAddress();
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal.Format(L"对象大小:[%d]", obj->GetSize());
InsertItemEx(txtVal, 6, NULL, hBase);
txtVal = L"注释:" + obj->GetNote();
InsertItemEx(txtVal, 6, NULL, hBase);
InsertItemEx(L"成员变量", 6, NULL, hRoot);
InsertItemEx(L"成员函数", 6, NULL, hRoot);
return hRoot;
}
void CwndRAN::SetOBJHTree(HTREEITEM h, PCOBJContext obj)
{
mTree.SetItemText(h, obj->GetName());
HTREEITEM hBase = mTree.GetChildItem(h);
HTREEITEM hBaseSon = mTree.GetChildItem(hBase);
CString txtVal;
txtVal = L"内存地址:" + obj->GetAddress();
mTree.SetItemText(hBaseSon, txtVal);
txtVal.Format(L"对象大小:[%d]", obj->GetSize());
hBaseSon = mTree.GetNextSiblingItem(hBaseSon);
mTree.SetItemText(hBaseSon, txtVal);
txtVal = L"注释:" + obj->GetNote();
hBaseSon = mTree.GetNextSiblingItem(hBaseSon);
mTree.SetItemText(hBaseSon, txtVal);
}
CwndRAN.h文件的修改
#pragma once
#include "CWndAddClass.h"
#include "CWindProcess.h"
#include "COBJContext.h"
// CwndRAN 对话框
class CwndRAN : public CDialogEx
{
DECLARE_DYNAMIC(CwndRAN)
public:
CwndRAN(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CwndRAN();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_PAGE_2 };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
DECLARE_MESSAGE_MAP()
private:
void OnOK();
void OnCancel();
public:
CTreeCtrl mTree;
CListCtrl LstData;
CWindProcess wndSelProcess;
CWndAddClass wndAddClass;
HANDLE hProcess{};
CString wAppPath;
CString wAnlyPath;
CString wAnlyData;
afx_msg void OnBnClickedButton1();
afx_msg void OnTvnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult);
virtual BOOL OnInitDialog();
afx_msg void OnNMRClickTree1(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnLoadGame();
void SetAppPath(const wchar_t * path);
HTREEITEM InsertItemEx(const wchar_t* txt, DWORD _menuId, LPVOID _data, HTREEITEM h = TVI_ROOT);
void DeleteItemEx(HTREEITEM h);
afx_msg void OnAddClass();
afx_msg void OnDeleteClass();
HTREEITEM GetFirstItem(HTREEITEM h);
afx_msg void OnSetClass();
protected:
PCOBJContext GetOBJPtr(HTREEITEM h);
HTREEITEM AddOBJHTree( PCOBJContext obj);
void SetOBJHTree(HTREEITEM _h, PCOBJContext obj);
};