28.02.2010, 00:36
вот, приблизительно так это у меня сейчас выглядит:
Code:
class Code
{
private:
static DWORD protect;
static LPVOID adress;
static SIZE_T size;
public:
enum HOOK_TYPE
{
JUMP, CALL
};
static void BeginWrite(DWORD adress, DWORD size);
static void EndWrite();
static void Write(DWORD adress, BYTE value);
static void Write(DWORD adress, WORD value);
static void Write(DWORD adress, DWORD value);
static void WriteAdd(DWORD adress, DWORD value);
static void Hook(DWORD adress, LPVOID procedure, HOOK_TYPE type);
};
Code:
void Code::BeginWrite(DWORD a, DWORD s)
{
adress = (LPVOID)a;
size = (SIZE_T)s;
VirtualProtect(adress, size, PAGE_READWRITE, &protect);
}
void Code::EndWrite()
{
VirtualProtect(adress, size, protect, NULL);
}
void Code::Write(DWORD adress, BYTE value)
{
*(LPBYTE)adress = value;
}
void Code::Write(DWORD adress, WORD value)
{
*(LPWORD)adress = value;
}
void Code::Write(DWORD adress, DWORD value)
{
*(LPDWORD)adress = value;
}
void Code::WriteAdd(DWORD adress, DWORD value)
{
*(LPDWORD)adress += value;
}
void Code::Hook(DWORD adress, LPVOID procedure, HOOK_TYPE type)
{
if (type == HOOK_TYPE::JUMP)
Write(adress, (BYTE)0xE9); //write JMP opcode
else //if (type == HOOK_TYPE::CALL)
Write(adress, (BYTE)0xE8); // write CALL opcode
Write(adress + 1, (DWORD)procedure - adress - 5);
}
Code:
void Patch()
{
// ...
Code::BeginWrite(0x401000, 0x239000);
// ...
// ADVMAN window size - FS
Code::Write((0x401530 + 1), (DWORD)screen_Height);
Code::Write((0x401537 + 1), (DWORD)screen_Width);
// ADVMAN window: world view size
Code::WriteAdd((0x401608 + 1), (DWORD)common_stretching_Y);
Code::WriteAdd((0x40160d + 1), (DWORD)common_stretching_X);
// ...
Code::EndWrite();
}