Can somebody help me with extracting ip address from a detoured function?
PHP Code:
int __usercall sub_29AFF0@<eax>(long double a1@<st0>, int a2, int a3, void *src, int a5, int a6) // The function from IDA Pseudo (linux)
int NET_SendPacket ( INetChannel *chan, int sock, const ns_address &to, const unsigned char *data, int length, bf_write *pVoicePayload = NULL, bool bUseCompression = false, uint32 unMillisecondsDelay = 0u ); // The same function from some old sources
The ns_address contains netadr_t as the first field, which is technically this:
PHP Code:
struct netadr_t
{
public:
netadrtype_t type; //enum
unsigned char ip[4];
unsigned short port;
};
Here is what I have at the moment
PHP Code:
public OnPluginStart()
{
new Handle:hGameConf;
new String:error[128];
hGameConf = LoadGameConfigFile("ruleshax.games");
if(!hGameConf)
{
Format(error, sizeof(error), "Failed to find ruleshax.games");
SetFailState(error);
}
hNetSendPacket = DHookCreateDetour(Address_Null, CallConv_CDECL, ReturnType_Int, ThisPointer_Ignore);
if (!hNetSendPacket)
SetFailState("Failed to setup detour for NET_SendPacket");
if (!DHookSetFromConf(hNetSendPacket, hGameConf, SDKConf_Signature, "NET_SendPacket"))
SetFailState("Failed to load NET_SendPacket signature from gamedata");
DHookAddParam(hNetSendPacket, HookParamType_ObjectPtr);
DHookAddParam(hNetSendPacket, HookParamType_Int);
DHookAddParam(hNetSendPacket, HookParamType_ObjectPtr, -1, DHookPass_ByRef);
DHookAddParam(hNetSendPacket, HookParamType_CharPtr);
DHookAddParam(hNetSendPacket, HookParamType_Int);
//DHookAddParam(hNetSendPacket, HookParamType_ObjectPtr);
//DHookAddParam(hNetSendPacket, HookParamType_Bool);
DHookAddParam(hNetSendPacket, HookParamType_Int);
if (!DHookEnableDetour(hNetSendPacket, false, Detour_OnNetSendPacket))
SetFailState("Failed to detour NET_SendPacket.");
PrintToServer("NET_SendPacket detoured!");
}
public MRESReturn Detour_OnNetSendPacket(Handle hReturn, Handle hParams)
{
char addressBuffer[8];
DHookGetParamString(hParams, 3, addressBuffer, sizeof(addressBuffer));
PrintToServer("OnNetSendPacket called %x %x %x %x %x %x %x %x", addressBuffer[0], addressBuffer[1], addressBuffer[2], addressBuffer[3], addressBuffer[4], addressBuffer[5], addressBuffer[6], addressBuffer[7]);
return MRES_Ignored;
}
The hook works, but the result ip address is 0 0 0 0. Also the CC is incorrect, but it crashes if I change it to anything else.