Zeex / subhook

Simple hooking library for C/C++ (x86 only, 32/64-bit, no dependencies)
BSD 2-Clause "Simplified" License
782 stars 122 forks source link

Hook same tunction multiple times or share hook #12

Closed ghost closed 7 years ago

ghost commented 8 years ago

YSF and SKY both use hook for function GetPacketID. Both of the plugins cant be loaded because latest will crash. Would be good if you create a method to double hook same runction or only hook it once and then just share the hook only.

Zeex commented 8 years ago

It should be possible to hook the same function multiple times, I've done it in other plugins. In that case the n-th (last) hook will call the (n-1)-st nook, which in turn will call (n-2)-nd one and so on until the real implementation is called. If that doesn't work there's probably a bug somewhere, I'll need to look into it.

If by sharing you mean "don't hook again if already hooked" then you can implement that with Subhook::ReadDst: if it returns a non-NULL value, someone might have already hooked the function. For example, JIT uses this method to check if amx_Exec() is hooked by another plugin.