feat: 集成 LLVM IR 混淆体系、Route 2 全量合规与系统调用调度加固
- defender: 扩展 IGDispatch/IGArchiveGuard/IGAntiHook/IGObjCBaseline/IGResolve,支持 Route 2 静态库桥接 (IGThreadID.c) 与防重签名检测 - llvm_passes: 新增 IGObfuscator LLVM IR 插件源码(控制流平坦化、字符串加密、间接跳转/调用、不透明常量/字段、MBA、函数外提、基本块拆分、反 Hook 序言) - tools & config: 新增 Xcode 归档编译/链接包装器、LLVM 自愈工具链 (ig_toolchain_resolver)、IPA 审计门禁、崩溃符号还原及最新 ig_llvm_policy.json(文件级匹配 + 3.0 全业务 Handler 平坦化) - tests & docs: 补齐 M0~M3、Pass 单测及系统调用调度/Route 2/LLVM 方案文档;.gitignore 忽略 *.bc 与 .obfuscate_extraction_cache.json
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
#ifndef IG_OBFUSCATOR_PASS_UTILS_H
|
||||
#define IG_OBFUSCATOR_PASS_UTILS_H
|
||||
|
||||
#include "IGPolicyConfig.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/IR/DebugInfoMetadata.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/GlobalValue.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/SHA256.h"
|
||||
#include "llvm/TargetParser/Triple.h"
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace igobf {
|
||||
|
||||
inline llvm::StringRef stripObjCMarker(llvm::StringRef Name) {
|
||||
if (!Name.empty() && Name.front() == '\x01')
|
||||
return Name.drop_front(1);
|
||||
return Name;
|
||||
}
|
||||
|
||||
inline bool isMachOAArch64NonArm64e(const llvm::Module &M) {
|
||||
if (M.getTargetTriple().empty())
|
||||
return true;
|
||||
llvm::Triple TT(M.getTargetTriple());
|
||||
return TT.isOSBinFormatMachO() && TT.isAArch64() &&
|
||||
TT.getArchName() != "arm64e";
|
||||
}
|
||||
|
||||
inline std::string computeShortModuleTag(llvm::StringRef Seed,
|
||||
llvm::StringRef ModId,
|
||||
llvm::StringRef SourcePath) {
|
||||
llvm::SHA256 Hasher;
|
||||
Hasher.update(Seed);
|
||||
Hasher.update("|");
|
||||
Hasher.update(ModId);
|
||||
Hasher.update("|");
|
||||
Hasher.update(SourcePath);
|
||||
auto Digest = Hasher.final();
|
||||
return llvm::toHex(llvm::ArrayRef<uint8_t>(Digest.data(), 4),
|
||||
/*LowerCase=*/true);
|
||||
}
|
||||
|
||||
inline bool isCompilerSynthesizedFunction(const llvm::Function &F,
|
||||
const IGPolicyConfig &Policy) {
|
||||
if (Policy.hasAnnotation(F, "ig_flatten"))
|
||||
return false;
|
||||
llvm::StringRef Name = stripObjCMarker(F.getName());
|
||||
|
||||
if (Name.starts_with("block_copy_helper") ||
|
||||
Name.starts_with("block_destroy_helper") ||
|
||||
Name.starts_with("__copy_helper_block_") ||
|
||||
Name.starts_with("___copy_helper_block_") ||
|
||||
Name.starts_with("__destroy_helper_block_") ||
|
||||
Name.starts_with("___destroy_helper_block_") ||
|
||||
Name.starts_with("objectdestroy") ||
|
||||
Name.ends_with(" .cxx_destruct]") ||
|
||||
Name.contains(".resume.")) {
|
||||
return true;
|
||||
}
|
||||
if (Name.starts_with("$s") || Name.starts_with("_$s")) {
|
||||
if (Name.ends_with("Tm") || Name.ends_with("Wl") ||
|
||||
Name.ends_with("WL") || Name.ends_with("CMa") ||
|
||||
Name.ends_with("VMa") || Name.ends_with("OMa") ||
|
||||
Name.ends_with("WOh") || Name.ends_with("WOy") ||
|
||||
Name.ends_with("WOe") || Name.ends_with("WOc") ||
|
||||
Name.ends_with("WOb") || Name.ends_with("WOd") ||
|
||||
Name.ends_with("TR") || Name.ends_with("TA")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (const llvm::Module *M = F.getParent()) {
|
||||
if (M->getNamedMetadata("llvm.dbg.cu") != nullptr) {
|
||||
const llvm::DISubprogram *SP = F.getSubprogram();
|
||||
if (!SP || SP->isArtificial() ||
|
||||
SP->getFilename().contains("<compiler-generated>")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool matchesAnySubstring(const llvm::Function &F,
|
||||
const std::vector<std::string> &Patterns) {
|
||||
llvm::StringRef CleanName = stripObjCMarker(F.getName());
|
||||
for (const std::string &Pat : Patterns) {
|
||||
if (!Pat.empty() &&
|
||||
(CleanName.contains(Pat) || F.getName().contains(Pat))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool isFunctionSafeForTransform(
|
||||
const llvm::Function &F, const IGPolicyConfig &Policy,
|
||||
const std::vector<std::string> *ExtraExemptSubstrings = nullptr) {
|
||||
if (F.isDeclaration() || Policy.isFunctionExempt(F))
|
||||
return false;
|
||||
if (llvm::GlobalValue::isWeakForLinker(F.getLinkage()) ||
|
||||
F.hasAvailableExternallyLinkage()) {
|
||||
return false;
|
||||
}
|
||||
if (F.isPresplitCoroutine() || F.hasFnAttribute(llvm::Attribute::Naked))
|
||||
return false;
|
||||
if (F.getCallingConv() == llvm::CallingConv::SwiftTail)
|
||||
return false;
|
||||
if (F.hasSection()) {
|
||||
llvm::StringRef Sec = F.getSection();
|
||||
if (Sec.contains("__mod_init_func") || Sec.contains("__objc_init_func") ||
|
||||
Sec.contains("__mod_term_func")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (isCompilerSynthesizedFunction(F, Policy))
|
||||
return false;
|
||||
if (ExtraExemptSubstrings &&
|
||||
matchesAnySubstring(F, *ExtraExemptSubstrings)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline llvm::DebugLoc resolveInstDebugLoc(const llvm::Instruction *I,
|
||||
const llvm::Function &F) {
|
||||
if (I && I->getDebugLoc())
|
||||
return I->getDebugLoc();
|
||||
if (llvm::DISubprogram *SP = F.getSubprogram()) {
|
||||
unsigned Line = SP->getScopeLine() ? SP->getScopeLine() : SP->getLine();
|
||||
return llvm::DILocation::get(F.getContext(), Line, 0, SP);
|
||||
}
|
||||
return llvm::DebugLoc();
|
||||
}
|
||||
|
||||
} // namespace igobf
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user