Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码加固里BCF分析的四个问题 #1

Closed
Naville opened this issue Jun 14, 2018 · 3 comments
Closed

代码加固里BCF分析的四个问题 #1

Naville opened this issue Jun 14, 2018 · 3 comments

Comments

@Naville
Copy link

Naville commented Jun 14, 2018

  • 印次: 第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.*的调用并递归删除指令和指令的参数

@Naville
Copy link
Author

Naville commented Jun 14, 2018

388页。
需要过滤Invoke的原因不是什么跳转。而是因为splitbb会把split之后第一个基本块的末尾修改成无条件跳转的br指令。 而原来的异常处理基本块开头的LandingPad应该被invoke引用而不是无条件的br。 这样生成的ir不合规

Ref: https://mayuyu.io/2017/12/27/BogusControlFlowBug/

@Naville
Copy link
Author

Naville commented Jun 14, 2018

389页。
C++ Include的问题是因为clone的llvm里没有libcxx libcxxabi compiler-rt等,全部带上即可

@Naville
Copy link
Author

Naville commented Jun 14, 2018

369页。通过增加load来加载LLVMObfuscation.dylib

不需要,可以把Obfuscation编译静态库然后修改opt来静态链接混淆

参考: https://github.com/HikariObfuscator/Hikari/blob/release_60/tools/opt/opt.cpp#L412

@Naville Naville changed the title 代码加固里BCF分析的两个问题 代码加固里BCF分析的四个问题 Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants