-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move IndirectCall Obfuscation to LTO pipeline
- Loading branch information
Showing
15 changed files
with
87 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,9 @@ | ||
#pragma once | ||
|
||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Transforms/Obfuscation/Flattening.h" | ||
#include "llvm/Transforms/Obfuscation/HelloWorld.h" | ||
#include "llvm/Transforms/Obfuscation/IndirectCall.h" | ||
#include "llvm/Transforms/Obfuscation/MBAObfuscation.h" | ||
#include "llvm/Transforms/Obfuscation/Substitution.h" | ||
#include "llvm/Transforms/Utils/LowerSwitch.h" | ||
|
||
using namespace llvm; | ||
using namespace Pluto; | ||
|
||
static cl::list<std::string> Passes("passes", cl::CommaSeparated, cl::Hidden, cl::desc("Obfuscation passes")); | ||
|
||
struct LowerSwitchWrapper : LowerSwitchPass { | ||
static bool isRequired() { return true; } | ||
}; | ||
ModulePassManager buildObfuscationPipeline(); | ||
|
||
ModulePassManager buildObfuscationPipeline() { | ||
ModulePassManager MPM; | ||
FunctionPassManager FPM; | ||
for (auto pass : Passes) { | ||
if (pass == "hlw") { | ||
FPM.addPass(HelloWorld()); | ||
} else if (pass == "fla") { | ||
FPM.addPass(LowerSwitchWrapper()); | ||
FPM.addPass(Flattening()); | ||
} else if (pass == "sub") { | ||
FPM.addPass(Substitution()); | ||
} else if (pass == "mba") { | ||
FPM.addPass(MbaObfuscation()); | ||
} else if (pass == "idc") { | ||
MPM.addPass(IndirectCall()); | ||
} | ||
} | ||
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); | ||
return MPM; | ||
} | ||
ModulePassManager buildLTOObfuscationPipeline(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Transforms/Obfuscation/Flattening.h" | ||
#include "llvm/Transforms/Obfuscation/HelloWorld.h" | ||
#include "llvm/Transforms/Obfuscation/IndirectCall.h" | ||
#include "llvm/Transforms/Obfuscation/MBAObfuscation.h" | ||
#include "llvm/Transforms/Obfuscation/Substitution.h" | ||
#include "llvm/Transforms/Utils/LowerSwitch.h" | ||
|
||
using namespace llvm; | ||
using namespace Pluto; | ||
|
||
static cl::list<std::string> Passes("passes", cl::CommaSeparated, cl::Hidden, cl::desc("Obfuscation passes")); | ||
|
||
struct LowerSwitchWrapper : LowerSwitchPass { | ||
static bool isRequired() { return true; } | ||
}; | ||
|
||
ModulePassManager buildObfuscationPipeline() { | ||
ModulePassManager MPM; | ||
FunctionPassManager FPM; | ||
for (auto pass : Passes) { | ||
if (pass == "fla") { | ||
FPM.addPass(LowerSwitchWrapper()); | ||
FPM.addPass(Flattening()); | ||
} else if (pass == "sub") { | ||
FPM.addPass(Substitution()); | ||
} else if (pass == "mba") { | ||
FPM.addPass(MbaObfuscation()); | ||
} else if (pass == "idc") { | ||
MPM.addPass(IndirectCall()); | ||
} | ||
} | ||
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); | ||
return MPM; | ||
} | ||
|
||
ModulePassManager buildLTOObfuscationPipeline() { | ||
ModulePassManager MPM; | ||
FunctionPassManager FPM; | ||
for (auto pass : Passes) { | ||
if (pass == "hlw") { | ||
FPM.addPass(HelloWorld()); | ||
} else if (pass == "idc") { | ||
MPM.addPass(IndirectCall()); | ||
} | ||
} | ||
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); | ||
return MPM; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cd tests/tiny-AES-c | ||
../../install/bin/clang -O3 -mllvm -passes=hlw,idc,mba,fla,sub test.c aes.c -o test.elf | ||
../../install/bin/clang -O3 -flto -fuse-ld=lld -mllvm -passes=mba,fla,sub -Xlinker -mllvm -Xlinker -passes=hlw,idc test.c aes.c -o test.elf | ||
./test.elf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
CXX=`pwd`/install/bin/clang++ | ||
CXX_FLAGS="-mllvm -passes=hlw,idc,mba,fla,sub" | ||
CXX="`pwd`/install/bin/clang++" | ||
CXX_FLAGS="-flto -fuse-ld=lld -O3 -mllvm -passes=mba,fla,sub -Xlinker -mllvm -Xlinker -passes=hlw,idc -Wno-unused-command-line-argument" | ||
|
||
cd tests/jsoncpp | ||
rm -rf build | ||
mkdir -p build | ||
cmake -B build \ | ||
-DCMAKE_CXX_COMPILER=$CXX \ | ||
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" | ||
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" | ||
make -j`nproc` -C build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
cd tests/openssl | ||
CC=../../install/bin/clang CFLAGS="-mllvm -passes=hlw,idc,mba,fla,sub" ./Configure | ||
CC=../../install/bin/clang CFLAGS="-flto -fuse-ld=lld -O3 -mllvm -passes=mba,fla,sub -Xlinker -mllvm -Xlinker -passes=hlw,idc -Wno-unused-command-line-argument" ./Configure | ||
make -j`nproc` tests |