-
Notifications
You must be signed in to change notification settings - Fork 8
/
func.h
89 lines (67 loc) · 1.46 KB
/
func.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include<Windows.h>
void PrintSingleCharacter(char c)
{
DWORD written;
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), &c, 1, &written, NULL);
}
void PrintMessage(const char* fmt, ...)
{
char buf[4096];
va_list args;
va_start(args, fmt);
vsnprintf(buf, 4096, fmt, args);
char* bufptr = buf;
while (*bufptr)
{
if (*bufptr == '~')
{
++bufptr;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), *bufptr);
}
else
{
PrintSingleCharacter(*bufptr);
}
++bufptr;
}
PrintSingleCharacter('\n');
va_end(args);
}
bool write_file(const char* name, const void* data, size_t len)
{
FILE* f = fopen(name, "wb");
if (f == NULL)
{
PrintMessage("[-] error writing file");
return false;
}
size_t r = fwrite(data, 1, len, f);
if (r != len)
{
PrintMessage("[-] error writing file");
return false;
}
fclose(f);
return true;
}
uintptr_t find_pattern(const char* block, uint64_t startAddress, uint64_t size, const char* pattern, const char* mask, int offset)
{
size_t pos = 0;
auto maskLength = strlen(mask);
for (int j = 0; j < size; j++)
{
if (block[j] == pattern[pos] || mask[pos] == '?')
{
if (mask[pos + 1] == '\0')
{
PrintMessage("[+] pattern scan succeeded!\n");
return startAddress + j - maskLength + offset;
}
pos++;
}
else pos = 0;
}
PrintMessage("[-] pattern scan failed!\n");
return 0;
}