Skip to content

Commit 541ea2e

Browse files
committed
fix: skip loader test on macOS, add signal recovery
0 parents  commit 541ea2e

37 files changed

Lines changed: 5368 additions & 0 deletions

‎.clang-format‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# .clang-format
2+
BasedOnStyle: LLVM
3+
IndentWidth: 4
4+
UseTab: Never
5+
BreakBeforeBraces: Attach
6+
AllowShortIfStatementsOnASingleLine: false
7+
AllowShortFunctionsOnASingleLine: None
8+
ColumnLimit: 100
9+
PointerAlignment: Right
10+
SpaceAfterCStyleCast: true
11+
AlignConsecutiveAssignments: true
12+
AlignConsecutiveDeclarations: true
13+
SortIncludes: true

‎.github/workflows/build.yml‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# =============================================================================
2+
# Shellcode Executor - CI/CD 构建与测试流水线
3+
# Shellcode Executor - CI/CD Build & Test Pipeline
4+
# =============================================================================
5+
6+
name: Build & Test
7+
8+
on:
9+
push:
10+
branches: [main, master]
11+
paths-ignore:
12+
- "docs/**"
13+
- "**.md"
14+
- "**.txt"
15+
pull_request:
16+
branches: [main, master]
17+
18+
# 取消重复的正在运行的构建 / Cancel duplicate in-progress builds
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
env:
24+
BUILD_TYPE: Release
25+
26+
jobs:
27+
# ─────────────────────────────────────────────────────────
28+
# 代码质量检查 / Code Quality
29+
# ─────────────────────────────────────────────────────────
30+
code-quality:
31+
name: Code Quality
32+
runs-on: ubuntu-latest
33+
continue-on-error: true # 不阻塞 PR / Don't block PR
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Install Tools
38+
run: |
39+
sudo apt-get update -qq
40+
sudo apt-get install -y -qq cppcheck clang-format 2>/dev/null || true
41+
42+
- name: Static Analysis (cppcheck)
43+
continue-on-error: true
44+
run: |
45+
if command -v cppcheck &>/dev/null; then
46+
cppcheck --version
47+
cppcheck --enable=warning,style,performance,portability \
48+
--suppress=missingIncludeSystem \
49+
--suppress=unmatchedSuppression \
50+
--error-exitcode=0 \
51+
src/ tests/ examples/ 2>&1 || true
52+
fi
53+
echo "cppcheck check completed (non-fatal)"
54+
55+
- name: Formatting Check (clang-format)
56+
continue-on-error: true
57+
run: |
58+
if command -v clang-format &>/dev/null; then
59+
find src/ tests/ examples/ -name "*.c" -o -name "*.h" | \
60+
xargs clang-format --dry-run -Werror 2>&1 || \
61+
echo "clang-format: formatting suggestions available (non-fatal)"
62+
else
63+
echo "clang-format not available, skipping"
64+
fi
65+
66+
# ─────────────────────────────────────────────────────────
67+
# 多平台编译矩阵 / Multi-platform Build Matrix
68+
# ─────────────────────────────────────────────────────────
69+
build:
70+
name: ${{ matrix.os }} (${{ matrix.cc }}, ${{ matrix.build_type }})
71+
needs: [code-quality]
72+
runs-on: ${{ matrix.os }}
73+
strategy:
74+
fail-fast: false # 一个失败不取消其他 / Don't cancel other jobs
75+
matrix:
76+
os: [ubuntu-latest, macos-latest]
77+
cc: [gcc, clang]
78+
build_type: [Debug, Release]
79+
exclude:
80+
# macOS 默认是 clang,跳过 gcc 以节省资源
81+
- os: macos-latest
82+
cc: gcc
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Install Dependencies (Linux)
88+
if: runner.os == 'Linux'
89+
run: |
90+
sudo apt-get update -qq
91+
sudo apt-get install -y -qq cmake build-essential clang 2>/dev/null || true
92+
93+
- name: Install Dependencies (macOS)
94+
if: runner.os == 'macOS'
95+
run: |
96+
echo "macOS tools pre-installed"
97+
cmake --version
98+
which make
99+
100+
- name: Configure CMake
101+
run: |
102+
cmake -B build -G "Unix Makefiles" \
103+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
104+
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
105+
-DENABLE_TESTS=ON \
106+
-DENABLE_EXAMPLES=ON \
107+
-DENABLE_ASAN=OFF \
108+
-Wno-dev
109+
echo "--- CMake Cache: ENABLE_TESTS ---"
110+
grep -E "ENABLE_TESTS|WITH_REMOTE" build/CMakeCache.txt || true
111+
112+
- name: Build All (verbose on failure)
113+
run: |
114+
JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)
115+
cmake --build build -j${JOBS} 2>&1 || {
116+
echo "=== First build attempt failed, retrying with VERBOSE ==="
117+
cmake --build build -j1 --verbose 2>&1
118+
exit 1
119+
}
120+
121+
- name: List Built Artifacts
122+
run: |
123+
echo "=== Build directory structure ==="
124+
find build -name "test_*" -o -name "scloader*" 2>/dev/null | sort
125+
echo "=== tests/ directory ==="
126+
ls -la build/tests/ 2>/dev/null || echo "(no tests dir)"
127+
echo "=== bin/ directory ==="
128+
ls -la build/bin/ 2>/dev/null || echo "(no bin dir)"
129+
130+
- name: Run Tests
131+
run: |
132+
cd build
133+
ctest --output-on-failure --timeout 30 -V 2>&1

‎.gitignore‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ── Build Artifacts ──
2+
build/
3+
bin/
4+
obj/
5+
lib/
6+
7+
# ── IDE Files ──
8+
.vscode/
9+
.idea/
10+
*.swp
11+
*.swo
12+
*~
13+
14+
# ── OS Files ──
15+
.DS_Store
16+
Thumbs.db
17+
18+
# ── Coverage ──
19+
coverage/
20+
*.gcda
21+
*.gcno
22+
*.gcov
23+
24+
# ── Documentation ──
25+
docs/html/
26+
docs/latex/
27+
28+
# ── Compiled Objects ──
29+
*.o
30+
*.a
31+
*.so
32+
*.dylib
33+
*.dll
34+
*.exe
35+
36+
# ── CMake ──
37+
CMakeCache.txt
38+
CMakeFiles/
39+
cmake_install.cmake
40+
compile_commands.json
41+
42+
# ── Python ──
43+
__pycache__/
44+
*.pyc
45+
*.pyo
46+
47+
# ── Temp Files ──
48+
*.tmp
49+
*.bak
50+
*.log

‎CMakeLists.txt‎

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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

Comments
 (0)