Files
Cmake c04836fd49 runtime: 让 runtime 在 Linux 上可构建 + 资源打包脚本
- runtime/precompiled.h: sys/sysctl.h 只在 __APPLE__ 引入;补 <cstdarg>
- runtime/lin_runtime.mak: curl 改为 -lcurl + pkg-config(原来是写死 ~/curl-7.35.0-64)
- core/gen_inc_lin.py: 把 lin_runtime.so 打成 lin_runtimeNN.so.inc(key + 位置异或,格式对齐
  IFile::OpenResource(is_enc=true)),_so_code 写空表
- runtime/licensing_manager.cc: SetSerialNumber 加 DOGDBG=1 才输出的 [dbrt] 跟踪
- tools/dogkeygen/testhost_lin.c: Linux 侧 SDK 调用测试宿主
- BUILD-LINUX.md: 补 runtime 构建与 .inc 格式说明(含 _so_code 缺失导致授权调用被打桩的结论)
2026-11-23 17:38:12 +08:00

51 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""把编译出来的 runtime .so 打包成 core/lin_runtimeNN.so.inc(打包器内置的 runtime 资源)。
格式与 core/files.cc::IFile::OpenResource(..., is_enc=true) 对应:
前 4 字节 = key(uint32 小端),其余字节按位置异或:
out[p] = in[p] ^ uint8(rotl32(key, p) + p)
`_so_code` 是 runtime 被 VMProtect 处理后导出的函数元数据缓冲(export/import/map/function 四张表)。
这里写空表({0}),打包器读到的就是 0 条 —— runtime 以整块方式注入,不做函数级映射。
用法:
python3 core/gen_inc_lin.py <lin_runtime64.so> core/lin_runtime64.so.inc lin_runtime64
"""
import sys, os
MASK = 0xFFFFFFFF
def rotl32(v, n):
n &= 31
v &= MASK
return ((v << n) | (v >> (32 - n))) & MASK if n else v
def encrypt(data: bytes, key: int) -> bytes:
out = bytearray(len(data))
for i, b in enumerate(data):
out[i] = b ^ ((rotl32(key, i) + i) & 0xFF)
return bytes(out)
def emit(fh, name, data):
fh.write('const uint8_t %s[] = {\n' % name)
for i in range(0, len(data), 16):
fh.write('\t' + ', '.join('0x%02x' % b for b in data[i:i + 16]) + ',\n')
fh.write('};\n\n')
def main():
if len(sys.argv) != 4:
print(__doc__)
return 1
so_path, out_path, prefix = sys.argv[1], sys.argv[2], sys.argv[3]
raw = open(so_path, 'rb').read()
key = 0x5A17C0DE # 任意固定 key,打包器从头部读取
payload = key.to_bytes(4, 'little') + encrypt(raw, key)
with open(out_path, 'w', newline='\n') as fh:
emit(fh, prefix + '_so_code', b'\x00') # 空元数据表
emit(fh, prefix + '_so_file', payload) # key + 加密后的 .so
print('%s: %d bytes .so -> %d bytes resource (key=0x%08X)' % (so_path, len(raw), len(payload), key))
return 0
if __name__ == '__main__':
sys.exit(main())