Raised This Month: $63 Target: $400
 15% 

DHooks (Dynamic Hooks - Dev Preview)


Post New Thread Reply   
 
Thread Tools Display Modes
Ryan.
Member
Join Date: Jan 2018
Old 12-17-2018 , 20:33   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #641

Quote:
Originally Posted by asherkin View Post
Make sure that you’re using clang for your build rather than gcc, and that you’re using the right SDK.
Thanks man, I'll give clang a try.
__________________
Ryan. is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 01-11-2019 , 15:12   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #642

Hello everyone,
Dhooks with detours is great extension for saving me time when i want to hook functions, but i have a great problem when i try to post hook a function

Description:
I'm hooking non-virtual member function and when I use a pre hook, it works fine and prints the message in the test plugin, but the return value is invalid(expected, because original function is not called). When I try to use post hook, when i try to build a building, it crashes the server. I firstly used detours6 version, then after the crash i updated to detours7, but crashes still occurs.

Test plugin:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <dhooks>

#pragma newdecls required

#define PLUGIN_NAME     "Build on buildings plugin"
#define PLUGIN_AUTHOR   "Naydef"
#define PLUGIN_VERSION  "1.0"

public Plugin myinfo =
{
    
name PLUGIN_NAME,
    
author PLUGIN_AUTHOR,
    
version PLUGIN_VERSION,
};

Handle hDetourIsPlacementPosValid;

public 
void OnPluginStart()
{
    
Handle gamedatafile=LoadGameConfigFile("buildonbuildings_defs.games");
    if(
gamedatafile==null)
    {
        
SetFailState("Cannot find file buildonbuildings_defs.games!");
    }
    
hDetourIsPlacementPosValid=DHookCreateDetour(Address_NullCallConv_THISCALLReturnType_BoolThisPointer_CBaseEntity);
    if(
hDetourIsPlacementPosValid==null)
    {
        
SetFailState("Failed to create CBaseObject::IsPlacementPosValid detour!");
    }
    
// Load the address of the function from PTaH's signature gamedata file.
    
if(!DHookSetFromConf(hDetourIsPlacementPosValidgamedatafileSDKConf_Signature"CBaseObject::IsPlacementPosValid"))
    {
        
SetFailState("Failed to load CBaseObject::IsPlacementPosValid signature from gamedata");
    }
    
delete gamedatafile;
    
    
// Add a post hook on the function.
    //if(!DHookEnableDetour(hDetourIsPlacementPosValid, false, Detour_IsPlacementPosValid)) // Not crashing
          
if(!DHookEnableDetour(hDetourIsPlacementPosValidtrueDetour_IsPlacementPosValid)) // Crashing
    
{
        
SetFailState("Failed to detour CBaseObject::IsPlacementPosValid!");
    }
}

public 
MRESReturn Detour_IsPlacementPosValid(int pThisHandle hReturnHandle hParams)
{
    if(
pThis==-1)
    {
        return 
MRES_Ignored;
    }
    
/*
    if(DHookGetReturn(hReturn))
    {
        return MRES_Ignored;
    }
    */
    //bool result=false;
    
    
PrintToChatAll("Placement pos valid for: %i is %i"pThisDHookGetReturn(hReturn));
    
//DHookSetReturn(hReturn, result);
    //return MRES_ChangedOverride;
    
return MRES_Ignored;

The gamedata:
PHP Code:
"Games"
{
    
"#default"
    
{
        
"Signatures"
        
{
            
"CBaseObject::IsPlacementPosValid"
            
{
                
"library"        "server"
                "windows"        "\x53\x8b\xdc\x83\xec\x08\x83\xe4\xf0\x83\xc4\x04\x55\x8b\x6b\x04\x89\x6c\x24\x04\x8b\xec\x81\xec\x48\x01\x00\x00\x56\x57\x8b\xf9\x8b\x07\x8b\x80\x18"
                "linux"            "_ZN11CBaseObject19IsPlacementPosValidEv"
            
}
        }
    }

Info:
DHooks with detours(detours6, upgraded to detours7)
Sourcemod 1.8.0.6028
Windows platform
Accelerator crash report from detours6 - https://crash.limetech.org/jag75n4rfrem
Accelerator crash report from detours7 - https://crash.limetech.org/rb6m2np5yorp

The crash looks to me like a NULL pointer problem

Edit:
The functions is actually a virtual function, but i doubt this will create cause the crash.
__________________
My plugins:
Admin Stealth REDUX(v1.6.1)

Non-Sourcemod related projects:
8086eD x86 Emulator

Steam:
naydef

Last edited by Naydef; 01-11-2019 at 15:24.
Naydef is offline
Peace-Maker
SourceMod Plugin Approver
Join Date: Aug 2008
Location: Germany
Old 01-11-2019 , 17:27   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #643

That's an outstanding issue with parameter addresses getting reused in the functions on Windows, so post-hooks don't have access to the initial input anymore. The same holds for the this-pointer, except that there is special handling to save it and restore it for a post-hook. It is only saved from a pre-hook though and thus requires one. To work around that for now, you can add an empty pre hook on the function and you'll have access to the this-pointer in the post hook as well. This doesn't work for parameters.
__________________
Peace-Maker is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 01-12-2019 , 08:11   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #644

Quote:
Originally Posted by Peace-Maker View Post
That's an outstanding issue with parameter addresses getting reused in the functions on Windows, so post-hooks don't have access to the initial input anymore. The same holds for the this-pointer, except that there is special handling to save it and restore it for a post-hook. It is only saved from a pre-hook though and thus requires one. To work around that for now, you can add an empty pre hook on the function and you'll have access to the this-pointer in the post hook as well. This doesn't work for parameters.
Thank you, now the post hook works correctly, but next time it'd be better this info is mentioned somewhere.
__________________
My plugins:
Admin Stealth REDUX(v1.6.1)

Non-Sourcemod related projects:
8086eD x86 Emulator

Steam:
naydef
Naydef is offline
SZOKOZ
Member
Join Date: Jan 2014
Old 02-20-2019 , 15:02   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #645

I have a scenario where I try to retrieve an object from a parameter and try to call a function of that object. Problem is I think the address is getting truncated because I'm retrieving it as an int.
Code:
StartPrepSDKCall(SDKCall_Raw);
PrepSDKCall_SetFromConf(hGameData, SDKConf_Signature, "GetEntityIndex");
PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain);
g_hGetEntityIndex = EndPrepSDKCall();

...

any GameTraceObj = DHookGetParamObjectPtrVar(hParams, 1, 0, ObjectValueType_Int);
SDKCall(g_hGetEntityIndex, GameTraceObj);//Will crash here.
Any future support for retrieving addresses or I'm I making a mistake somewhere.
__________________
May still be available for SM scripting. Just look at my Steam profile regarding my availability.
My Steam
SZOKOZ is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-20-2019 , 15:31   Re: DHooks (Dynamic Hooks - Dev Preview)
Reply With Quote #646

Quote:
Originally Posted by SZOKOZ View Post
Problem is I think the address is getting truncated because I'm retrieving it as an int.
That is not the problem, your address is int-sized.
__________________
asherkin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:01.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode