102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
dttr_sigscan.h
Go to the documentation of this file.
1#ifndef DTTR_SIGSCAN_H
2#define DTTR_SIGSCAN_H
3
4#include <stddef.h>
5#include <stdint.h>
6#include <string.h>
7
8// Scans bytes with 'x' mask entries as exact matches and all other entries as wildcards.
9static inline const uint8_t *DTTR_Sigscan_Bytes(
10 const uint8_t *base,
11 size_t size,
12 const void *sig,
13 const char *mask
14) {
15 if (!base || !sig || !mask) {
16 return NULL;
17 }
18
19 const uint8_t *sig_bytes = sig;
20 const size_t mask_len = strlen(mask);
21 if (mask_len == 0 || mask_len > size) {
22 return NULL;
23 }
24
25 for (size_t i = 0; i <= size - mask_len; i++) {
26 size_t j = 0;
27 for (; j < mask_len; j++) {
28 if (mask[j] != 'x') {
29 continue;
30 }
31
32 if (base[i + j] != sig_bytes[j]) {
33 break;
34 }
35 }
36
37 if (j == mask_len) {
38 return base + i;
39 }
40 }
41
42 return NULL;
43}
44
45#endif // DTTR_SIGSCAN_H
const DWORD size
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
static const uint8_t * DTTR_Sigscan_Bytes(const uint8_t *base, size_t size, const void *sig, const char *mask)
Definition dttr_sigscan.h:9