-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsigscan.cpp
More file actions
53 lines (41 loc) · 1.19 KB
/
sigscan.cpp
File metadata and controls
53 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "sigscan.h"
CSigScan::CSigScan(BYTE* address, size_t length)
{
addr = address;
len = length;
}
CSigScan* CSigScan::Create(void* interfaceFn)
{
if (!interfaceFn)
return nullptr;
MEMORY_BASIC_INFORMATION mem;
if (!VirtualQuery(interfaceFn, &mem, sizeof(mem)))
return nullptr;
BYTE* addr = (BYTE*)mem.AllocationBase;
IMAGE_DOS_HEADER* dos = (IMAGE_DOS_HEADER*)mem.AllocationBase;
if (dos->e_lfanew <= 0 || dos->e_lfanew > (LONG)mem.RegionSize)
return nullptr;
IMAGE_NT_HEADERS* pe = (IMAGE_NT_HEADERS*)((unsigned long)dos + (unsigned long)dos->e_lfanew);
if (pe->Signature != IMAGE_NT_SIGNATURE)
return nullptr;
return new CSigScan(addr, (size_t)pe->OptionalHeader.SizeOfImage);
}
SigScanAddr CSigScan::Find(const BYTE* sig, const BYTE* mask)
{
BYTE* ptr = addr;
BYTE* end = addr + len;
size_t sigLen = strlen((const char*)mask);
size_t i;
while (ptr + sigLen <= end)
{
for (i = 0; i < sigLen; i++)
{
if ((mask[i] != '?') && (sig[i] != ptr[i]))
break;
}
if (i == sigLen)
return ptr;
ptr++;
}
return nullptr;
}