New Virtual function table hook - worlds better, linux compa
1 Attachment(s)
Well this one's alot better. Again, it lets you hook virtual funcs on any class, but this time it's alot easier to work with, can do more, is faster, smaller, and should make the same code work on windows and linux with no hassle to the coder. Not a bad update. I horribly overengineered the first one. My bad - I blame the drugs. The goods are in the attachment, but here's a HL2 sample:
Code:
//declare the original func and the gate if in windows. syntax is: This *should* work on linux - I went according to XAD's findings. I haven't even compiled it under linux though, but it's childishly simple to get working. When you do, please post so I can update the header :D |
Nice again, lance! Great :)
|
Hi Vance,
thanks, but i have 2 Questions : 1. How to unhook a function 2. Does not work under linux --> Segmentation fault. Do you have a new version ??? |
updated with unhook, and you gotta deprotect the table in linux - just look at xads
oh, and in this ver theres HDEFVFUNC and DEFVFUNC put HDEFVFUNC in a header to allow other files to use it, and DEFVFUNC in the source file - or just DEFVFUNC_ if you don't need it to be exported |
Quote:
It should be a rule that a plugin using hooks MUST NOT be unloaded... /X |
Thanks vancelorgin, works great under Windows.
I have done a protection under linux by using : Quote:
Is the calling-convention different under Linux?? Im no Linux-Expert, so some folks from the Linux-Front can help me out P.S. By the way XAD, I know the problem of unhooking functions. I dont use this in a server-plugin. |
Quote:
|
I used to get seg faults regularly, however, I found out that it was an issue with the size with which mprotect unwrite/rewrite pages, thus, I went back and deprotected a _ton_ of stuff.
I use this for HOOKVFUNC: Code:
#define HOOKVFUNC( classptr , index , funcname , newfunc ) \ Code:
#define PROTECT( ptr, index, val ) DeProtect( ( void* ) ptr , 2048 , val ) Code:
This is not guaranteed to work, but this worked for me 5 weeks ago when I last compiled and ran this code. More specifically, this code does not crash, at least for me, on: Code:
HOOKVFUNC(engine, 21, engine_CreateEdict, myCreateEdict); p.s. BAILOPAN, this _is_ is nifty. p.s.s _yams_ |
I'm having trouble getting this to work. I'm compiling on a Linux system so I combined Vance's and Qizmo's code into this:
Code:
#define ADDRTYPE unsigned long Code:
DEFVFUNC(engine_CreateEdict, edict_t*, (IVEngineServer* pEngine, int iForceEdictIndex)); Code:
../utils/serverplugin/serverplugin.h:71: error: `engine_CreateEdictFunc' does not name a type |
You have to now either do HDEVFUNC and DEFVFUNC with the same params or DEFVFUNC_ - I made it this way so original functions may be exported to other source files (put HDEFVFUNC in a header and DEFVFUNC in *one* source file - the one with your function to be called in it). If you don't need to export it just add the _ on the end and it'll be equivilant to HDEFVFUNC and DEFVFUNC.
Long story short, add a _ to DEFVFUNC. |
All times are GMT -4. The time now is 03:53. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.