07-25-2016, 02:10 PM
Собственно хочу сделать еще одну реинкарнацию пакетхака. На этот раз в виде длл, но возникла большая проблема:
[SRC="c++"]// dllmain.cpp: определяет точку входа для приложения DLL.
#include <Windows.h>
__declspec(dllexport) void dllmain() {}
class UNetworkHandler {};
#pragma pack(push, 1)
struct NetworkPacket
{
unsigned char id, _padding1, exid, _padding2;
unsigned short size, _padding3;
unsigned char* data;
};
struct ClientPacket
{
unsigned char id, _padding1, exid, _padding2;
unsigned short size, _padding3;
unsigned char* data;
};
#pragma pack(pop)
int(__fastcall *UNetworkHandler_AddNetworkQueue)(UNetworkHandler*, int, NetworkPacket*);
typedef void(__cdecl *UNetworkHandler_OutgoingPacket)(unsigned int This, char *Format, ...);
UNetworkHandler_OutgoingPacket true_UNetworkHandler_OutgoingPacket;
void ParseClientPacket(ClientPacket* packet)
{
}
void ParseServerPacket(NetworkPacket* packet)
{
}
//Клиентские пакеты
int __cdecl UNetworkHandler_OutgoingPacket_hook(unsigned int This, char *Format, ...)
{
true_UNetworkHandler_OutgoingPacket(This, Format, ...);
return 0;
}
//Серверные пакеты
int __fastcall UNetworkHandler_IncommingPacket_hook(UNetworkHandler* This, int /*edx*/, NetworkPacket* packet)
{
// Полезная нагрузка перехвата
char buf[1024];
wsprintfA(buf, "Server Packet id=0x%x, size=0x%x", packet->id, packet->size);
OutputDebugStringA(buf);
ParseServerPacket(packet);
//-----------------------------------------
return (*UNetworkHandler_AddNetworkQueue)(This, 0/*чтоугодно*/, packet);
}
DWORD WINAPI InitThread(LPVOID)
{
HMODULE hEngine = LoadLibraryA("Engine.dll");
(FARPROC&)UNetworkHandler_AddNetworkQueue = GetProcAddress(hEngine, "?AddNetworkQueue@UNetworkHandler@@UAEHPAUNetworkPacket@@@Z");
void** UNetworkHandler_vftable = (void**)GetProcAddress(hEngine, "??_7UNetworkHandler@@6BUObject@@@");
void** addr = (void**)(UNetworkHandler_vftable - 0x7); //0x1C for 4 byte
(FARPROC&)true_UNetworkHandler_OutgoingPacket = FARPROC(addr);
*addr = (void*)UNetworkHandler_OutgoingPacket_hook;
void** UNetworkHandler_vftableCheck = UNetworkHandler_vftable;
while (*UNetworkHandler_vftableCheck != (void*)UNetworkHandler_AddNetworkQueue) ++UNetworkHandler_vftableCheck;
*UNetworkHandler_vftableCheck = (void*)UNetworkHandler_IncommingPacket_hook;
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID)
{
if (DLL_PROCESS_ATTACH != ul_reason_for_call)
return 1;
DisableThreadLibraryCalls(hModule);
CreateThread(0, 0, &InitThread, 0, 0, 0);
return 1;
}[/SRC]
Собственно почему в одном случае все работает, а в другом ошибка?)
[SRC="c++"]// dllmain.cpp: определяет точку входа для приложения DLL.
#include <Windows.h>
__declspec(dllexport) void dllmain() {}
class UNetworkHandler {};
#pragma pack(push, 1)
struct NetworkPacket
{
unsigned char id, _padding1, exid, _padding2;
unsigned short size, _padding3;
unsigned char* data;
};
struct ClientPacket
{
unsigned char id, _padding1, exid, _padding2;
unsigned short size, _padding3;
unsigned char* data;
};
#pragma pack(pop)
int(__fastcall *UNetworkHandler_AddNetworkQueue)(UNetworkHandler*, int, NetworkPacket*);
typedef void(__cdecl *UNetworkHandler_OutgoingPacket)(unsigned int This, char *Format, ...);
UNetworkHandler_OutgoingPacket true_UNetworkHandler_OutgoingPacket;
void ParseClientPacket(ClientPacket* packet)
{
}
void ParseServerPacket(NetworkPacket* packet)
{
}
//Клиентские пакеты
int __cdecl UNetworkHandler_OutgoingPacket_hook(unsigned int This, char *Format, ...)
{
true_UNetworkHandler_OutgoingPacket(This, Format, ...);
return 0;
}
//Серверные пакеты
int __fastcall UNetworkHandler_IncommingPacket_hook(UNetworkHandler* This, int /*edx*/, NetworkPacket* packet)
{
// Полезная нагрузка перехвата
char buf[1024];
wsprintfA(buf, "Server Packet id=0x%x, size=0x%x", packet->id, packet->size);
OutputDebugStringA(buf);
ParseServerPacket(packet);
//-----------------------------------------
return (*UNetworkHandler_AddNetworkQueue)(This, 0/*чтоугодно*/, packet);
}
DWORD WINAPI InitThread(LPVOID)
{
HMODULE hEngine = LoadLibraryA("Engine.dll");
(FARPROC&)UNetworkHandler_AddNetworkQueue = GetProcAddress(hEngine, "?AddNetworkQueue@UNetworkHandler@@UAEHPAUNetworkPacket@@@Z");
void** UNetworkHandler_vftable = (void**)GetProcAddress(hEngine, "??_7UNetworkHandler@@6BUObject@@@");
void** addr = (void**)(UNetworkHandler_vftable - 0x7); //0x1C for 4 byte
(FARPROC&)true_UNetworkHandler_OutgoingPacket = FARPROC(addr);
*addr = (void*)UNetworkHandler_OutgoingPacket_hook;
void** UNetworkHandler_vftableCheck = UNetworkHandler_vftable;
while (*UNetworkHandler_vftableCheck != (void*)UNetworkHandler_AddNetworkQueue) ++UNetworkHandler_vftableCheck;
*UNetworkHandler_vftableCheck = (void*)UNetworkHandler_IncommingPacket_hook;
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID)
{
if (DLL_PROCESS_ATTACH != ul_reason_for_call)
return 1;
DisableThreadLibraryCalls(hModule);
CreateThread(0, 0, &InitThread, 0, 0, 0);
return 1;
}[/SRC]
Собственно почему в одном случае все работает, а в другом ошибка?)