1+ cmake_minimum_required (VERSION 3.20 )
2+ project (shellcode-executor
3+ VERSION 2.0.2
4+ DESCRIPTION "跨平台 Shellcode 执行器与漏洞利用框架 / Cross-Platform Shellcode Executor & Exploitation Framework"
5+ LANGUAGES C
6+ )
7+
8+ # ──────────────────────────────────────────────
9+ # 项目选项 / Project Options
10+ # ──────────────────────────────────────────────
11+ option (BUILD_SHARED_LIBS "Build shared libraries" OFF )
12+ option (ENABLE_TESTS "Build unit tests" ON )
13+ option (ENABLE_EXAMPLES "Build example programs" ON )
14+ option (ENABLE_ASAN "Enable AddressSanitizer" OFF )
15+ option (ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF )
16+ option (ENABLE_STATIC_ANALYSIS "Enable Clang-Tidy static analysis" OFF )
17+ option (ENABLE_COVERAGE "Enable code coverage instrumentation" OFF )
18+ option (WITH_ENCRYPTION "Enable encryption module (OpenSSL)" OFF )
19+ option (WITH_REMOTE "Enable remote shellcode fetch module" ON )
20+
21+ # ──────────────────────────────────────────────
22+ # C Standard & Compiler Settings
23+ # ──────────────────────────────────────────────
24+ set (CMAKE_C_STANDARD 11)
25+ set (CMAKE_C_STANDARD_REQUIRED ON )
26+ set (CMAKE_C_EXTENSIONS OFF )
27+
28+ if (MSVC )
29+ add_compile_options (/W4 /utf-8 /MP )
30+ set (CMAKE_C_FLAGS_RELEASE "/O2 /GL /GS-" )
31+ set (CMAKE_C_FLAGS_DEBUG "/Od /RTC1" )
32+ else ()
33+ add_compile_options (-Wall -Wextra -Wpedantic -Wshadow -Wstrict-prototypes )
34+ add_compile_options (-Wmissing-prototypes -Wconversion -Wformat=2 )
35+
36+ set (CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG" )
37+ set (CMAKE_C_FLAGS_DEBUG "-O0 -g3" )
38+
39+ if (ENABLE_ASAN)
40+ add_compile_options (-fsanitize=address -fno-omit-frame-pointer )
41+ add_link_options (-fsanitize=address )
42+ endif ()
43+ if (ENABLE_UBSAN)
44+ add_compile_options (-fsanitize=undefined )
45+ add_link_options (-fsanitize=undefined )
46+ endif ()
47+ if (ENABLE_COVERAGE)
48+ add_compile_options (--coverage )
49+ add_link_options (--coverage )
50+ endif ()
51+ endif ()
52+
53+ # ──────────────────────────────────────────────
54+ # Platform Detection
55+ # ──────────────────────────────────────────────
56+ if (WIN32 )
57+ add_definitions (-DPLATFORM_WINDOWS=1 )
58+ set (PLATFORM_LIBS ws2_32)
59+ elseif (APPLE )
60+ add_definitions (-DPLATFORM_MACOS=1 )
61+ set (PLATFORM_LIBS)
62+ else ()
63+ add_definitions (-DPLATFORM_LINUX=1 )
64+ set (PLATFORM_LIBS dl)
65+ endif ()
66+
67+ # ──────────────────────────────────────────────
68+ # Include Directories
69+ # ──────────────────────────────────────────────
70+ include_directories (${CMAKE_SOURCE_DIR } /src )
71+
72+ # ──────────────────────────────────────────────
73+ # Source Files
74+ # ──────────────────────────────────────────────
75+ set (LOADER_SRC
76+ src/loader/loader.c
77+ )
78+
79+ set (ENCODER_SRC
80+ src/encoder/encoder.c
81+ src/encoder/xor.c
82+ src/encoder/base64.c
83+ )
84+
85+ set (UTILS_SRC
86+ src/utils/utils.c
87+ src/utils/hex.c
88+ src/utils/memory_info.c
89+ )
90+
91+ set (REMOTE_SRC
92+ src/remote/remote.c
93+ )
94+
95+ set (CRYPTO_SRC
96+ src/crypto/crypto.c
97+ )
98+
99+ # ──────────────────────────────────────────────
100+ # Core Static Library
101+ # ──────────────────────────────────────────────
102+ add_library (scloader STATIC
103+ ${LOADER_SRC}
104+ ${ENCODER_SRC}
105+ ${UTILS_SRC}
106+ ${REMOTE_SRC}
107+ ${CRYPTO_SRC}
108+ )
109+
110+ target_include_directories (scloader PUBLIC ${CMAKE_SOURCE_DIR } /src )
111+
112+ if (WITH_ENCRYPTION)
113+ find_package (OpenSSL REQUIRED )
114+ target_link_libraries (scloader PUBLIC OpenSSL::Crypto )
115+ target_compile_definitions (scloader PRIVATE WITH_ENCRYPTION=1 )
116+ endif ()
117+
118+ if (WITH_REMOTE AND WIN32 )
119+ target_link_libraries (scloader PUBLIC ${PLATFORM_LIBS} )
120+ endif ()
121+
122+ # ──────────────────────────────────────────────
123+ # Main Executable
124+ # ──────────────────────────────────────────────
125+ add_executable (scloader-cli src/main.c )
126+ target_link_libraries (scloader-cli PRIVATE scloader )
127+
128+ # ──────────────────────────────────────────────
129+ # Examples
130+ # ──────────────────────────────────────────────
131+ if (ENABLE_EXAMPLES)
132+ add_subdirectory (examples )
133+ endif ()
134+
135+ # ──────────────────────────────────────────────
136+ # Tests
137+ # ──────────────────────────────────────────────
138+ if (ENABLE_TESTS)
139+ enable_testing ()
140+ add_subdirectory (tests )
141+ endif ()
142+
143+ # ──────────────────────────────────────────────
144+ # Install
145+ # ──────────────────────────────────────────────
146+ install (TARGETS scloader scloader-cli
147+ RUNTIME DESTINATION bin
148+ LIBRARY DESTINATION lib
149+ ARCHIVE DESTINATION lib
150+ )
151+ install (DIRECTORY src/ DESTINATION include
152+ FILES_MATCHING PATTERN "*.h"
153+ )
154+
155+ # ──────────────────────────────────────────────
156+ # Custom Targets
157+ # ──────────────────────────────────────────────
158+ if (ENABLE_STATIC_ANALYSIS AND NOT MSVC )
159+ find_program (CLANG_TIDY NAMES clang-tidy )
160+ if (CLANG_TIDY)
161+ set (CMAKE_C_CLANG_TIDY ${CLANG_TIDY}
162+ -checks=clang-analyzer-*,bugprone-*,performance-*
163+ )
164+ endif ()
165+ endif ()
0 commit comments