Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Checks: >
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-special-member-functions,
-hicpp-avoid-c-arrays,
-hicpp-signed-bitwise,
-hicpp-special-member-functions,
-misc-include-cleaner,
-misc-no-recursion,
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
run: |
echo "Checks: '-*'" > build/.clang-tidy
echo "Checks: '-*'" > vendor/zasm/.clang-tidy
echo "Checks: '-*'" > vendor/unicorn/.clang-tidy

- name: Run clang tidy
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "vendor/common"]
path = vendor/common
url = https://github.com/es3n1n/common
[submodule "vendor/unicorn"]
path = vendor/unicorn
url = https://github.com/unicorn-engine/unicorn.git
5 changes: 5 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ msvc-runtime = "static"

[options]
OBFUSCATOR_BUILD_TESTS = true
UNICORN_LEGACY_STATIC_ARCHIVE = false
BUILD_SHARED_LIBS = false

[variables]
UNICORN_ARCH = "aarch64"

[conditions]
build-tests = "OBFUSCATOR_BUILD_TESTS"
Expand Down
1 change: 1 addition & 0 deletions scripts/adjust_compile_commands.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import json
from sys import argv

Expand Down
11 changes: 11 additions & 0 deletions scripts/bytes_to_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3

buf = ''
while True:
try:
buf += input()
except (KeyboardInterrupt, EOFError):
break

data_str = ', '.join([f'0x{byte:02X}' for byte in bytes.fromhex(buf)])
print('\nconstexpr auto kData = std::to_array<std::uint8_t>({%data%});'.replace('%data%', data_str))
65 changes: 34 additions & 31 deletions src/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 20 additions & 26 deletions src/bin/entry.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
#include "config_parser/config_parser.hpp"
#include "cont/cont.hpp"
#include "obfuscator/obfuscator.hpp"
#include "obfuscator/transforms/scheduler.hpp"
#include "pe/arch/arch.hpp"
#include "pe/common/common.hpp"
#include <es3n1n/common/files.hpp>
#include <es3n1n/common/logger.hpp>
#include <es3n1n/common/random.hpp>

namespace {
template <pe::any_raw_image_t Img>
void bootstrap(Img* raw_image, config_parser::Config& config) {
pe::Image<Img> image(raw_image);

obfuscator::Instance<decltype(image)> inst(&image, config);
inst.run();

logger::info("startup: bye-bye");
}

int startup(config_parser::Config& config) try {
int startup(config_parser::Config& config) {
rnd::detail::seed(config.obfuscator_config().seed);
const auto& binary_path = config.obfuscator_config().binary_path;

Expand All @@ -28,23 +17,25 @@ namespace {
throw std::runtime_error("Got empty binary");
}

auto* img_x64 = reinterpret_cast<win::image_x64_t*>(file->data());
auto* img_x86 = reinterpret_cast<win::image_x86_t*>(img_x64);

if (!pe::common::is_valid(img_x64)) {
throw std::runtime_error("Invalid pe header");
std::unique_ptr<cont::ImageBase> image;
switch (cont::get_image_type(*file)) {
case cont::ContImageType::PE:
image = std::make_unique<cont::pe::Image>(file->data());
logger::info("main: PE image loaded");
break;
case cont::ContImageType::ELF:
image = std::make_unique<cont::elf::Image>(file->data());
logger::info("main: ELF image loaded");
break;
default:
throw std::runtime_error("Got unsupported image type");
}

if (pe::arch::is_x64(img_x64)) {
bootstrap(img_x64, config);
} else {
bootstrap(img_x86, config);
}
obfuscator::Instance inst(image.get(), config);
inst.run();

logger::info("startup: bye-bye");
return 0;
} catch (std::runtime_error& err) {
logger::critical("RUNTIME ERROR: {}", err.what());
return 1;
}
} // namespace

Expand All @@ -53,6 +44,9 @@ int main(const int argc, const char* argv[]) try {

auto config = config_parser::from_argv(argc, argv);
return startup(config);
} catch (std::exception& err) {
logger::critical("RUNTIME ERROR: {}", err.what());
return 1;
} catch (...) {
logger::critical("Unknown runtime error");
return 1;
Expand Down
5 changes: 3 additions & 2 deletions src/cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
type = "interface"
compile-features = ["cxx_std_23"]
compile-definitions = ["NOMINMAX"]
msvc.compile-options = ["/wd4661", "/MP"]
msvc.compile-options = ["/MP"]

[target.obfuscator-lib]
alias = "obfuscator::lib"
Expand All @@ -13,6 +13,7 @@ link-libraries = [
"obfuscator-project",
"zasm",
"linux-pe",
"elf",
"magic_enum",
"LLVMDemangle",
"es3n1n::common",
Expand All @@ -29,7 +30,7 @@ condition = "build-tests"
type = "executable"
sources = ["tests/**.cpp", "lib/**.hpp"]
include-directories = ["tests/"]
link-libraries = ["obfuscator-project", "obfuscator::lib", "GTest::gtest_main"]
link-libraries = ["obfuscator-project", "obfuscator::lib", "GTest::gtest_main", "unicorn"]
cmake-after = """
FetchContent_MakeAvailable(resources)
target_compile_definitions(obfuscator-tests PRIVATE OBFUSCATOR_RESOURCES_PATH="${resources_SOURCE_DIR}")
Expand Down
Loading