代码加固里BCF分析的四个问题
Naville opened this issue · comments
Zhang commented
- 印次: 第1次印刷
- 位置: 385,386页
Strip掉LLVM的DebugIntrinsics。 因为都是void返回类型不需要处理Def-Use Chain所以直接删除指令即可
参见Hikari的实现:
vector<CallInst *> toRemove;
vector<Constant*> DeadConstants;
for (Instruction &I : *alteredBB) {
if (CallInst *CI = dyn_cast<CallInst>(&I)) {
if (CI->getCalledFunction() != nullptr &&
CI->getCalledFunction()->getName().startswith("llvm.dbg")) {
toRemove.push_back(CI);
}
}
}
// Shamefully stolen from IPO/StripSymbols.cpp
for (CallInst *CI : toRemove) {
Value *Arg1 = CI->getArgOperand(0);
Value *Arg2 = CI->getArgOperand(1);
assert(CI->use_empty() && "llvm.dbg intrinsic should have void result");
CI->eraseFromParent();
if (Arg1->use_empty()) {
if (Constant *C = dyn_cast<Constant>(Arg1)) {
DeadConstants.push_back(C);
} else {
RecursivelyDeleteTriviallyDeadInstructions(Arg1);
}
}
if (Arg2->use_empty()) {
if (Constant *C = dyn_cast<Constant>(Arg2)) {
DeadConstants.push_back(C);
}
}
}
while (!DeadConstants.empty()) {
Constant *C = DeadConstants.back();
DeadConstants.pop_back();
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
if (GV->hasLocalLinkage())
RemoveDeadConstant(GV);
} else
RemoveDeadConstant(C);
}
从CloneBB里搜索对llvb.dbg.*
的调用并递归删除指令和指令的参数
Zhang commented
388页。
需要过滤Invoke的原因不是什么跳转。而是因为splitbb会把split之后第一个基本块的末尾修改成无条件跳转的br
指令。 而原来的异常处理基本块开头的LandingPad应该被invoke引用而不是无条件的br。 这样生成的ir不合规
Zhang commented
389页。
C++ Include的问题是因为clone的llvm里没有libcxx libcxxabi compiler-rt等,全部带上即可
Zhang commented
369页。通过增加load来加载LLVMObfuscation.dylib
不需要,可以把Obfuscation编译静态库然后修改opt来静态链接混淆
参考: https://github.com/HikariObfuscator/Hikari/blob/release_60/tools/opt/opt.cpp#L412