diff options
Diffstat (limited to 'sigscan.h')
| -rw-r--r-- | sigscan.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sigscan.h b/sigscan.h new file mode 100644 index 0000000..f6727a9 --- /dev/null +++ b/sigscan.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #ifndef SIGSCAN_H | ||
| 2 | #define SIGSCAN_H | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | #ifdef _WIN32 | ||
| 7 | #define WIN32_LEAN_AND_MEAN | ||
| 8 | #include <windows.h> | ||
| 9 | #else | ||
| 10 | #include <dlfcn.h> | ||
| 11 | #include <sys/types.h> | ||
| 12 | #include <sys/stat.h> | ||
| 13 | #endif | ||
| 14 | |||
| 15 | class CSigScan { | ||
| 16 | private: | ||
| 17 | /* Private Variables */ | ||
| 18 | /* Base Address of the server module in memory */ | ||
| 19 | static unsigned char *base_addr; | ||
| 20 | /* The length to the module's ending address */ | ||
| 21 | static size_t base_len; | ||
| 22 | |||
| 23 | /* The signature to scan for */ | ||
| 24 | unsigned char *sig_str; | ||
| 25 | /* A mask to ignore certain bytes in the signature such as addresses | ||
| 26 | The mask should be as long as all the bytes in the signature string | ||
| 27 | Use '?' to ignore a byte and 'x' to check it | ||
| 28 | Example: "xxx????xx" - The first 3 bytes are checked, then the next 4 are | ||
| 29 | ignored, then the last 2 are checked */ | ||
| 30 | char *sig_mask; | ||
| 31 | /* The length of sig_str and sig_mask (not including a terminating null for sig_mask) */ | ||
| 32 | size_t sig_len; | ||
| 33 | |||
| 34 | /* Private Functions */ | ||
| 35 | void* FindSignature(void); | ||
| 36 | |||
| 37 | public: | ||
| 38 | /* Public Variables */ | ||
| 39 | |||
| 40 | /* sigscan_dllfunc is a pointer of something that resides inside the gamedll so we can get | ||
| 41 | the base address of it. From a SourceMM plugin, just set this to ismm->serverFactory(0) | ||
| 42 | in Load(). From a Valve Server Plugin, you must set this to an actual factory returned | ||
| 43 | from gameServerFactory and hope that a SourceMM plugin did not override it. */ | ||
| 44 | static void *(*sigscan_dllfunc)(const char *pName, int *pReturnCode); | ||
| 45 | |||
| 46 | /* If the scan was successful or not */ | ||
| 47 | char is_set; | ||
| 48 | /* Starting address of the found function */ | ||
| 49 | void *sig_addr; | ||
| 50 | |||
| 51 | CSigScan(void): sig_str(NULL), sig_mask(NULL), sig_len(0), sig_addr(NULL) {} | ||
| 52 | ~CSigScan(void); | ||
| 53 | |||
| 54 | static bool GetDllMemInfo(void); | ||
| 55 | int Init(const unsigned char *sig, const char *mask, size_t len); | ||
| 56 | }; | ||
| 57 | |||
| 58 | /* Sigscanned member functions are casted to member function pointers of this class | ||
| 59 | and called with member function pointer syntax */ | ||
| 60 | class EmptyClass { }; | ||
| 61 | |||
| 62 | void InitSigs(void); | ||
| 63 | |||
| 64 | #endif | ||
