From 0771b52624cff4e736479ab87a83210593c7a9d5 Mon Sep 17 00:00:00 2001 From: Zhang Date: Wed, 7 Feb 2018 22:45:58 +0000 Subject: [PATCH] Don't doInitialization Unless IDB is enabled --- lib/Transforms/Obfuscation/IndirectBranch.cpp | 11 ++++++++--- lib/Transforms/Obfuscation/Obfuscation.cpp | 17 +++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Transforms/Obfuscation/IndirectBranch.cpp b/lib/Transforms/Obfuscation/IndirectBranch.cpp index a28e2b39a..303a1b810 100644 --- a/lib/Transforms/Obfuscation/IndirectBranch.cpp +++ b/lib/Transforms/Obfuscation/IndirectBranch.cpp @@ -32,11 +32,12 @@ namespace llvm { struct IndirectBranch : public FunctionPass { static char ID; bool flag; + bool initialized; map indexmap; - IndirectBranch() : FunctionPass(ID) { this->flag = true; } - IndirectBranch(bool flag) : FunctionPass(ID) { this->flag = flag; } + IndirectBranch() : FunctionPass(ID) { this->flag = true;this->initialized=false;} + IndirectBranch(bool flag) : FunctionPass(ID) { this->flag = flag;this->initialized=false;} StringRef getPassName() const override { return StringRef("IndirectBranch"); } - bool doInitialization(Module &M) override { + bool initialize(Module &M){ vector BBs; unsigned long long i = 0; for (auto F = M.begin(); F != M.end(); F++) { @@ -60,6 +61,10 @@ struct IndirectBranch : public FunctionPass { if (!toObfuscate(flag, &Func, "indibr")) { return false; } + if(this->initialized==false){ + initialize(*Func.getParent()); + this->initialized=true; + } errs() << "Running IndirectBranch On " << Func.getName() << "\n"; vector BIs; for (inst_iterator I = inst_begin(Func); I != inst_end(Func); I++) { diff --git a/lib/Transforms/Obfuscation/Obfuscation.cpp b/lib/Transforms/Obfuscation/Obfuscation.cpp index e23d7a73f..a8cbffece 100644 --- a/lib/Transforms/Obfuscation/Obfuscation.cpp +++ b/lib/Transforms/Obfuscation/Obfuscation.cpp @@ -89,20 +89,22 @@ struct Obfuscation : public ModulePass { } } delete FP; - ModulePass *MP = - createAntiHookPass(EnableAllObfuscation || EnableAntiHooking); - MP->doInitialization(M); - MP->runOnModule(M); - delete MP; + if(EnableAllObfuscation || EnableAntiHooking){ + ModulePass *MP = + createAntiHookPass(EnableAllObfuscation || EnableAntiHooking); + MP->doInitialization(M); + MP->runOnModule(M); + delete MP; + } if(EnableAllObfuscation || EnableAntiDebugging){ // We don't want to link in the IR if the user doesn't want ADB - MP = createAntiDebuggingPass(EnableAllObfuscation || EnableAntiDebugging); + ModulePass *MP = createAntiDebuggingPass(EnableAllObfuscation || EnableAntiDebugging); MP->doInitialization(M); MP->runOnModule(M); delete MP; } // Now Encrypt Strings - MP = createStringEncryptionPass(EnableAllObfuscation || + ModulePass *MP = createStringEncryptionPass(EnableAllObfuscation || EnableStringEncryption); MP->runOnModule(M); delete MP; @@ -140,7 +142,6 @@ struct Obfuscation : public ModulePass { errs() << "Doing Post-Run Cleanup\n"; FunctionPass *P = createIndirectBranchPass(EnableAllObfuscation || EnableIndirectBranching); - P->doInitialization(M); vector funcs; for (Module::iterator iter = M.begin(); iter != M.end(); iter++) { funcs.push_back(&*iter);