forked from KaylinOwO/projectnacl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.cpp
More file actions
135 lines (115 loc) · 3.41 KB
/
Log.cpp
File metadata and controls
135 lines (115 loc) · 3.41 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
#include "SDK.h"
#include <time.h>
char g_logFile[MAX_PATH];
char g_debugLogFile[MAX_PATH];
void Log::Init(HMODULE hModule) {
memset(g_logFile, 0, sizeof(g_logFile));
if (GetModuleFileNameA(hModule, g_logFile, MAX_PATH) != 0) {
size_t slash = -1;
for (size_t i = 0; i < strlen(g_logFile); i++) {
if (g_logFile[i] == '/' || g_logFile[i] == '\\') {
slash = i;
}
}
if (slash != -1) {
g_logFile[slash + 1] = '\0';
strcpy_s(g_debugLogFile, g_logFile);
strcat_s(g_debugLogFile, "debug.log");
strcat_s(g_logFile, "hook.log");
}
else {
// Shitty manual mapper detected.
MessageBoxA(NULL, "Unable to parse target module path", "ERROR", MB_OK);
//ExitProcess(0);
}
}
else {
// Shitty manual mapper detected.
MessageBoxA(NULL, "GetModuleFileNameA failed", "ERROR", MB_OK);
//ExitProcess(0);
}
}
void Log::Debug(const char* fmt, ...)
{
va_list va_alist;
char szLogbuf[4096];
char szParameters[4066];
char szTimestamp[30];
struct tm current_tm;
time_t current_time = time(NULL);
FILE* file;
localtime_s(¤t_tm, ¤t_time);
sprintf_s(szTimestamp, "[%02d:%02d:%02d]{DEBUG} %%s\n", current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
va_start(va_alist, fmt);
_vsnprintf_s(szParameters, sizeof(szParameters), fmt, va_alist);
va_end(va_alist);
sprintf_s(szLogbuf, szTimestamp, szParameters);
if ((fopen_s(&file, g_debugLogFile, "a")) == 0)
{
fprintf_s(file, "%s", szLogbuf);
fclose(file);
}
}
void Log::Msg(const char* fmt, ...) {
va_list va_alist;
char szLogbuf[4096];
char szParameters[4066];
char szTimestamp[30];
struct tm current_tm;
time_t current_time = time(NULL);
FILE* file;
localtime_s(¤t_tm, ¤t_time);
sprintf_s(szTimestamp, "[%02d:%02d:%02d]{MSG} %%s\n", current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
va_start(va_alist, fmt);
_vsnprintf_s(szParameters, sizeof(szParameters), fmt, va_alist);
va_end(va_alist);
sprintf_s(szLogbuf, szTimestamp, szParameters);
if ((fopen_s(&file, g_logFile, "a")) == 0)
{
fprintf_s(file, "%s", szLogbuf);
fclose(file);
}
}
void Log::Error(const char* fmt, ...) {
va_list va_alist;
char szLogbuf[4096];
char szParameters[4066];
char szTimestamp[30];
struct tm current_tm;
time_t current_time = time(NULL);
FILE* file;
localtime_s(¤t_tm, ¤t_time);
sprintf_s(szTimestamp, "[%02d:%02d:%02d]{ERROR} %%s\n", current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
va_start(va_alist, fmt);
_vsnprintf_s(szParameters, sizeof(szParameters), fmt, va_alist);
va_end(va_alist);
sprintf_s(szLogbuf, szTimestamp, szParameters);
if ((fopen_s(&file, g_debugLogFile, "a")) == 0)
{
fprintf_s(file, "%s", szLogbuf);
fclose(file);
}
MessageBoxA(NULL, szLogbuf, "ERROR", MB_ICONERROR);
}
void Log::Fatal(const char* fmt, ...) {
va_list va_alist;
char szLogbuf[4096];
char szParameters[4066];
char szTimestamp[30];
struct tm current_tm;
time_t current_time = time(NULL);
FILE* file;
localtime_s(¤t_tm, ¤t_time);
sprintf_s(szTimestamp, "[%02d:%02d:%02d]{FATAL} %%s\n", current_tm.tm_hour, current_tm.tm_min, current_tm.tm_sec);
va_start(va_alist, fmt);
_vsnprintf_s(szParameters, sizeof(szParameters), fmt, va_alist);
va_end(va_alist);
sprintf_s(szLogbuf, szTimestamp, szParameters);
if ((fopen_s(&file, g_debugLogFile, "a")) == 0)
{
fprintf_s(file, "%s", szLogbuf);
fclose(file);
}
MessageBoxA(NULL, szLogbuf, "FATAL ERROR", MB_ICONERROR);
ExitProcess(0);
}