From 917dc888262d49c8e6cf84ac93b838ae55206bdd Mon Sep 17 00:00:00 2001 From: icex2 Date: Wed, 2 Sep 2020 21:28:35 +0200 Subject: [PATCH] util/log: Remove log_error, replace occurances with log_warning log_error was using the log_writer_fatal impl which conflicts with how this is used on AVS. Therefore, achieve a visible "error" message in inject by using log_warning + ERROR string in the message --- src/main/inject/debugger.c | 50 +++++++++++++++++++------------------- src/main/inject/logger.c | 4 +-- src/main/inject/main.c | 8 +++--- src/main/util/log.h | 2 -- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/main/inject/debugger.c b/src/main/inject/debugger.c index 63e2a00..8319594 100644 --- a/src/main/inject/debugger.c +++ b/src/main/inject/debugger.c @@ -122,8 +122,8 @@ read_debug_str(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) } else { free(str); - log_error( - "ReadProcessMemory for debug string failed: %08x", + log_warning( + "ERROR: ReadProcessMemory for debug string failed: %08x", (unsigned int) GetLastError()); str = NULL; } @@ -149,12 +149,12 @@ read_debug_wstr(HANDLE process, const OUTPUT_DEBUG_STRING_INFO *odsi) if (wstr_narrow(wstr, &str)) { str[odsi->nDebugStringLength - 1] = '\0'; } else { - log_error("OutputDebugStringW: UTF-16 conversion failed"); + log_warning("ERROR: OutputDebugStringW: UTF-16 conversion failed"); str = NULL; } } else { - log_error( - "ReadProcessMemory for debug string failed: %08x", + log_warning( + "ERROR: ReadProcessMemory for debug string failed: %08x", (unsigned int) GetLastError()); str = NULL; } @@ -221,8 +221,8 @@ static bool debugger_create_process( app_name, cmd_line, NULL, NULL, FALSE, flags, NULL, NULL, &si, &pi); if (!ok) { - log_error( - "Failed to launch hooked EXE: %08x", (unsigned int) GetLastError()); + log_warning( + "ERRPR: Failed to launch hooked EXE: %08x", (unsigned int) GetLastError()); free(cmd_line); @@ -246,8 +246,8 @@ static bool debugger_loop() for (;;) { if (!WaitForDebugEvent(&de, INFINITE)) { - log_error( - "WaitForDebugEvent failed: %08x", + log_warning( + "ERROR: WaitForDebugEvent failed: %08x", (unsigned int) GetLastError()); return false; } @@ -364,8 +364,8 @@ static bool debugger_loop() if (!ContinueDebugEvent( de.dwProcessId, de.dwThreadId, continue_status)) { - log_error( - "ContinueDebugEvent failed: %08x", + log_warning( + "ERROR: ContinueDebugEvent failed: %08x", (unsigned int) GetLastError()); return false; } @@ -410,8 +410,8 @@ bool debugger_init(bool local_debugger, const char *app_name, char *cmd_line) if (!debugger_ready_event) { free(cmd_line); - log_error( - "Creating event object failed: %08x", + log_warning( + "ERROR: Creating event object failed: %08x", (unsigned int) GetLastError()); return false; } @@ -430,8 +430,8 @@ bool debugger_init(bool local_debugger, const char *app_name, char *cmd_line) free(cmd_line); free(thread_params); - log_error( - "Creating debugger thread failed: %08x", + log_warning( + "ERROR: Creating debugger thread failed: %08x", (unsigned int) GetLastError()); return false; } @@ -453,8 +453,8 @@ bool debugger_wait_for_remote_debugger() res = FALSE; if (!CheckRemoteDebuggerPresent(pi.hProcess, &res)) { - log_error( - "CheckRemoteDebuggerPresent failed: %08x", + log_warning( + "ERROR: CheckRemoteDebuggerPresent failed: %08x", (unsigned int) GetLastError()); return false; } @@ -495,7 +495,7 @@ bool debugger_inject_dll(const char *path_dll) PAGE_READWRITE); if (!remote_addr) { - log_error("VirtualAllocEx failed: %08x", (unsigned int) GetLastError()); + log_warning("ERROR: VirtualAllocEx failed: %08x", (unsigned int) GetLastError()); goto alloc_fail; } @@ -504,8 +504,8 @@ bool debugger_inject_dll(const char *path_dll) pi.hProcess, remote_addr, dll_path, dll_path_length, NULL); if (!ok) { - log_error( - "WriteProcessMemory failed: %08x", (unsigned int) GetLastError()); + log_warning( + "ERROR: WriteProcessMemory failed: %08x", (unsigned int) GetLastError()); goto write_fail; } @@ -520,8 +520,8 @@ bool debugger_inject_dll(const char *path_dll) NULL); if (remote_thread == NULL) { - log_error( - "CreateRemoteThread failed: %08x", (unsigned int) GetLastError()); + log_warning( + "ERROR: CreateRemoteThread failed: %08x", (unsigned int) GetLastError()); goto inject_fail; } @@ -533,7 +533,7 @@ bool debugger_inject_dll(const char *path_dll) remote_addr = NULL; if (!ok) { - log_error("VirtualFreeEx failed: %08x", (unsigned int) GetLastError()); + log_warning("ERROR: VirtualFreeEx failed: %08x", (unsigned int) GetLastError()); } return true; @@ -553,8 +553,8 @@ bool debugger_resume_process() log_info("Resuming remote process..."); if (ResumeThread(pi.hThread) == -1) { - log_error( - "Error resuming remote process: %08x", + log_warning( + "ERROR: Resuming remote process: %08x", (unsigned int) GetLastError()); return false; } diff --git a/src/main/inject/logger.c b/src/main/inject/logger.c index 681ec21..72fc5dd 100644 --- a/src/main/inject/logger.c +++ b/src/main/inject/logger.c @@ -185,8 +185,8 @@ bool logger_init(const char *log_file_path) log_info("Log file: %s", log_file_path); if (!log_file) { - log_error( - "Opening log file %s failed: %s", + log_warning( + "ERROR: Opening log file %s failed: %s", log_file_path, strerror(errno)); return false; diff --git a/src/main/inject/main.c b/src/main/inject/main.c index c057493..2ad0990 100644 --- a/src/main/inject/main.c +++ b/src/main/inject/main.c @@ -54,12 +54,12 @@ static bool verify_hook_dll_and_exec_args_and_count_hooks( } if (!(*hooks)) { - log_error("No Hook DLL(s) specified before executable"); + log_warning("ERROR: No Hook DLL(s) specified before executable"); return false; } if (!*exec_arg_pos) { - log_error("No executable specified"); + log_warning("ERROR: No executable specified"); return false; } @@ -83,8 +83,8 @@ verify_hook_dlls_exist(int argc, char **argv, uint32_t hook_dll_count) SearchPath(NULL, argv[i + 1], NULL, MAX_PATH, dll_path, NULL); if (dll_path_length == 0) { - log_error( - "Hook DLL not found: %08x", (unsigned int) GetLastError()); + log_warning( + "ERROR: Hook DLL not found: %08x", (unsigned int) GetLastError()); return false; } diff --git a/src/main/util/log.h b/src/main/util/log.h index 6bc34f1..a60cdb7 100644 --- a/src/main/util/log.h +++ b/src/main/util/log.h @@ -22,7 +22,6 @@ #define log_misc(...) log_impl_misc(LOG_MODULE, __VA_ARGS__) #define log_info(...) log_impl_info(LOG_MODULE, __VA_ARGS__) #define log_warning(...) log_impl_warning(LOG_MODULE, __VA_ARGS__) -#define log_error(...) log_impl_fatal(LOG_MODULE, __VA_ARGS__) /* This doesn't really belong here, but it's what libavs does so w/e */ @@ -38,7 +37,6 @@ #define log_misc(...) #define log_info(...) #define log_warning(...) -#define log_error(...) #define log_assert(x) \ do { \ if (!(x)) { \