diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f16c9e..21c2fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,9 @@ set(INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/includes) # library - ReflectiveDLLInjection add_subdirectory(${INCLUDES}/ReflectiveDLLInjection) +include(cmake/JuiceModule.cmake) + # modules -add_subdirectory(src/core) -add_subdirectory(src/loader) -add_subdirectory(src/injector) \ No newline at end of file +add_juice_module(agent) +add_juice_module(juiceloader) +add_juice_module(injector) \ No newline at end of file diff --git a/cmake/JuiceModule.cmake b/cmake/JuiceModule.cmake new file mode 100644 index 0000000..692bfe4 --- /dev/null +++ b/cmake/JuiceModule.cmake @@ -0,0 +1,34 @@ +# JuiceModule.cmake +# Function to add a JuiceAgent module (agent, injector, juiceloader) + +function(add_juice_module NAME) + link_directories("$ENV{JAVA_HOME}/lib") + + # Collect all source files in module src and utils + file(GLOB MODULE_SOURCES + "${CMAKE_SOURCE_DIR}/src/${NAME}/*.c" + "${CMAKE_SOURCE_DIR}/src/${NAME}/utils/*.c" + ) + + # Create shared library + add_library(${NAME} SHARED ${MODULE_SOURCES}) + + # Include directories + target_include_directories(${NAME} PRIVATE + ${CMAKE_SOURCE_DIR}/includes + ${CMAKE_SOURCE_DIR}/includes/jvm + ${CMAKE_SOURCE_DIR}/includes/jvm/win32 + ${CMAKE_SOURCE_DIR}/includes/JuiceLoader + ${CMAKE_SOURCE_DIR}/includes/ReflectiveDLLInjection + "${CMAKE_SOURCE_DIR}/src/${NAME}/utils" + "${CMAKE_SOURCE_DIR}/src/${NAME}/include" + ) + + # Link common libraries + target_link_libraries(${NAME} PRIVATE + ReflectiveDLLInjection + jvm + ) + + add_subdirectory("${CMAKE_SOURCE_DIR}/src/${NAME}") +endfunction() diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt new file mode 100644 index 0000000..a018ad2 --- /dev/null +++ b/src/agent/CMakeLists.txt @@ -0,0 +1,4 @@ +# src/core/CMakeLists.txt + + +target_compile_definitions(agent PRIVATE REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR) diff --git a/src/core/libagent.c b/src/agent/libagent.c similarity index 100% rename from src/core/libagent.c rename to src/agent/libagent.c diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt deleted file mode 100644 index b64430b..0000000 --- a/src/core/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -link_directories("$ENV{JAVA_HOME}/lib") - -file(GLOB CORE_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" - "${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c" -) - -add_library(agent SHARED ${CORE_SOURCES}) - -target_include_directories(agent PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/utils - ${INCLUDES}/jvm - ${INCLUDES}/jvm/win32 - ${INCLUDES}/JuiceLoader -) - -target_compile_definitions(agent PRIVATE REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR) - -target_link_libraries(agent PRIVATE - ReflectiveDLLInjection - jvm -) diff --git a/src/injector/CMakeLists.txt b/src/injector/CMakeLists.txt index f7c3c35..71e7a1e 100644 --- a/src/injector/CMakeLists.txt +++ b/src/injector/CMakeLists.txt @@ -1,21 +1,2 @@ -link_directories("$ENV{JAVA_HOME}/lib") +# src/injector/CMakeLists.txt -file(GLOB INJECTOR_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" - "${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c" -) - -add_library(injector SHARED ${INJECTOR_SOURCES}) - -target_include_directories(injector PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/utils - ${INCLUDES}/jvm - ${INCLUDES}/jvm/win32 - ${INCLUDES}/JuiceLoader -) - -target_link_libraries(injector PRIVATE - jvm - ReflectiveDLLInjection -) diff --git a/src/juiceloader/CMakeLists.txt b/src/juiceloader/CMakeLists.txt new file mode 100644 index 0000000..8382300 --- /dev/null +++ b/src/juiceloader/CMakeLists.txt @@ -0,0 +1 @@ +# src/loader/CMakeLists.txt diff --git a/src/loader/libjuiceloader.c b/src/juiceloader/libjuiceloader.c similarity index 100% rename from src/loader/libjuiceloader.c rename to src/juiceloader/libjuiceloader.c diff --git a/src/loader/CMakeLists.txt b/src/loader/CMakeLists.txt deleted file mode 100644 index 9437bb8..0000000 --- a/src/loader/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -link_directories("$ENV{JAVA_HOME}/lib") - -file(GLOB LOADER_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/*.c" - "${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c" -) - -add_library(juiceloader SHARED ${LOADER_SOURCES}) - -target_include_directories(juiceloader PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/utils - ${INCLUDES}/jvm - ${INCLUDES}/jvm/win32 - ${INCLUDES}/JuiceLoader -) - -target_link_libraries(juiceloader PRIVATE jvm)