Cache copy of library on first symbol/signature lookup#1642
Cache copy of library on first symbol/signature lookup#1642peace-maker merged 1 commit intomasterfrom
Conversation
Always perform signature searches on an unaltered copy of the binary. This avoids signature mismatches if the same function is detoured twice and thus the first bytes of the function were replaced by the detour.
|
This is the genial and demanded thing.
When does the first symbol/signature lookup happens by default (except GetMemSig e.t.c.)? I mean, if e.g. I manually detour some function (not via dhooks) from the plugin context, does the most common libs like server/engine had already been precached? |
|
Ok, I see. It only preserves a single symbol by FindPattern request. |
|
The current state of the whole library in memory will be preserved whenever the first call to So this isn't linked to dhooks at all, but only to the address lookup process. You can assume that SourceMod itself already performed some lookup and triggered the caching before the first sourcepawn plugin code runs, yes. |
Always perform signature searches on an unaltered copy of the binary. This avoids signature mismatches if the same function is detoured twice and thus the first bytes of the function were replaced by the detour.

Always perform signature searches on an unaltered copy of the binary. This avoids signature mismatches if the same function is detoured twice and thus the first bytes of the function were replaced by the detour. It is implemented by creating a copy of the current (hopefully unaltered) state of the library on first symbol or signature lookup through
IMemoryUtilsand using that copy to find matching signatures.Now you're able to find signatures even if something else already messed with the bytes. Before this patch, code like this would fail to locate the signature again after the memory was altered (assuming both gamedata files are identical).
So it's not necessary to wildcard the first 6 bytes of a signature to still find it even if the function was detoured by something else. This is only true for SourceMod and its extensions or rather anything using the
IMemoryUtilsto find a signature in memory. It'd be desired to have such an interface exposed in MetaMod:Source for all other server plugins to use in the future.