Skip to content

Commit

Permalink
automatically assign log indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jbremer committed Jul 18, 2014
1 parent 8af6ec4 commit 82fcda6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 37 deletions.
2 changes: 1 addition & 1 deletion hook_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
/*
Expand Down
12 changes: 6 additions & 6 deletions hook_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions hook_reg_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion hook_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions hook_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
16 changes: 1 addition & 15 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
14 changes: 4 additions & 10 deletions log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down

0 comments on commit 82fcda6

Please sign in to comment.