[Asm] 纯文本查看 复制代码
#include "stdafx.h"
#include "include/MinHook.h"
#include <Windows.h>
#include <atlstr.h>
typedef void (WINAPI *OldGetSystemTime)(LPSYSTEMTIME);
OldGetSystemTime fpMyC = NULL;
DWORD SEaddress = 0;
void DoEvents()
{
MSG msg;
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
int L = 0;
void search(){
DWORD processId = GetCurrentProcessId();
HANDLE Hprocess;
unsigned char makecode[0x002A] =
{
0xe5, 0x07, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x07
};
//By R-R,
DWORD makecodesize = sizeof(makecode);
int len = 0;
MEMORY_BASIC_INFORMATION buf;
SIZE_T d_len = sizeof(MEMORY_BASIC_INFORMATION);
LPCVOID p_Address = NULL;
BOOL ret;
Hprocess = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
while (VirtualQueryEx(Hprocess, (LPCVOID)p_Address, &buf, d_len) != 0)
{
DWORD Address = 0;
if (buf.Protect != 16 && buf.Protect != 1 && buf.Protect != 512)
{
BYTE *m_code = new BYTE[buf.RegionSize];
ret = ReadProcessMemory(Hprocess, (LPCVOID)p_Address, m_code, buf.RegionSize, 0);
if (*m_code != 0xcd)
{
len = buf.RegionSize;
for (int i = 0; i < len; i++)
{
int ret = memcmp(makecode, m_code, makecodesize);
if (ret != 0)
{
m_code = m_code + 1;
}
if (ret == 0)
{
Address = DWORD(p_Address) + i;
L = L + 1;
if (L == 3)
{
//By R-R,
CString str;
str.Format(_T("Address:%#x"), Address);
MessageBox(0, str, L"", 48);
BYTE Data[] = { 0xE6 };
DWORD Datasize = sizeof(Data);
WriteProcessMemory(Hprocess, (LPVOID)Address, (LPVOID)Data, Datasize, NULL);
}
if (i < len)
{
m_code = m_code + 1;
}
}
}
}
}
if ((DWORD)p_Address > 0x01000000)
{
break;
}
p_Address = (LPCVOID)((DWORD)p_Address + buf.RegionSize);
DoEvents();
}
}
int i = 0;
void MyGetSystemTime(LPSYSTEMTIME lpSystemTime)
{
MessageBoxA(NULL, "安装HOOK成功!", "HOOK成功! ", MB_OK);//进行功能hook
i = i + 1;
if (i == 2)
{
search();
}
fpMyC(lpSystemTime);
}
void MyHook(){
if (MH_Initialize() == MB_OK)
{
MH_CreateHook(&GetSystemTime, &MyGetSystemTime, reinterpret_cast<void**>(&fpMyC));
MH_EnableHook(&GetSystemTime);
}
}