I need packet reader

04/06/2021 20:51 ProKKC#1
I need packet reader
I tested this code but not working
Code:
#include "stdafx.h"
#include <iostream>
#include <detours.h>
#include <vector>
#include <io.h>
#include <fcntl.h>
using namespace std;

typedef int(__fastcall * tHookPacketFunction)(int, int, unsigned int, long**a3); // int __thiscall sub_52AA90(int this, unsigned int a2, const void *a3)
tHookPacketFunction oHookPacketFunction;
void OpenConsole();

void OpenConsole()
{
    int hCrtIn, hCrtOut;
    FILE *conIn, *conOut;

    AllocConsole();
    hCrtIn = _open_osfhandle((intptr_t) GetStdHandle(STD_INPUT_HANDLE), _O_TEXT);
    hCrtOut = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
    conIn = _fdopen(hCrtIn, "r");
    conOut = _fdopen(hCrtOut, "w");
    *stdin = *conIn;
    *stdout = *conOut;
}

int __fastcall hHookPacketFunction(int a1, int ebx, unsigned int a2, long **a3)
{
    //int iVal = static_cast<int>(reinterpret_cast<BYTE*>(a3)[0]);
    for (long i = 0; i < sizeof(a3); i++){
        if (i == sizeof(a3) - 1)
            cout << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << endl;
        else if (i == 0)
            cout << "Packet header : " << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << ", ";
        else
            cout << static_cast<int>(reinterpret_cast<BYTE*>(a3)[i]) << ", ";
    }
    return oHookPacketFunction(a1, ebx, a2, a3);
}

extern "C" __declspec(dllexport) void __cdecl Initialize()
{
    OpenConsole();
    oHookPacketFunction = (tHookPacketFunction) DetourFunction((PBYTE) 0x0052AA90, (PBYTE) hHookPacketFunction);
}

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(NULL, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(Initialize), NULL, 0, NULL);
        break;
    case DLL_THREAD_ATTACH:
        break;
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
if i need pointer how to i get this pointer ?
04/12/2021 12:55 Aeryas#2
The code works fine, you just read the header as I see.

You can easly get the pointer from following a function ( for example selling something to the general store and following the SendShopSellPacket ) to the main SendPacket function and pass that.