From 233dd384f6bdb4bb6b09f6bec9ed77d0692c43fe Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Tue, 28 Oct 2025 18:36:54 +0000 Subject: [PATCH] [Add] Obfuscate executable file content. --- common/src/lua_api.cpp | 3 ++- common/src/machine_manager.cpp | 3 ++- common/src/session.cpp | 5 +++-- common/src/util.cpp | 14 ++++++++++++++ common/src/util.h | 6 ++++++ 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 common/src/util.cpp create mode 100644 common/src/util.h diff --git a/common/src/lua_api.cpp b/common/src/lua_api.cpp index 47fe9bf..84e0c32 100644 --- a/common/src/lua_api.cpp +++ b/common/src/lua_api.cpp @@ -7,6 +7,7 @@ #include "session.h" #include "machine.h" #include "vfs.h" +#include "util.h" namespace api { @@ -117,7 +118,7 @@ std::string create_executable(Session& context, const std::string& path, parent_dir->children.erase(it); } vfs_node* new_exec = new_node(filename, EXEC_NODE, parent_dir); - new_exec->content = content; + new_exec->content = util::xor_string(content); parent_dir->children[filename] = new_exec; return ""; } diff --git a/common/src/machine_manager.cpp b/common/src/machine_manager.cpp index c4267ce..e7cc33b 100644 --- a/common/src/machine_manager.cpp +++ b/common/src/machine_manager.cpp @@ -7,6 +7,7 @@ #include "machine_manager.h" #include "machine.h" #include "vfs.h" +#include "util.h" vfs_node* copy_vfs_node(vfs_node* original, vfs_node* new_parent) { if(!original) { @@ -42,7 +43,7 @@ MachineManager::MachineManager(DatabaseManager* db_manager) : std::string filename_with_ext = entry.path().filename().string(); std::string filename = filename_with_ext.substr(0, filename_with_ext.find_last_of('.')); vfs_node* script_node = new_node(filename, EXEC_NODE, bin); - script_node->content = buffer.str(); + script_node->content = util::xor_string(buffer.str()); bin->children[filename] = script_node; fprintf(stderr, "Loaded executable: /bin/%s\n", filename.c_str()); } diff --git a/common/src/session.cpp b/common/src/session.cpp index 3bb1e32..a47a01f 100644 --- a/common/src/session.cpp +++ b/common/src/session.cpp @@ -8,7 +8,7 @@ #include "lua_processor.h" #include "machine.h" #include "vfs.h" - +#include "util.h" vfs_node* find_node_by_id(vfs_node* root, long long id) { if(root->id == id) { @@ -113,7 +113,8 @@ std::string Session::process_command(const std::string& command) { if(command_node) { if(command_node->type == EXEC_NODE) { bool is_remote = (_session_machine != _home_machine); - sol::object result = lua.execute(command_node->content, *this, args, is_remote); + std::string deobfuscated_content = util::xor_string(command_node->content); + sol::object result = lua.execute(deobfuscated_content, *this, args, is_remote); return result.is() ? result.as() : "[Script returned non-string value]"; } else if(command_node->type == DIR_NODE) { diff --git a/common/src/util.cpp b/common/src/util.cpp new file mode 100644 index 0000000..7ce0626 --- /dev/null +++ b/common/src/util.cpp @@ -0,0 +1,14 @@ +#include "util.h" + +namespace util { + +std::string xor_string(const std::string& data) { + std::string result = data; + char key = 'B'; + for(size_t i = 0; i < data.size(); ++i) { + result[i] = data[i] ^ key; + } + return result; +} + +} diff --git a/common/src/util.h b/common/src/util.h new file mode 100644 index 0000000..d984eec --- /dev/null +++ b/common/src/util.h @@ -0,0 +1,6 @@ +#pragma once +#include + +namespace util { + std::string xor_string(const std::string& data); +}