#include"llvm/Pass.h"#include"llvm/IR/Function.h"#include"llvm/Support/raw_ostream.h"usingnamespacellvm;namespace{structEncodeFunctionName:publicFunctionPass{staticcharID;EncodeFunctionName():FunctionPass(ID){}boolrunOnFunction(Function&F)override{errs()<<"Encode Function Name: "<<F.getName()<<" -> ";if(F.getName().compare("main")!=0){llvm::MD5Hasher;llvm::MD5::MD5ResultHash;Hasher.update("luohun_");Hasher.update(F.getName());Hasher.final(Hash);SmallString<32>HexString;llvm::MD5::stringifyResult(Hash,HexString);F.setName(HexString);}errs().write_escaped(F.getName())<<'\n';returnfalse;}};// end of struct EncodeFunctionName
}charEncodeFunctionName::ID=0;staticRegisterPass<EncodeFunctionName>X("encode","Encode Function Name Pass",false/* Only looks at CFG */,false/* Analysis Pass */);
#include"llvm/Pass.h"#include"llvm/IR/Function.h"#include"llvm/Support/raw_ostream.h"usingnamespacellvm;namespace{structEncodeFunctionName:publicFunctionPass{staticcharID;EncodeFunctionName():FunctionPass(ID){}boolrunOnFunction(Function&F)override{errs()<<"Encode Function Name: "<<F.getName()<<" -> ";if(F.getName().compare("main")!=0){llvm::MD5Hasher;llvm::MD5::MD5ResultHash;Hasher.update("luohun_");Hasher.update(F.getName());Hasher.final(Hash);SmallString<32>HexString;llvm::MD5::stringifyResult(Hash,HexString);F.setName(HexString);}errs().write_escaped(F.getName())<<'\n';returnfalse;}};// end of struct EncodeFunctionName
}charEncodeFunctionName::ID=0;staticRegisterPass<EncodeFunctionName>X("encode","Encode Function Name Pass",false/* Only looks at CFG */,false/* Analysis Pass */);
#include"llvm/Pass.h"#include"llvm/IR/Function.h"#include"llvm/Support/raw_ostream.h"#include"llvm/Transforms/EncodeFunctionName/EncodeFunctionName.h"usingnamespacellvm;namespace{structEncodeFunctionName:publicFunctionPass{staticcharID;EncodeFunctionName():FunctionPass(ID){}boolrunOnFunction(Function&F)override{errs()<<"Encode Function Name: "<<F.getName()<<" -> ";if(F.getName().compare("main")!=0){llvm::MD5Hasher;llvm::MD5::MD5ResultHash;Hasher.update("luohun_");Hasher.update(F.getName());Hasher.final(Hash);SmallString<32>HexString;llvm::MD5::stringifyResult(Hash,HexString);F.setName(HexString);}errs().write_escaped(F.getName())<<'\n';returnfalse;}};// end of struct EncodeFunctionName
}charEncodeFunctionName::ID=0;staticRegisterPass<EncodeFunctionName>X("encode","Encode Function Name Pass",false/* Only looks at CFG */,false/* Analysis Pass */);//实现该函数
Pass*llvm::createEncodeFunctionName(){returnnewEncodeFunctionName();}
#include"llvm/Transforms/EncodeFunctionName/EncodeFunctionName.h"staticcl::opt<bool>EnableEncodeFunctionName("encode",cl::init(false),cl::Hidden,cl::ZeroOrMore,cl::desc("Encode Name Function Pass"));voidPassManagerBuilder::populateModulePassManager(legacy::PassManagerBase&MPM){//---
if(EnableEncodeFunctionName){MPM.add(createEncodeFunctionName());}//---
}