build(linux): 让 Core/SDK/Console 在 Linux 上按顺序直接编译通过
- 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: <intrin.h> 在 Linux 走 <x86intrin.h> - core/objects.cc: 补 <cstdarg>(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 全跑完)。
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
/bin/
|
||||
/tmp/
|
||||
*.o
|
||||
*.gch
|
||||
@@ -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 <sys/sysctl.h>`(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 <intrin.h>`(MSVC 头) | Linux 走 `#include <x86intrin.h>` |
|
||||
| 7 | `core/objects.cc` | 用了 `va_start/va_end` 但缺 `<cstdarg>` | 补 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 上编译并跑起来」,不涉及授权校验。
|
||||
@@ -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)
|
||||
|
||||
|
||||
+12
-6
@@ -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;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#include "packer.h"
|
||||
#include "intel.h"
|
||||
#include "objc.h"
|
||||
#ifdef _WIN32
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* IntelCommand
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
#include "objects.h"
|
||||
#include <cstdarg>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define _vsnprintf_s(dest, dest_sz, cnt, fmt, args) _vsnprintf((dest), (dest_sz), (fmt), (args))
|
||||
|
||||
+4
-4
@@ -3163,7 +3163,7 @@ void PERuntimeFunctionList::ReadFromFile(PEArchitecture &file, PEDirectory &dire
|
||||
std::vector<uint8_t> 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<uint32_t>(runtime_function->begin() - image_base);
|
||||
data.EndAddress = static_cast<uint32_t>(runtime_function->end() - image_base);
|
||||
data.u.UnwindData = static_cast<uint32_t>(runtime_function->unwind_address() - image_base);
|
||||
data.UnwindInfoAddress = static_cast<uint32_t>(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_)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#define CORE_PCH
|
||||
|
||||
#include "../runtime/precommon.h"
|
||||
#include <cstdarg>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
@@ -38,7 +39,9 @@
|
||||
#endif
|
||||
#endif
|
||||
#include <sys/mman.h>
|
||||
#ifdef __APPLE__
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#define DUMMYUNIONNAME u
|
||||
#define DUMMYUNIONNAME2 u2
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
#include "core.h"
|
||||
#include "processors.h"
|
||||
#include "lang.h"
|
||||
#ifdef _WIN32
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* AddressRange
|
||||
|
||||
+3
-2
@@ -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
|
||||
|
||||
+2
-1
@@ -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<uint64_t>(lo) | static_cast<uint64_t>(hi) << 32;
|
||||
}
|
||||
#define __rdtsc() vmp_rdtsc()
|
||||
|
||||
|
||||
inline void __cpuid(int regs[4], uint32_t value)
|
||||
|
||||
@@ -102,7 +102,11 @@ typedef int (FAR WINAPI *FARPROC)();
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <iphlpapi.h>
|
||||
#ifdef _WIN32
|
||||
#include <intrin.h>
|
||||
#else
|
||||
#include <x86intrin.h>
|
||||
#endif
|
||||
#include <wtsapi32.h>
|
||||
#include <winternl.h>
|
||||
#include <tlhelp32.h>
|
||||
|
||||
Reference in New Issue
Block a user