From 82fcda6c25bb183f0ae616eb7464968a3095aac2 Mon Sep 17 00:00:00 2001 From: Jurriaan Bremer Date: Fri, 18 Jul 2014 10:13:09 +0200 Subject: [PATCH] automatically assign log indices --- hook_process.c | 2 +- hook_reg.c | 12 ++++++------ hook_reg_native.c | 4 ++-- hook_sleep.c | 2 +- hook_window.c | 4 ++-- log.c | 16 +--------------- log.h | 14 ++++---------- 7 files changed, 17 insertions(+), 37 deletions(-) diff --git a/hook_process.c b/hook_process.c index 1da939a..625bbd6 100644 --- a/hook_process.c +++ b/hook_process.c @@ -161,7 +161,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtOpenProcess, NTSTATUS ret = Old_NtOpenProcess(ProcessHandle, DesiredAccess, ObjectAttributes, ClientId); - LOQ2("PpP", "ProcessHandle", ProcessHandle, + LOQ("PpP", "ProcessHandle", ProcessHandle, "DesiredAccess", DesiredAccess, "ProcessIdentifier", &pid); /* diff --git a/hook_reg.c b/hook_reg.c index 6151e1a..1399e9b 100644 --- a/hook_reg.c +++ b/hook_reg.c @@ -171,7 +171,7 @@ HOOKDEF(LONG, WINAPI, RegEnumValueA, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData); } else { - LOQ2("plsLL", "Handle", hKey, "Index", dwIndex, + LOQ("plsLL", "Handle", hKey, "Index", dwIndex, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData); } return ret; @@ -196,7 +196,7 @@ HOOKDEF(LONG, WINAPI, RegEnumValueW, "ValueName", lpValueName, "Data", *lpType, *lpcbData, lpData); } else { - LOQ2("pluLL", "Handle", hKey, "Index", dwIndex, + LOQ("pluLL", "Handle", hKey, "Index", dwIndex, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData); } return ret; @@ -217,7 +217,7 @@ HOOKDEF(LONG, WINAPI, RegSetValueExA, "Buffer", dwType, cbData, lpData); } else { - LOQ2("psl", "Handle", hKey, "ValueName", lpValueName, "Type", dwType); + LOQ("psl", "Handle", hKey, "ValueName", lpValueName, "Type", dwType); } return ret; } @@ -237,7 +237,7 @@ HOOKDEF(LONG, WINAPI, RegSetValueExW, "Buffer", dwType, cbData, lpData); } else { - LOQ2("pul", "Handle", hKey, "ValueName", lpValueName, "Type", dwType); + LOQ("pul", "Handle", hKey, "ValueName", lpValueName, "Type", dwType); } return ret; } @@ -259,7 +259,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExA, "Data", *lpType, *lpcbData, lpData); } else { - LOQ2("psLL", "Handle", hKey, "ValueName", lpValueName, + LOQ("psLL", "Handle", hKey, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData); } return ret; @@ -282,7 +282,7 @@ HOOKDEF(LONG, WINAPI, RegQueryValueExW, "Data", *lpType, *lpcbData, lpData); } else { - LOQ2("puLL", "Handle", hKey, "ValueName", lpValueName, + LOQ("puLL", "Handle", hKey, "ValueName", lpValueName, "Type", lpType, "DataLength", lpcbData); } return ret; diff --git a/hook_reg_native.c b/hook_reg_native.c index 4640200..71dfd1b 100644 --- a/hook_reg_native.c +++ b/hook_reg_native.c @@ -133,7 +133,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtSetValueKey, "Type", Type, "Buffer", Type, DataSize, Data); } else { - LOQ2("pol", "KeyHandle", KeyHandle, "ValueName", ValueName, + LOQ("pol", "KeyHandle", KeyHandle, "ValueName", ValueName, "Type", Type); } return ret; @@ -175,7 +175,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtQueryValueKey, "Type", Type, "Information", Type, DataLength, Data); } else { - LOQ2("po", "KeyHandle", KeyHandle, "ValueName", ValueName); + LOQ("po", "KeyHandle", KeyHandle, "ValueName", ValueName); } return ret; diff --git a/hook_sleep.c b/hook_sleep.c index 753c5dc..f606325 100644 --- a/hook_sleep.c +++ b/hook_sleep.c @@ -63,7 +63,7 @@ HOOKDEF(NTSTATUS, WINAPI, NtDelayExecution, } } unsigned long milli = -DelayInterval->QuadPart / 10000; - LOQ2("l", "Milliseconds", milli); + LOQ("l", "Milliseconds", milli); return Old_NtDelayExecution(Alertable, DelayInterval); } diff --git a/hook_window.c b/hook_window.c index 4c0666a..e709e21 100644 --- a/hook_window.c +++ b/hook_window.c @@ -70,7 +70,7 @@ HOOKDEF(HWND, WINAPI, FindWindowExA, LOQ("ls", "ClassName", lpszClass, "WindowName", lpszWindow); } else { - LOQ2("ss", "ClassName", lpszClass, "WindowName", lpszWindow); + LOQ("ss", "ClassName", lpszClass, "WindowName", lpszWindow); } return ret; } @@ -89,7 +89,7 @@ HOOKDEF(HWND, WINAPI, FindWindowExW, LOQ("lu", "ClassName", lpszClass, "WindowName", lpszWindow); } else { - LOQ2("uu", "ClassName", lpszClass, "WindowName", lpszWindow); + LOQ("uu", "ClassName", lpszClass, "WindowName", lpszWindow); } return ret; } diff --git a/log.c b/log.c index 5d560d4..a2db645 100644 --- a/log.c +++ b/log.c @@ -44,6 +44,7 @@ static bson g_bson[1]; static char g_istr[4]; static char logtbl_explained[256] = {0}; +int g_log_index; // // Log API @@ -560,18 +561,3 @@ void log_free() closesocket(g_sock); } } - -int log_resolve_index(const char *funcname, int index) -{ - for (int i = 0; logtbl[i][0] != NULL; i++) { - if(!strcmp(funcname, logtbl[i][0])) { - if(index != 0) { - index--; - } - else { - return i; - } - } - } - return -1; -} diff --git a/log.h b/log.h index a87662c..45619a2 100644 --- a/log.h +++ b/log.h @@ -67,20 +67,14 @@ void log_free(); int log_resolve_index(const char *funcname, int index); extern const char *logtbl[][2]; -#define LOQ(fmt, ...) { static int _index; if(_index == 0) \ - _index = log_resolve_index(&__FUNCTION__[4], 0); loq(_index, category, \ - &__FUNCTION__[4], is_success(ret), (int) ret, fmt, ##__VA_ARGS__); } +extern int g_log_index; -#define LOQ2(fmt, ...) { static int _index; if(_index == 0) \ - _index = log_resolve_index(&__FUNCTION__[4], 1); loq(_index, category, \ - &__FUNCTION__[4], is_success(ret), (int) ret, fmt, ##__VA_ARGS__); } - -#define LOQ3(fmt, ...) { static int _index; if(_index == 0) \ - _index = log_resolve_index(&__FUNCTION__[4], 2); loq(_index, category, \ +#define LOQ(fmt, ...) { static int _index; if(_index == 0) \ + _index = ++g_log_index; loq(_index, category, \ &__FUNCTION__[4], is_success(ret), (int) ret, fmt, ##__VA_ARGS__); } #define LOQspecial(fmt, ...) { static int _index; if(_index == 0) \ - _index = log_resolve_index(&__FUNCTION__[5], 0); loq(_index, category, \ + _index = ++g_log_index; loq(_index, category, \ &__FUNCTION__[5], is_success(ret), (int) ret, fmt, ##__VA_ARGS__); } #define IS_SUCCESS_NTSTATUS() int is_success(NTSTATUS ret) { \