I've attempted the type*& cast and some tweaked variations of it on overloaded functions, and the result always caused the compiler to crash with an internal compiler error. You don't want to reference the pointer like you have to for member functions. Void *fPtr = (void*&)SomeGlobalOrStaticFunction And if you do feel like trying that cast for those cases, you'll actually want: If it's static or global, the void*& cast isn't necessary to begin with. Void *fPtr = (void*)&(void*&)Class::Function For non-member or static function overloads, it's simpler as you can cast that to void* without any assemblerĪlso, in case you might be wondering, if you want a void* pointer to a non-overloaded, non-virtual (unless you find a pointer to a vcall thunk useful), non-static member function, you can try this non-standard - meaning, don't try this in non-Microsoft compilers It's entirely possible that it may not work in some older versions of MSVC, and perhaps future versions. RetType (Class::*mfPtrTemp)(args,etc,etc) = (retType (Class::*)(args,etc,etc))&Class::Function And you need to provide the pdb file of your code for this method to work.ĮDIT: Or, as it was pointed out, mark the functions as dllexport (Detours looks for exports first anyway). To your CFoo anymore, it will get optimized out - so you need to disable the linker's unused code elimination. A caveat is that since there's nothing referring It also handles multiple virtual inheritance seamlessly (provided you class compiles the exact same way the target does). ![]() This avoids referring to the virtual function entirely - it's just strings of text. Hook(DetourFindFunction("target.exe", "CFoo::Func"), DetourFindFunction("your.dll", "CFoo::Func")) A caveat is that if the class has multiple virtual inheritance, you might have to do manual 'this' base readjustment to match the caller.Ģ. ![]() This avoids using & on the virtual method directly, and uses the this->CFoo::Func notation to do an explicit call. Hook(DetourFindFunction("target.exe", "CFoo::Func"), &CFoo::_Func) Use a non-virtual helper that will be the target of the detour. I'll list them here, maybe they'll be useful to someone:ġ. So far I have come up with two methods of achieving this. Not sure what that asm code does, but the whole point was to avoid asm (thanks, though).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |