-
Notifications
You must be signed in to change notification settings - Fork 55
/
misc.c
98 lines (58 loc) · 2.08 KB
/
misc.c
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
90
91
92
93
94
95
96
97
98
#include "xor.h"
const unsigned char functionStart[] = "\x09\xC0\x09\xC0\x09\xC0";
const unsigned char functionEnd[] = "\x09\xC9\x09\xC9\x09\xC9";
char text[50];
unsigned char buffer[4096];
BOOL getModuleHandle(DWORD processId, const char* name, DWORD* baseAddr, DWORD* moduleSize){
HANDLE moduleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
MODULEENTRY32 moduleEntry;
moduleEntry.dwSize = sizeof moduleEntry;
if(moduleSnap == INVALID_HANDLE_VALUE)
return FALSE;
Module32First(moduleSnap, &moduleEntry);
do{
if(!strcmp(name, moduleEntry.szModule)){
(*baseAddr) = (DWORD)moduleEntry.modBaseAddr;
(*moduleSize) = moduleEntry.modBaseSize;
CloseHandle(moduleSnap);
return TRUE;
}
}while(Module32Next(moduleSnap, &moduleEntry));
return FALSE;
}
void freeLinkedList(void **entry, DWORD sizeOfEntry){
if(!(*(DWORD*)entry))
return;
freeLinkedList((void*)(*(DWORD*)(entry)) + sizeOfEntry-4, sizeOfEntry); //next level casting lol
free((void*)*(DWORD*)entry);
*(DWORD**)entry = NULL;
}
void removeLastEntry(void **entry, uint32_t sizeOfEntry){
if(!(*(uint32_t*)entry))
return;//should never reach here
uint32_t *curNext = (uint32_t*)(*(uint32_t*)entry + sizeOfEntry-4);
if((void*)*curNext == NULL){
free(*entry);//no leaks
*entry = NULL;
return;
}
removeLastEntry((void*)((*(uint32_t*)entry)+sizeOfEntry-4), sizeOfEntry);
}
BOOLEAN FindPattern(PROCESS_INFORMATION* processInfo, char* pattern, char* mask, void* address){
DWORD scan1 = 0,scan2 = 0;
BOOLEAN found = TRUE;
BYTE* memPosition = (BYTE*)0x69;
for(scan1 = 0; scan1 < 0x70; scan1++){
found = TRUE;
for(scan2 = 0; scan2<strlen(mask); scan2++){
found &= ((BYTE)mask[scan2] == '?' || memPosition[scan1 + scan2] == (BYTE)pattern[scan2]);//Casting is needed if not it fuckups
if(!found)
break;
}
if(found){
(*(DWORD*)address) = (DWORD)memPosition + scan1; //Treat as 32bit value
return TRUE;
}
}
return FALSE;
}