Raised This Month: $51 Target: $400
 12% 

Easy to Hook :)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 04-11-2014 , 00:01   Easy to Hook :)
Reply With Quote #1

First of all, thanks my friend who name's Nagist make metahook .
what you can do with metahook ?
1. Hook virtual table function just like hamsandwich(support windows and linux)
2. Find the function address with the signature, use or hook it(windows only)
3. Hook the API function(windows only)

Ok, now i will show you how to hook virtual table function,
about the function offset we know it can be found at the "hamdata.ini",
yeah this is enough, I will hook player spawn, so the offset is 0 on windows, 2 on linux.

And now I will hook it at entity spawn callback, and it should be very simple to do it just like this ;) all of the code is here. got it ?
Code:
#include "amxxmodule.h" #include "metahook.h" //this is the original address void (__fastcall *g_pfnCBasePlayer_Spawn)(/*CBasePlayer*/void *pThis, int) = NULL; //this is the new addr void __fastcall CBasePlayer_Sapwn(void *pThis, int) {     SERVER_PRINT("\n\tHook player spawn pre.\n");     g_pfnCBasePlayer_Spawn(pThis, 0);//call the original function     SERVER_PRINT("\n\tHook player spawn post.\n"); } int DispatchSpawn(edict_t *ent) {     const char *classname = STRING(ent->v.classname);     if (!strcmp(classname, "worldspawn"))     {         if (!g_pfnCBasePlayer_Spawn)         {             //register a entity spawn hook which the classname is "player"             edict_t *pEntity = g_engfuncs.pfnCreateNamedEntity(MAKE_STRING("player"));//create a new entity             void *pClassData = pEntity->pvPrivateData;//store the class data                         //and hook it             MH_VFTHook(pClassData, 0, 0, CBasePlayer_Sapwn, (void*&)g_pfnCBasePlayer_Spawn);             g_engfuncs.pfnRemoveEntity(pEntity);//remove the entity         }     }     RETURN_META_VALUE(MRES_IGNORED, 0); } void OnMetaAttach(){}

the following code will show you how to find function and hook it with signature:
note that: when use inline hook, have to enable this line;
PHP Code:
#define DISABLE_INLINEHOOK 1 
==>
PHP Code:
#define DISABLE_INLINEHOOK 0 
Code:
#include "amxxmodule.h" #include "metahook.h" #define HANDLEMENU_CHOOSETEAM "\x83\xEC\x2A\x8B\x0D\x2A\x2A\x2A\x2A\x53\x55\x56\x8B\x74\x2A\x2A\x57\x33\xFF" typedef BOOL (*Func_HandleMenuChoose)(CBasePlayer *pPlayer, int slot); Func_HandleMenuChoose HandleMenuChooseOri = NULL; BOOL HandleMenuChooseHook(CBasePlayer *pPlayer, int slot); bool hookCreate(); HMODULE g_hMod; DWORD g_dwModBase, g_dwModSize; BOOL HandleMenuChooseHook(CBasePlayer *pPlayer, int slot) {     BOOL bRet = FALSE;     //hook pre     bRet = HandleMenuChooseOri(pPlayer, slot);     //hook post     return bRet; } void OnMetaAttach() {     g_hMod = GetModuleHandle("mp.dll");         g_dwModBase = MH_GetModuleBase(g_hMod);     g_dwModSize = MH_GetModuleSize(g_hMod);         bool result = hookCreate();         printf("Address Patch : %s\n", result ? "Success" : "Failed" ); } bool hookCreate() {     HandleMenuChooseOri = (Func_HandleMenuChoose)MH_SearchPattern((void*)g_dwModBase, g_dwModSize, HANDLEMENU_CHOOSETEAM, sizeof(HANDLEMENU_CHOOSETEAM) - 1);     return MH_InlineHook(HandleMenuChooseOri, HandleMenuChooseHook, (void*&)HandleMenuChooseOri) ? true : false; }

and the api hook will be coming soom
chinese version here
Attached Files
File Type: zip demo.zip (39.4 KB, 7685 views)
File Type: zip Detours.zip (35.5 KB, 131 views)
__________________
QQ:116268742

Last edited by K.K.Lv; 04-11-2014 at 10:13.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-11-2014 , 04:06   Re: Easy to Hook :)
Reply With Quote #2

So, this is working under linux too ?

You should give more example how to use it.
__________________
Arkshine is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 04-11-2014 , 10:10   Re: Easy to Hook :)
Reply With Quote #3

add snippets about how to use inline hook !
and the api hook will be coming soon.
about the environment, have been update at the first post.
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 04-17-2014 , 01:48   Re: Easy to Hook :)
Reply With Quote #4

Good work!
__________________
youtube:
@holla16
11922911 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-17-2014 , 08:35   Re: Easy to Hook :)
Reply With Quote #5

Sorry but your example contains CBasePlayer_Sapwn instead of "Spawn" two times.
__________________
Black Rose is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 04-17-2014 , 23:13   Re: Easy to Hook :)
Reply With Quote #6

What do you mean ?
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 04-17-2014 , 23:25   Re: Easy to Hook :)
Reply With Quote #7

Quote:
Originally Posted by K.K.Lv View Post
What do you mean ?
He meant you have spelled it wrong in the code.
Sapwn
__________________
youtube:
@holla16

Last edited by 11922911; 04-17-2014 at 23:26.
11922911 is offline
Reply



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 01:44.


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