View Single Post
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 10-24-2021 , 10:49   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #852

Can somebody help me with extracting ip address from a detoured function?
PHP Code:
int __usercall sub_29AFF0@<eax>(long double a1@<st0>, int a2int a3void *srcint a5int a6// The function from IDA Pseudo (linux)
int NET_SendPacket INetChannel *chanint sock,  const ns_address &to, const  unsigned char *dataint lengthbf_write *pVoicePayload NULLbool bUseCompression falseuint32 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(errorsizeof(error), "Failed to find ruleshax.games");
        
SetFailState(error);
    }

    
hNetSendPacket DHookCreateDetour(Address_NullCallConv_CDECLReturnType_IntThisPointer_Ignore);
    if (!
hNetSendPacket)
        
SetFailState("Failed to setup detour for NET_SendPacket");
    
    if (!
DHookSetFromConf(hNetSendPackethGameConfSDKConf_Signature"NET_SendPacket"))
        
SetFailState("Failed to load NET_SendPacket signature from gamedata");

    
DHookAddParam(hNetSendPacketHookParamType_ObjectPtr);
    
DHookAddParam(hNetSendPacketHookParamType_Int);
    
DHookAddParam(hNetSendPacketHookParamType_ObjectPtr, -1DHookPass_ByRef);
    
DHookAddParam(hNetSendPacketHookParamType_CharPtr);
    
DHookAddParam(hNetSendPacketHookParamType_Int);
    
//DHookAddParam(hNetSendPacket, HookParamType_ObjectPtr);
    //DHookAddParam(hNetSendPacket, HookParamType_Bool);
    
DHookAddParam(hNetSendPacketHookParamType_Int);

    if (!
DHookEnableDetour(hNetSendPacketfalseDetour_OnNetSendPacket))
        
SetFailState("Failed to detour NET_SendPacket.");

    
PrintToServer("NET_SendPacket detoured!");
}

public 
MRESReturn Detour_OnNetSendPacket(Handle hReturnHandle hParams)
{
    
char addressBuffer[8];
    
DHookGetParamString(hParams3addressBuffersizeof(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.
kadet.89 is offline
Send a message via Skype™ to kadet.89