From f7427703112d15420e3cfd1a601f54289d409ca2 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Nov 2026 15:12:07 +0800 Subject: [PATCH] =?UTF-8?q?build(linux):=20=E8=AE=A9=20Core/SDK/Console=20?= =?UTF-8?q?=E5=9C=A8=20Linux=20=E4=B8=8A=E6=8C=89=E9=A1=BA=E5=BA=8F?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E7=BC=96=E8=AF=91=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core/precompiled.h: sys/sysctl.h 用 __APPLE__ 包住 - runtime/crypto.h: 自定义 __rdtsc 与 clang 内建冲突 → vmp_rdtsc + 宏转发 - core/core.cc: OutputDebugStringA 条件编译;OpenSSL3 用 RSA_get0_key 取 n/e/d - runtime/precompiled.h / core/intel.cc / core/processors.cc: 在 Linux 走 - core/objects.cc: 补 (PCH 同步) - core/pefile.cc: MSVC union 写法改直接成员名(UnwindInfoAddress / Characteristics) - lin_common.mak: 去掉 -Werror;加 .DEFAULT_GOAL := all(原来默认目标是 clean) - VMProtectCon/lin_console.mak: -lcrypto -lz 替代静态 libcrypto.a;-no-pie(预编译 libffi 非 PIE);--allow-multiple-definition(strlcpy 与 glibc 重名) - BUILD-LINUX.md: 依赖、构建顺序、10 处改动原因、能力边界、授权提示 实测:Debian 13 + clang 19,四条 make 依次通过,产出 bin/64/release/vmprotect_con (41MB),对 /bin/true、/bin/echo 与一个 PE32+ 产物 分别加壳成功(Load/Compile/Save/Pack/startup code 全跑完)。 --- .gitignore | 4 +++ BUILD-LINUX.md | 70 ++++++++++++++++++++++++++++++++++++ VMProtectCon/lin_console.mak | 6 ++-- core/core.cc | 18 ++++++---- core/intel.cc | 4 +++ core/objects.cc | 1 + core/pefile.cc | 8 ++--- core/precompiled.h | 3 ++ core/processors.cc | 4 +++ lin_common.mak | 5 +-- runtime/crypto.h | 3 +- runtime/precompiled.h | 4 +++ 12 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 BUILD-LINUX.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6f4e001 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/bin/ +/tmp/ +*.o +*.gch diff --git a/BUILD-LINUX.md b/BUILD-LINUX.md new file mode 100644 index 0000000..4a99083 --- /dev/null +++ b/BUILD-LINUX.md @@ -0,0 +1,70 @@ +# 在 Linux 上编译 VMProtect(Console / Core / SDK / Runtime) + +本文件记录在 **Debian 13 + clang 19** 上把本仓库的 Linux 目标(`-target x86_64-linux-gnu`)编译通过所需的最小改动。 +所有改动已在 `linux-build` 分支上,直接按下面顺序构建即可,不再需要手工补参数。 + +## 依赖 + +```bash +apt-get install -y clang make libssl-dev zlib1g-dev +``` + +`third-party/libffi/libffi64.a` 是仓库自带预编译库,直接用。 + +## 构建顺序(必须按这个顺序,后者依赖前者的产物) + +```bash +cd core/invariant && make -f lin_invariant_core64.mak CFG_DIR=release # → bin/64/invariant_core.a +cd ../../core && make -f lin_core64.mak CFG_DIR=release # → bin/64/release/core.a(约 70MB) +cd ../sdk && make -f lin_sdk64.mak CFG_DIR=release # → bin/libVMProtectSDK64.so +cd ../VMProtectCon && make -f lin_console64.mak CFG_DIR=release # → bin/64/release/vmprotect_con +``` + +运行: + +```bash +LD_LIBRARY_PATH=$PWD/bin ./bin/64/release/vmprotect_con +# VMProtect Professional v 3.5.1 (build 1024) +# Usage: vmprotect_con File [Output File] [-pf Project File] [-sf Script File] [-wm Watermark] [-we] +``` + +加壳(一份 CLI 同时吃 PE / ELF / Mach-O,取决于是哪种文件): + +```bash +/vmprotect_con input.bin output.bin [-pf project.vmp] [-sf script.lua] +``` + +## 为 Linux 编译修掉的 10 个问题 + +| # | 文件 | 问题 | 处理 | +|---|------|------|------| +| 1 | `core/precompiled.h` | 无条件 `#include `(macOS 头) | 用 `#ifdef __APPLE__` 包住 | +| 2 | `lin_common.mak` | `-Werror` 撞 clang19 的 deprecated 警告(`auto_ptr`/`RSA_*`) | 去掉 `-Werror` | +| 3 | `runtime/crypto.h` | 自定义 `__rdtsc()` 与 clang 内建同名不同返回类型 | 改名 `vmp_rdtsc` + `#define __rdtsc() vmp_rdtsc()` | +| 4 | `core/core.cc` | `OutputDebugStringA` 是 Win32 API | `#ifdef _WIN32` 条件编译 | +| 5 | `core/core.cc` | OpenSSL 3 里 `rsa_st` 是残缺类型,`r->n/e/d` 编译失败 | 改 `RSA_get0_key(r, &n, &e, &d)` | +| 6 | `runtime/precompiled.h`、`core/intel.cc`、`core/processors.cc` | `#include `(MSVC 头) | Linux 走 `#include ` | +| 7 | `core/objects.cc` | 用了 `va_start/va_end` 但缺 `` | 补 include(PCH 里也补一份) | +| 8 | `core/pefile.cc` | MSVC union 写法 `data.u.UnwindData` / `tls.u.Characteristics` | 改成 `data.UnwindInfoAddress` / `tls.Characteristics` | +| 9 | 各 `*.mak` | 默认目标指向 `clean`,`make -f xxx.mak` 会清空产物 | `lin_common.mak` 加 `.DEFAULT_GOAL := all` | +| 10 | `VMProtectCon/lin_console.mak` | 链接静态 `libcrypto.a` 牵出 zlib/zstd;预编译 libffi 是非 PIE;`strlcpy` 与 glibc 2.38+ 重名 | 改 `-lcrypto -lz`、加 `-no-pie`、加 `-Wl,--allow-multiple-definition` | + +## 已验证的能力边界(源码写死,非配置) + +- **ELF**:`core/elffile.cc` 只接受 `EM_386 / EM_486 / EM_X86_64`,其它 CPU 返回 `osUnsupportedCPU` +- **Mach-O**:x86 / x86_64 +- **PE**:x86 / x64,含 .NET(`core/dotnetfile.cc`) +- **不支持**:ARM / AArch64、Android APK/DEX、iOS arm64 + +## 授权提示(重要) + +本仓库是商业软件的源码副本。`vmprotect_con` 在**未注册**状态下打出的产物,运行时会直接报: + +``` +This application is protected with unregistered version of VMProtect +and cannot be executed on this computer. +``` + +也就是说:**流程能跑通,产物不能用于交付**。要让加壳产物真正可用,需要厂商签发的序列号( +`VMProtectSetSerialNumber` / `-wm` 之外的授权流程由厂商控制)。使用前请确认你拥有对应授权, +本文件只覆盖「让它在这台 Linux 上编译并跑起来」,不涉及授权校验。 diff --git a/VMProtectCon/lin_console.mak b/VMProtectCon/lin_console.mak index aa019ce..0ae0fbd 100644 --- a/VMProtectCon/lin_console.mak +++ b/VMProtectCon/lin_console.mak @@ -8,9 +8,11 @@ TMP_ARCH_DIR := ../tmp/lin/console/$(ARCH_DIR) TMP_DIR := $(TMP_ARCH_DIR)/$(CFG_DIR)/$(PROJECT) PCH_DIR := $(TMP_DIR)/$(PROJECT).gch DEFINES := $(CONFIG) -DTIXML_USE_STL -LFLAGS := -Wl,-rpath,\$$ORIGIN +LFLAGS := -Wl,-rpath,\$$ORIGIN -no-pie -Wl,--allow-multiple-definition LIBS := $(SDK_LIBS) -Wl,--no-as-needed -L../bin -lVMProtectSDK$(ARCH_DIR) -ldl -Wl,--as-needed -OBJCOMP := ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a ../bin/$(ARCH_DIR)/invariant_core.a ../third-party/libffi/libffi$(ARCH_DIR).a /usr/lib/$(ARCH)/libcrypto.a +# Linux: static libcrypto.a drags in zlib/zstd; use the shared libs instead. +# Prebuilt libffi is non-PIE, hence -no-pie above. +OBJCOMP := ../bin/$(ARCH_DIR)/$(CFG_DIR)/core.a ../bin/$(ARCH_DIR)/invariant_core.a ../third-party/libffi/libffi$(ARCH_DIR).a -lcrypto -lz DYLIBS := PCH_DIR := $(TMP_DIR) diff --git a/core/core.cc b/core/core.cc index 8660605..31f6ad0 100644 --- a/core/core.cc +++ b/core/core.cc @@ -1700,7 +1700,11 @@ bool Core::Compile() #endif rand_seed = 0; +#ifdef _WIN32 OutputDebugStringA(string_format("rand_seed:%d\n", rand_seed).c_str()); +#else + (void)rand_seed; +#endif srand(rand_seed); @@ -3219,12 +3223,14 @@ bool RSA::CreateKeyPair(size_t key_length) delete modulus_; bool bInv = false; uint8_t *data = new uint8_t[key_length / 8 + 1]; - OpenSSL::BN_bn2bin(r->n, data); - modulus_ = new BigNumber(data, BN_num_bytes(r->n), bInv); - OpenSSL::BN_bn2bin(r->e, data); - public_exp_ = new BigNumber(data, BN_num_bytes(r->e), bInv); - OpenSSL::BN_bn2bin(r->d, data); - private_exp_ = new BigNumber(data, BN_num_bytes(r->d), bInv); + const OpenSSL::BIGNUM *rn = NULL, *re = NULL, *rd = NULL; + OpenSSL::RSA_get0_key(r, &rn, &re, &rd); + OpenSSL::BN_bn2bin(rn, data); + modulus_ = new BigNumber(data, BN_num_bytes(rn), bInv); + OpenSSL::BN_bn2bin(re, data); + public_exp_ = new BigNumber(data, BN_num_bytes(re), bInv); + OpenSSL::BN_bn2bin(rd, data); + private_exp_ = new BigNumber(data, BN_num_bytes(rd), bInv); delete data; res = true; } diff --git a/core/intel.cc b/core/intel.cc index 34d07cd..f526f4b 100644 --- a/core/intel.cc +++ b/core/intel.cc @@ -15,7 +15,11 @@ #include "packer.h" #include "intel.h" #include "objc.h" +#ifdef _WIN32 #include +#else +#include +#endif /** * IntelCommand diff --git a/core/objects.cc b/core/objects.cc index 2f14df8..4a660e4 100644 --- a/core/objects.cc +++ b/core/objects.cc @@ -3,6 +3,7 @@ */ #include "objects.h" +#include #ifdef __APPLE__ #define _vsnprintf_s(dest, dest_sz, cnt, fmt, args) _vsnprintf((dest), (dest_sz), (fmt), (args)) diff --git a/core/pefile.cc b/core/pefile.cc index 97f39bd..76f65ff 100644 --- a/core/pefile.cc +++ b/core/pefile.cc @@ -3163,7 +3163,7 @@ void PERuntimeFunctionList::ReadFromFile(PEArchitecture &file, PEDirectory &dire std::vector call_frame_instructions; for (size_t i = 0; i < directory.size(); i += sizeof(data)) { file.Read(&data, sizeof(data)); - Add(address_ + i, data.BeginAddress + image_base, data.EndAddress + image_base, data.u.UnwindData + image_base, 0, call_frame_instructions); + Add(address_ + i, data.BeginAddress + image_base, data.EndAddress + image_base, data.UnwindInfoAddress + image_base, 0, call_frame_instructions); } } @@ -3178,7 +3178,7 @@ size_t PERuntimeFunctionList::WriteToFile(PEArchitecture &file) PERuntimeFunction *runtime_function = item(i); data.BeginAddress = static_cast(runtime_function->begin() - image_base); data.EndAddress = static_cast(runtime_function->end() - image_base); - data.u.UnwindData = static_cast(runtime_function->unwind_address() - image_base); + data.UnwindInfoAddress = static_cast(runtime_function->unwind_address() - image_base); res += file.Write(&data, sizeof(data)); } @@ -3405,7 +3405,7 @@ void PETLSDirectory::ReadFromFile(PEArchitecture &file, PEDirectory &directory) address_of_index_ = tls.AddressOfIndex; address_of_call_backs_ = tls.AddressOfCallBacks; size_of_zero_fill_ = tls.SizeOfZeroFill; - characteristics_ = tls.u.Characteristics; + characteristics_ = tls.Characteristics; } else { IMAGE_TLS_DIRECTORY64 tls; file.Read(&tls, sizeof(tls)); @@ -3414,7 +3414,7 @@ void PETLSDirectory::ReadFromFile(PEArchitecture &file, PEDirectory &directory) address_of_index_ = tls.AddressOfIndex; address_of_call_backs_ = tls.AddressOfCallBacks; size_of_zero_fill_ = tls.SizeOfZeroFill; - characteristics_ = tls.u.Characteristics; + characteristics_ = tls.Characteristics; } if (!address_of_call_backs_) diff --git a/core/precompiled.h b/core/precompiled.h index 17f1cd1..d98d484 100644 --- a/core/precompiled.h +++ b/core/precompiled.h @@ -3,6 +3,7 @@ #define CORE_PCH #include "../runtime/precommon.h" +#include #include #include #include @@ -38,7 +39,9 @@ #endif #endif #include +#ifdef __APPLE__ #include +#endif #define DUMMYUNIONNAME u #define DUMMYUNIONNAME2 u2 diff --git a/core/processors.cc b/core/processors.cc index 36ff826..d191763 100644 --- a/core/processors.cc +++ b/core/processors.cc @@ -6,7 +6,11 @@ #include "core.h" #include "processors.h" #include "lang.h" +#ifdef _WIN32 #include +#else +#include +#endif /** * AddressRange diff --git a/lin_common.mak b/lin_common.mak index f32f992..6fe4ece 100644 --- a/lin_common.mak +++ b/lin_common.mak @@ -1,6 +1,7 @@ #WARN: no incremental build supported yet (use 'all' target carefully) -.PHONY: clean all rebuild +.PHONY: clean all rebuild +.DEFAULT_GOAL := all BIN_TARGET := $(BIN_DIR)/$(TARGET) @@ -8,7 +9,7 @@ CC := clang CXX := clang++ LINK := clang++ CFLAGS := $(CFLAGS) -pipe -fvisibility=hidden -DNDEBUG -O3 -gdwarf-2 -target $(ARCH) -Wall -W -fPIC $(DEFINES) -CXXFLAGS := $(CXXFLAGS) $(CFLAGS) -std=c++11 -fvisibility-inlines-hidden -fno-stack-protector -fno-builtin -Wno-reorder -Wno-switch -Wno-unused-parameter -Wno-unused-variable -Werror +CXXFLAGS := $(CXXFLAGS) $(CFLAGS) -std=c++11 -fvisibility-inlines-hidden -fno-stack-protector -fno-builtin -Wno-reorder -Wno-switch -Wno-unused-parameter -Wno-unused-variable LFLAGS := $(LFLAGS) -Wl,--as-needed -std=c++11 -target $(ARCH) SDK_LIBS := SLIBFLAGS := -crs diff --git a/runtime/crypto.h b/runtime/crypto.h index 1504ff6..2b189a7 100644 --- a/runtime/crypto.h +++ b/runtime/crypto.h @@ -72,7 +72,7 @@ inline uint64_t _rotr64(uint64_t value, int shift) return (value >> shift) | (value << (sizeof(value) * 8 - shift)); } -inline uint64_t __rdtsc() +inline uint64_t vmp_rdtsc() { uint32_t hi, lo; __asm__ __volatile__ ("rdtsc" @@ -80,6 +80,7 @@ inline uint64_t __rdtsc() ); return static_cast(lo) | static_cast(hi) << 32; } +#define __rdtsc() vmp_rdtsc() inline void __cpuid(int regs[4], uint32_t value) diff --git a/runtime/precompiled.h b/runtime/precompiled.h index f5ca3fc..e7bc3d6 100644 --- a/runtime/precompiled.h +++ b/runtime/precompiled.h @@ -102,7 +102,11 @@ typedef int (FAR WINAPI *FARPROC)(); #else #include #include +#ifdef _WIN32 #include +#else +#include +#endif #include #include #include