Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
5 files changed
+52
-125
No files matched your search
+43
-84
@@ -1,98 +1,57 @@
|
|||||||
cmake_minimum_required(VERSION 3.22)
|
cmake_minimum_required(VERSION 3.15)
|
||||||
project(VoidLoaderCore LANGUAGES CXX)
|
project(VoidLoader LANGUAGES CXX)
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Project settings
|
||||||
|
# ============================================================
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
# Options
|
# Source / includes
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
option(BUILD_LINUX "Build shared lib for Linux" ON)
|
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "src/*.cpp")
|
||||||
option(BUILD_WINDOWS "Cross-compile shared lib for Windows" ON)
|
include_directories(include)
|
||||||
set(VERSION "1.0.1")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
# Locate JDK and JNI
|
# Find JDK / JNI / JVMTI
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
|
find_package(Java REQUIRED)
|
||||||
find_package(JNI REQUIRED)
|
find_package(JNI REQUIRED)
|
||||||
|
message(STATUS "JNI include dirs: ${JNI_INCLUDE_DIRS}")
|
||||||
|
message(STATUS "JNI libs: ${JNI_LIBRARIES}")
|
||||||
|
|
||||||
if (JNI_FOUND)
|
# For JVMTI: also include JAVA_HOME/include/<os>
|
||||||
message(STATUS "✅ JNI include dirs: ${JNI_INCLUDE_DIRS}")
|
if (DEFINED ENV{JAVA_HOME})
|
||||||
include_directories(${JNI_INCLUDE_DIRS})
|
message(STATUS "JAVA_HOME: $ENV{JAVA_HOME}")
|
||||||
|
include_directories($ENV{JAVA_HOME}/include)
|
||||||
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
include_directories($ENV{JAVA_HOME}/include/win32)
|
||||||
|
else()
|
||||||
|
include_directories($ENV{JAVA_HOME}/include/linux)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# Platform flags
|
||||||
|
# ============================================================
|
||||||
|
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "❌ Could not locate JNI (ensure JAVA_HOME or JDK installed)")
|
add_compile_options(-fPIC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
# Toolchain autodetection
|
# Build shared library
|
||||||
# ----------------------------------------------------------
|
# ============================================================
|
||||||
find_program(GCC_PATH g++)
|
add_library(${PROJECT_NAME} SHARED ${SOURCES})
|
||||||
find_program(MINGW_PATH x86_64-w64-mingw32-g++)
|
|
||||||
|
|
||||||
message(STATUS "🔍 Toolchains detected:")
|
target_include_directories(${PROJECT_NAME} PRIVATE ${JNI_INCLUDE_DIRS})
|
||||||
message(STATUS " Linux → ${GCC_PATH}")
|
target_link_libraries(${PROJECT_NAME} PRIVATE ${JNI_LIBRARIES})
|
||||||
message(STATUS " Win64 → ${MINGW_PATH}")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
# Output name: YourAgent.dll / libYourAgent.so
|
||||||
# Source structure
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
# ----------------------------------------------------------
|
PREFIX ""
|
||||||
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
OUTPUT_NAME "VoidLoader"
|
||||||
include_directories("include")
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
# Linux target
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
if (BUILD_LINUX AND GCC_PATH)
|
|
||||||
add_library(VoidLoader_Linux SHARED ${SOURCES})
|
|
||||||
set_target_properties(VoidLoader_Linux PROPERTIES
|
|
||||||
OUTPUT_NAME "VoidLoader"
|
|
||||||
SUFFIX ".so"
|
|
||||||
VERSION ${VERSION}
|
|
||||||
)
|
|
||||||
target_compile_options(VoidLoader_Linux PRIVATE -O2 -Wall -fPIC)
|
|
||||||
target_include_directories(VoidLoader_Linux PRIVATE ${JNI_INCLUDE_DIRS})
|
|
||||||
target_link_libraries(VoidLoader_Linux PRIVATE ${JNI_LIBRARIES})
|
|
||||||
|
|
||||||
# Post-build: bundle dependencies
|
|
||||||
add_custom_command(TARGET VoidLoader_Linux POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -DINPUT_LIB=$<TARGET_FILE:VoidLoader_Linux>
|
|
||||||
-DOUT_DIR=$<TARGET_FILE_DIR:VoidLoader_Linux>
|
|
||||||
-P ${CMAKE_SOURCE_DIR}/cmake/bundle_linux.cmake
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
# Windows target
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
if (BUILD_WINDOWS AND MINGW_PATH)
|
|
||||||
add_library(VoidLoader_Windows SHARED ${SOURCES})
|
|
||||||
set_target_properties(VoidLoader_Windows PROPERTIES
|
|
||||||
OUTPUT_NAME "VoidLoader"
|
|
||||||
SUFFIX ".dll"
|
|
||||||
VERSION ${VERSION}
|
|
||||||
)
|
|
||||||
target_compile_options(VoidLoader_Windows PRIVATE
|
|
||||||
-O2 -Wall -static-libstdc++ -static-libgcc
|
|
||||||
)
|
|
||||||
target_include_directories(VoidLoader_Windows PRIVATE ${JNI_INCLUDE_DIRS})
|
|
||||||
|
|
||||||
add_custom_command(TARGET VoidLoader_Windows POST_BUILD
|
|
||||||
COMMAND ${CMAKE_COMMAND} -DINPUT_LIB=$<TARGET_FILE:VoidLoader_Windows>
|
|
||||||
-DOUT_DIR=$<TARGET_FILE_DIR:VoidLoader_Windows>
|
|
||||||
-P ${CMAKE_SOURCE_DIR}/cmake/bundle_windows.cmake
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
# Combined target
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
add_custom_target(buildAll
|
|
||||||
DEPENDS
|
|
||||||
$<$<BOOL:${BUILD_LINUX}>:VoidLoader_Linux>
|
|
||||||
$<$<BOOL:${BUILD_WINDOWS}>:VoidLoader_Windows>
|
|
||||||
)
|
)
|
||||||
|
|
||||||
message(STATUS "✅ Configured VoidLoader JNI agent build")
|
|
||||||
|
|
||||||
Vendored
+5
-2
@@ -4,8 +4,11 @@ pipeline {
|
|||||||
stage('Build') {
|
stage('Build') {
|
||||||
steps {
|
steps {
|
||||||
sh 'rm -rf build'
|
sh 'rm -rf build'
|
||||||
sh 'cmake -B build -S . -DBUILD_WINDOWS=ON -DBUILD_LINUX=ON'
|
sh 'mkdir build && mkdir build/linux && mkdir build/windows'
|
||||||
sh 'cmake --build build --target buildAll'
|
sh 'cmake -B build/linux -DCMAKE_BUILD_TYPE=Release'
|
||||||
|
sh 'cmake --build build/linux'
|
||||||
|
sh 'cmake -B build/windows -DCMAKE_TOOLCHAIN_FILE=mingw.cmake -DCMAKE_BUILD_TYPE=Release'
|
||||||
|
sh 'cmake --build build/windows'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
# Copy non-system dependencies using ldd
|
|
||||||
execute_process(
|
|
||||||
COMMAND ldd ${INPUT_LIB}
|
|
||||||
OUTPUT_VARIABLE LDD_OUT
|
|
||||||
)
|
|
||||||
string(REGEX MATCHALL "\t[^ ]+ => (/[^ ]+)" MATCHES "${LDD_OUT}")
|
|
||||||
|
|
||||||
foreach(M ${MATCHES})
|
|
||||||
string(REGEX REPLACE ".*=> " "" M_PATH ${M})
|
|
||||||
if (NOT "${M_PATH}" MATCHES "^/usr/lib" AND NOT "${M_PATH}" MATCHES "^/lib")
|
|
||||||
message(STATUS "📦 Copying ${M_PATH}")
|
|
||||||
file(COPY ${M_PATH} DESTINATION ${OUT_DIR})
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
# Copy referenced DLLs using objdump
|
|
||||||
execute_process(
|
|
||||||
COMMAND objdump -p ${INPUT_LIB}
|
|
||||||
OUTPUT_VARIABLE OBJDUMP_OUT
|
|
||||||
)
|
|
||||||
string(REGEX MATCHALL "DLL Name: ([A-Za-z0-9_\\.-]+)" DLLS "${OBJDUMP_OUT}")
|
|
||||||
|
|
||||||
set(MINGW_ROOTS
|
|
||||||
"/usr/x86_64-w64-mingw32/bin"
|
|
||||||
"/usr/lib/gcc/x86_64-w64-mingw32/"
|
|
||||||
)
|
|
||||||
|
|
||||||
foreach(DLL ${DLLS})
|
|
||||||
string(REGEX REPLACE "DLL Name: " "" DLL_NAME ${DLL})
|
|
||||||
foreach(ROOT ${MINGW_ROOTS})
|
|
||||||
file(GLOB CAND "${ROOT}/${DLL_NAME}")
|
|
||||||
if (CAND)
|
|
||||||
message(STATUS "📦 Copying ${CAND}")
|
|
||||||
file(COPY ${CAND} DESTINATION ${OUT_DIR})
|
|
||||||
break()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
set(CMAKE_SYSTEM_NAME Windows)
|
||||||
|
set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
|
||||||
|
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
|
||||||
|
set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||||
Reference in new issue
Block a user