-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathalog.cpp
98 lines (84 loc) · 2.79 KB
/
alog.cpp
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 <stdarg.h>
#include <fstream>
#include <time.h>
#include <aml.h>
#include <mod/logger.h>
#include <android/log.h>
void* hAndroidLog;
bool bAndroidLog_OnlyImportant, bAndroidLog_NoAfter;
std::ofstream oAndroidLogFile;
inline const char* EnumPriority(int prio)
{
switch(prio)
{
case ANDROID_LOG_UNKNOWN: return "UNKNOWN";
case ANDROID_LOG_DEFAULT: return "DEFAULT";
case ANDROID_LOG_VERBOSE: return "VERBOSE";
case ANDROID_LOG_DEBUG: return "DEBUG";
case ANDROID_LOG_INFO: return "INFO";
case ANDROID_LOG_WARN: return "WARN";
case ANDROID_LOG_ERROR: return "ERROR";
case ANDROID_LOG_FATAL: return "FATAL";
case ANDROID_LOG_SILENT: return "SILENT";
}
return "UNKNOWN";
}
inline bool IsImportantLogLevel(int prio)
{
switch(prio)
{
case ANDROID_LOG_DEBUG:
case ANDROID_LOG_WARN:
case ANDROID_LOG_ERROR:
case ANDROID_LOG_FATAL:
return true;
}
return false;
}
char text[4096]; // Log texts are not bigger than 4kb
extern DECL_HOOKv(__aml_log_print, int prio, const char *tag, const char *fmt, ...);
DECL_HOOKv(__aml_log_vprint, int prio, const char *tag, const char *fmt, va_list ap)
{
if(!fmt) return;
if(!tag) tag = "AML: Untagged sender";
vsprintf(text, fmt, ap);
__aml_log_print(prio, tag, text);
if(bAndroidLog_OnlyImportant && !IsImportantLogLevel(prio)) return;
time_t rawtime;
time ( &rawtime );
oAndroidLogFile << asctime(localtime ( &rawtime )) << " [" << EnumPriority(prio) << "][AML Hook: " << tag << "] " << text << std::endl << std::endl;
oAndroidLogFile.flush();
}
DECL_HOOKv(__aml_log_print, int prio, const char *tag, const char *fmt, ...)
{
if(!fmt) return;
va_list ap;
va_start(ap, fmt);
if(!bAndroidLog_NoAfter) HookOf___aml_log_vprint(prio, tag, fmt, ap);
va_end(ap);
}
void HookALog()
{
hAndroidLog = aml->GetLibHandle("liblog.so");
if(!hAndroidLog) return;
uintptr_t __android_log_print_addr = aml->GetSym(hAndroidLog, "__android_log_print");
uintptr_t __android_log_vprint_addr = aml->GetSym(hAndroidLog, "__android_log_vprint");
if(!__android_log_print_addr && !__android_log_vprint_addr)
{
logger->Error("AML Core just failed to patch logs function!");
return;
}
char path[320];
sprintf(path, "%s/android_log_print.txt", aml->GetAndroidDataRootPath());
oAndroidLogFile.open(path, std::ios::out | std::ios::trunc);
if(oAndroidLogFile.is_open())
{
if(__android_log_print_addr) HOOK(__aml_log_print, __android_log_print_addr);
if(__android_log_vprint_addr) HOOK(__aml_log_vprint, __android_log_vprint_addr);
}
else
{
an_epic_fail_ever:
logger->Error("AML Core just failed to open log file!");
}
}