Skip to content

Commit b6a3e95

Browse files
authored
Linux embedding tools (#15)
* linux support for encoder and generator * bump lz4 to 1.10.0 * fix compilation under MSVC * fix typos * add linux build to github actions
1 parent 7f8fe55 commit b6a3e95

File tree

11 files changed

+375
-279
lines changed

11 files changed

+375
-279
lines changed

.github/workflows/publish.yml

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- v*
1010

1111
jobs:
12-
build:
12+
build-windows:
1313
runs-on: windows-latest
1414
steps:
1515
- name: Checkout
@@ -24,10 +24,51 @@ jobs:
2424
configurePreset: x64-windows
2525
buildPreset: Release
2626

27+
- name: Upload artifacts
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: fumo-windows
31+
path: build/bin/Release/*
32+
if-no-files-found: error
33+
retention-days: 1
34+
35+
build-linux:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: Install CMake
42+
uses: lukka/get-cmake@latest
43+
44+
- name: Build
45+
uses: lukka/run-cmake@v10
46+
with:
47+
configurePreset: linux-embedding-tools
48+
buildPreset: Linux Embedding Tools
49+
50+
- name: Upload artifacts
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: fumo-linux
54+
path: build/bin/*
55+
if-no-files-found: error
56+
retention-days: 1
57+
58+
publish:
59+
runs-on: ubuntu-latest
60+
needs: [build-windows, build-linux]
61+
steps:
62+
- name: Download artifacts
63+
uses: actions/download-artifact@v4
64+
with:
65+
pattern: fumo-*
66+
merge-multiple: true
67+
2768
- name: ZIP embedding tools
28-
working-directory: build/bin/Release
2969
run: |
3070
7z a -tzip -mx=9 -r embedding_tools.zip fumo_encoder.exe fumo_generator.exe initial_loader.bin stage1.dll
71+
7z a -tzip -mx=9 -r embedding_tools_linux.zip fumo_encoder fumo_generator initial_loader.bin stage1.dll
3172
3273
- name: Publish release (version tag)
3374
if: startsWith(github.ref, 'refs/tags/v')
@@ -37,9 +78,10 @@ jobs:
3778
prerelease: false
3879
draft: true
3980
files: |
40-
build/bin/Release/fumo.exe
41-
build/bin/Release/fumo_encoder.exe
42-
build/bin/Release/embedding_tools.zip
81+
fumo.exe
82+
fumo_encoder.exe
83+
embedding_tools.zip
84+
embedding_tools_linux.zip
4385
4486
- name: Publish pre-release (push to master)
4587
if: github.ref == 'refs/heads/master'
@@ -50,6 +92,7 @@ jobs:
5092
title: Development build
5193
prerelease: true
5294
files: |
53-
build/bin/Release/fumo.exe
54-
build/bin/Release/fumo_encoder.exe
55-
build/bin/Release/embedding_tools.zip
95+
fumo.exe
96+
fumo_encoder.exe
97+
embedding_tools.zip
98+
embedding_tools_linux.zip

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ include(cmake/CPM.cmake)
1717
set(FUMO_DRIVER_DEBUG OFF CACHE BOOL "Enable driver debug logs/force reload")
1818
set(FUMO_DEBUG OFF CACHE BOOL "Disable creating new executables")
1919

20+
if (FUMO_DEBUG)
21+
add_compile_definitions(FUMO_DEBUG)
22+
endif()
23+
2024
add_subdirectory(src)

CMakePresets.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626
"FUMO_DEBUG": "ON",
2727
"FUMO_DRIVER_DEBUG": "ON"
2828
}
29+
},
30+
{
31+
"name": "linux-embedding-tools",
32+
"binaryDir": "${sourceDir}/build",
33+
"generator": "Ninja",
34+
"architecture": {
35+
"value": "x64",
36+
"strategy": "external"
37+
},
38+
"cacheVariables": {
39+
"FUMO_DEBUG": "OFF",
40+
"FUMO_DRIVER_DEBUG": "OFF"
41+
}
2942
}
3043
],
3144
"buildPresets": [
@@ -38,6 +51,11 @@
3851
"name": "Debug",
3952
"configurePreset": "x64-windows-debug",
4053
"configuration": "Release"
54+
},
55+
{
56+
"name": "Linux Embedding Tools",
57+
"configurePreset": "linux-embedding-tools",
58+
"configuration": "Release"
4159
}
4260
]
4361
}

cmake/CPM.cmake

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
set(CPM_DOWNLOAD_VERSION 0.38.2)
1+
# SPDX-License-Identifier: MIT
2+
#
3+
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
4+
5+
set(CPM_DOWNLOAD_VERSION 0.40.4)
6+
set(CPM_HASH_SUM "67dcc1deb6e12a2f0705647ccc5f7023e3d15746b944e14352b82373e09b8a0a")
27

38
if(CPM_SOURCE_CACHE)
4-
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
9+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
510
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
6-
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
11+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
712
else()
8-
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
13+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
914
endif()
1015

1116
# Expand relative path. This is important if the provided path contains a tilde (~)
1217
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
1318

14-
function(download_cpm)
15-
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
16-
file(DOWNLOAD
17-
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
18-
${CPM_DOWNLOAD_LOCATION}
19-
)
20-
endfunction()
21-
22-
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
23-
download_cpm()
24-
else()
25-
# resume download if it previously failed
26-
file(READ ${CPM_DOWNLOAD_LOCATION} check)
27-
if("${check}" STREQUAL "")
28-
download_cpm()
29-
endif()
30-
unset(check)
31-
endif()
19+
file(DOWNLOAD
20+
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
21+
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
22+
)
3223

3324
include(${CPM_DOWNLOAD_LOCATION})

src/CMakeLists.txt

Lines changed: 58 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,79 @@
11
# disable C4711, C5045, C4820 (caused by lz4)
2-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4711 /wd5045 /wd4820")
3-
4-
CPMAddPackage(
5-
NAME xorstr
6-
GITHUB_REPOSITORY JustasMasiulis/xorstr
7-
GIT_TAG master
8-
DOWNLOAD_ONLY True
9-
)
10-
11-
if (xorstr_ADDED)
12-
add_library(xorstr INTERFACE)
13-
target_include_directories(xorstr INTERFACE ${xorstr_SOURCE_DIR}/include)
14-
endif()
15-
16-
CPMAddPackage(
17-
NAME lazy_importer
18-
GITHUB_REPOSITORY JustasMasiulis/lazy_importer
19-
GIT_TAG master
20-
DOWNLOAD_ONLY True
21-
)
22-
23-
if (lazy_importer_ADDED)
24-
add_library(lazy_importer INTERFACE)
25-
target_include_directories(lazy_importer INTERFACE ${lazy_importer_SOURCE_DIR}/include)
2+
if(MSVC)
3+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4711 /wd5045 /wd4820")
264
endif()
275

286
CPMAddPackage(
297
NAME lz4
308
GITHUB_REPOSITORY lz4/lz4
31-
VERSION 1.9.4
9+
VERSION 1.10.0
3210
SOURCE_SUBDIR build/cmake
3311
OPTIONS
3412
"LZ4_BUILD_CLI OFF"
3513
"LZ4_BUILD_LEGACY_LZ4C OFF"
3614
)
3715
find_package(lz4 REQUIRED)
3816

39-
CPMAddPackage("gh:SergiusTheBest/FindWDK#master")
40-
list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
41-
find_package(WDK REQUIRED)
17+
CPMAddPackage("gh:dumbasPL/linux-pe#master")
18+
find_package(linux-pe REQUIRED)
19+
20+
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
21+
CPMAddPackage(
22+
NAME xorstr
23+
GITHUB_REPOSITORY JustasMasiulis/xorstr
24+
GIT_TAG master
25+
DOWNLOAD_ONLY True
26+
)
27+
28+
if (xorstr_ADDED)
29+
add_library(xorstr INTERFACE)
30+
target_include_directories(xorstr INTERFACE ${xorstr_SOURCE_DIR}/include)
31+
endif()
32+
33+
CPMAddPackage(
34+
NAME lazy_importer
35+
GITHUB_REPOSITORY JustasMasiulis/lazy_importer
36+
GIT_TAG master
37+
DOWNLOAD_ONLY True
38+
)
4239

43-
CPMAddPackage("gh:dumbasPL/[email protected]")
40+
if (lazy_importer_ADDED)
41+
add_library(lazy_importer INTERFACE)
42+
target_include_directories(lazy_importer INTERFACE ${lazy_importer_SOURCE_DIR}/include)
43+
endif()
4444

45-
if (FUMO_DEBUG)
46-
add_compile_definitions(FUMO_DEBUG)
45+
CPMAddPackage("gh:SergiusTheBest/FindWDK#master")
46+
list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
47+
find_package(WDK REQUIRED)
48+
49+
CPMAddPackage("gh:dumbasPL/[email protected]")
50+
51+
add_subdirectory(driver)
52+
add_subdirectory(driver_interface)
53+
add_subdirectory(resource_generator)
54+
add_subdirectory(stage1)
55+
add_subdirectory(stage2)
56+
add_subdirectory(initial_loader)
57+
add_subdirectory(shellcode_extractor)
4758
endif()
4859

49-
add_subdirectory(driver)
50-
add_subdirectory(driver_interface)
51-
add_subdirectory(resource_generator)
52-
add_subdirectory(stage1)
53-
add_subdirectory(stage2)
54-
add_subdirectory(initial_loader)
55-
add_subdirectory(shellcode_extractor)
5660
add_subdirectory(fumo_generator)
5761
add_subdirectory(encoder)
5862

59-
add_custom_command(
60-
COMMENT "building final executable"
61-
DEPENDS fumo_generator initial_loader stage1
62-
$<TARGET_PROPERTY:initial_loader,RUNTIME_OUTPUT_DIRECTORY>/initial_loader.bin
63-
$<TARGET_FILE:stage1>
64-
COMMAND fumo_generator ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
65-
$<TARGET_PROPERTY:initial_loader,RUNTIME_OUTPUT_DIRECTORY>/initial_loader.bin
66-
$<TARGET_FILE:stage1>
67-
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
68-
)
63+
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
64+
add_custom_command(
65+
COMMENT "building final executable"
66+
DEPENDS fumo_generator initial_loader stage1
67+
$<TARGET_PROPERTY:initial_loader,RUNTIME_OUTPUT_DIRECTORY>/initial_loader.bin
68+
$<TARGET_FILE:stage1>
69+
COMMAND fumo_generator ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
70+
$<TARGET_PROPERTY:initial_loader,RUNTIME_OUTPUT_DIRECTORY>/initial_loader.bin
71+
$<TARGET_FILE:stage1>
72+
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
73+
)
6974

70-
add_custom_target(
71-
fumo ALL
72-
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
73-
)
75+
add_custom_target(
76+
fumo ALL
77+
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/fumo.exe
78+
)
79+
endif()

src/encoder/fumo_encoder.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <Windows.h>
21
#include <iostream>
32
#include <fstream>
43
#include <vector>
@@ -7,8 +6,8 @@
76
#include <filesystem>
87
#include <stdint.h>
98
#include <ctime>
10-
#include <fomo_common.h>
11-
#include <util.h>
9+
#include <random>
10+
#include <fumo_data_header.h>
1211
#include <lz4.h>
1312

1413
int main(int argc, char** argv) {
@@ -74,10 +73,13 @@ int main(int argc, char** argv) {
7473
compressed_data.resize(compressed_size);
7574

7675
// generate xor key
77-
std::srand(std::time(nullptr));
78-
uint64_t xor_key = 0;
79-
for (int i = 0; i < 8; i++)
80-
xor_key |= (std::rand() % 256) << (i * 8);
76+
std::random_device rd;
77+
std::mt19937 gen(rd());
78+
std::uniform_int_distribution<unsigned long long> dis(
79+
std::numeric_limits<std::uint64_t>::min(),
80+
std::numeric_limits<std::uint64_t>::max()
81+
);
82+
uint64_t xor_key = dis(gen);
8183

8284
// pad to 8 bytes
8385
int padding = 8 - (compressed_data.size() % 8);

src/fumo_generator/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_executable(fumo_generator fumo_generator.cpp)
22
target_compile_features(fumo_generator PUBLIC c_std_17 cxx_std_20)
33
target_compile_definitions(fumo_generator PRIVATE UNICODE _UNICODE)
44
target_include_directories(fumo_generator PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
5+
target_link_libraries(fumo_generator PRIVATE linux-pe)

0 commit comments

Comments
 (0)