-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutil.cpp
More file actions
160 lines (119 loc) · 2.97 KB
/
util.cpp
File metadata and controls
160 lines (119 loc) · 2.97 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "util.h"
void util::Message(const char* f, ...)
{
typedef void (*MsgFn)(const char* fmt, ...);
static MsgFn Wrg = (MsgFn)IMPORT("tier0", "Warning");
static MsgFn Msg = (MsgFn)IMPORT("tier0", "Msg");
char buf[1024] = {0};
va_list v;
va_start(v, f);
vsprintf(buf, f, v);
va_end(v);
strcat(buf, "\n");
Wrg("[NanoHack] ");
Msg(buf);
fputs(buf, pipe::log);
fflush(pipe::log);
}
void util::SendStringCmd(const char* fmt, ...)
{
typedef void (__thiscall* SendStringCmdFn)(unsigned long, const char*);
static unsigned long sig = util::FindPattern("engine", "\x68????\xB9????\xE8????\x8D??????\x68");
static SendStringCmdFn
SendStringCmd = (SendStringCmdFn)util::CalcAbsAddress(sig + 11);
char cmd[256];
va_list v;
va_start(v, fmt);
vsprintf(cmd, fmt, v);
va_end(v);
SendStringCmd(*(unsigned long*)(sig + 6), cmd);
}
char* util::SafeFormat(char* string)
{
char* org = string;
for (; *string; ++string)
if (*string == '%')
*string = ' ';
return org;
}
bool util::IsKeyDown(int keycode)
{
if (!keycode)
return 0;
static HWND Valve001 = FindWindow("Valve001", NULL);
if (GetActiveWindow() != Valve001)
return 0;
return GetAsyncKeyState(keycode) != 0;
}
char* util::MakeFancy(const char* string)
{
static char fancy[1024];
char* pu = fancy;
bool abv = 1;
bool trim = 1;
for (; *string; ++string)
{
if (trim && *string == ' ')
continue;
if (!abv && *(pu - 1) != ' ' && *string >= 'A' && *string <= 'Z') // capital check
*(pu++) = ' ';
trim = 0;
abv = *string >= 'A' && *string <= 'Z' && *string > = 'A' && *string <= 'Z';
if (*string == '_')
{
if (*(pu - 1) != ' ' && pu != fancy)
*(pu++) = ' ';
}
else
{
if (*string != ' ' || *(pu - 1) != ' ')
*(pu++) = *string;
}
}
*pu = 0;
if (*fancy > 'Z')
{
*fancy -= 32;
}
return fancy;
}
unsigned long util::FindRefString(const char* dll, const char* string)
{
char m_push[6] = {0x68};
*(unsigned long*)(m_push + 1) = FindPattern(dll, string);
return FindPattern(dll, m_push);
}
unsigned long util::FindPattern(const char* dll, const char* pattern)
{
return FindPattern((unsigned long)GetModuleHandle(dll), (unsigned long)-1, pattern);
}
unsigned long util::FindPattern(unsigned long address, unsigned long size, const char* pattern)
{
for (unsigned long i = 0; i < size; ++i, ++address)
if (DataCompare((const char*)address, pattern))
return address;
return NULL;
}
bool util::DataCompare(const char* base, const char* pattern)
{
for (; *pattern; ++base, ++pattern)
if (*pattern != '?' && *base != *pattern)
return 0;
return *pattern == 0;
}
unsigned long util::FindPatternComplex(unsigned long base, unsigned long size, int n, ...)
{
va_list v;
va_start(v, n);
for (int i = 0; i < n; i++)
{
const char* sig = va_arg(v, const char*);
if (unsigned long ref = FindPattern(base, size, sig))
return ref + strlen(sig);
}
return 0;
}
unsigned long util::CalcAbsAddress(unsigned long address)
{
return address + *(signed long*)address + 4;
}