diff options
Diffstat (limited to '')
| -rw-r--r-- | obfuscator/obfuscator.cpp | 40 | ||||
| -rw-r--r-- | obfuscator/test/obfuscator-tee | 68 | ||||
| -rw-r--r-- | obfuscator/test/test.cpp | 1 | 
3 files changed, 23 insertions, 86 deletions
| diff --git a/obfuscator/obfuscator.cpp b/obfuscator/obfuscator.cpp index 0f9b03d..a76ff13 100644 --- a/obfuscator/obfuscator.cpp +++ b/obfuscator/obfuscator.cpp @@ -20,8 +20,6 @@ along with this program; if not, write to the Free Software  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*/  /*code structure inspired by Eli Bendersky's tutorial on Rewriters.*/  /**********************************************************************************************************************/ -//@DEVI-FIXME-will mess up macros -/**********************************************************************************************************************/  /*included modules*/  /*project headers*/  #include "../mutator_aux.h" @@ -38,22 +36,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.*  #include "clang/ASTMatchers/ASTMatchers.h"  #include "clang/ASTMatchers/ASTMatchFinder.h"  #include "clang/Basic/LLVM.h" -#include "clang/CodeGen/CodeGenAction.h" -#include "clang/CodeGen/BackendUtil.h"  #include "clang/Frontend/CompilerInstance.h"  #include "clang/Frontend/FrontendActions.h"  #include "clang/Lex/Lexer.h"  #include "clang/Tooling/CommonOptionsParser.h"  #include "clang/Tooling/Tooling.h"  #include "clang/Rewrite/Core/Rewriter.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/IR/IRBuilder.h" -#include "llvm/IR/LLVMContext.h" -#include "llvm/IR/Module.h" -#include "llvm/IR/BasicBlock.h" -#include "llvm/IR/Function.h"  #include "llvm/Support/raw_ostream.h" -#include "llvm/Linker/Linker.h"  /**********************************************************************************************************************/  /*used namespaces*/  using namespace llvm; @@ -319,6 +308,23 @@ public:        StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File,         StringRef SearchPath, StringRef RelativePath, const clang::Module *Imported) {      std::cout << "Include filename: " << FileName.str() << "\n"; +    // name, extension, path +    auto header_ = getNameFromPath(FileName.str()); +    std::string hashedName_ = getHashedName(std::get<0>(header_)); +    auto hashedNameX_ = nameMaker(hashedName_, std::get<1>(header_), ""); + +    auto SL = Devi::getSLSpellingLoc(FilenameRange.getBegin(), Rewrite); +    auto SLE = Devi::getSLSpellingLoc(FilenameRange.getEnd(), Rewrite); +    auto SR = SourceRange(SL, SLE); + +    std::string new_name_; +    if (IsAngled) {new_name_ = "<" + hashedNameX_ + ">";} +    else {new_name_ = "\"" + hashedNameX_ + "\"";} + +    Rewrite.ReplaceText(SR, new_name_); +#ifdef DBG +    std::cout << hashedNameX_ << "\n"; +#endif    }  private: @@ -340,7 +346,6 @@ public:      Matcher.addMatcher(functionDecl().bind("funcdecl"), &funcDeclHandler);      Matcher.addMatcher(varDecl(anyOf(unless(hasDescendant(expr(anything()))), hasDescendant(expr(anything()).bind("expr")))).bind("vardecl"), &HandlerForVar);      Matcher.addMatcher(recordDecl(isClass()).bind("classdecl"), &HandlerForClass); -    //Matcher.addMatcher(callExpr().bind("calledfunc"), &HandlerForCalledFunc);      Matcher.addMatcher(declRefExpr().bind("calledvar"), &HandlerForCalledVar);    } @@ -366,7 +371,7 @@ public:    }    void EndSourceFileAction() override {      std::error_code EC; -    std::string OutputFilename = "./obfuscator-tee"; +    std::string OutputFilename = "/tmp/obfuscator-tee";      TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(llvm::outs());      tee = new raw_fd_ostream(StringRef(OutputFilename), EC, sys::fs::F_None);      TheRewriter.getEditBuffer(TheRewriter.getSourceMgr().getMainFileID()).write(*tee); @@ -393,11 +398,10 @@ class CommentWiper {      int run(void) {        for (auto &filepath : sourcelist) {          std::ifstream sourcefile; -        sourcefile.open("./test/obfuscator-tee"); +        sourcefile.open("/tmp/obfuscator-tee");          std::ofstream dupe;          auto filename_ = getNameFromPath(filepath);          dupe.open(nameMaker(getHashedName(std::get<0>(filename_)), std::get<1>(filename_), "")); -        //dupe.open("./dupe.cpp");          std::string line;          int d_quote = 0; @@ -467,7 +471,7 @@ class WhitespaceWarper {      int run(void) {        for (auto &filepath : sourcelist) {          std::ifstream sourcefile; -        sourcefile.open("../test/bruisertest/obfuscator-tee"); +        sourcefile.open("./test/obfuscator-tee");          auto filename_ = getNameFromPath(filepath);          std::ofstream dupe;          dupe.open("./dupe2.cpp"); @@ -507,8 +511,8 @@ int main(int argc, const char **argv) {    //WW.run();    CommentWiper CW(SourcePathList);    CW.run(); -  //dumpHashFilenames(hashFilenames(SourcePathList)); -  //dumpDirList(listDirs("./test")); +  dumpHashFilenames(hashFilenames(SourcePathList)); +  dumpDirList(listDirs("./test"));  #if 0    for (auto &iter : SourcePathList) {      std::cout << "name: " << std::get<0>(getNameFromPath(iter)) << "\t" << "extension: " << std::get<1>(getNameFromPath(iter)) << "\tpath: " << std::get<2>(getNameFromPath(iter)) << "\n"; diff --git a/obfuscator/test/obfuscator-tee b/obfuscator/test/obfuscator-tee deleted file mode 100644 index 7fc775f..0000000 --- a/obfuscator/test/obfuscator-tee +++ /dev/null @@ -1,68 +0,0 @@ - -#if 0 -#include <fstream> -#include <iostream> -#endif - -int ID7143433513913994171(void) { -  return 123; -} - -int ID806107362239807644(int ID6414370376350317282, int ID5596922551969966689) { -  return ID6414370376350317282 + ID5596922551969966689; -} - -#define ID17270913437327947952 1 -#define ID3990433166784345791 int - -#define ID13091842907427809651 3.14 - -#define ID8553886278371731254 int ID6457201339852078238 -#define ID5893689362230717210 int ID17001300751847036766 - -namespace devi -{ -  class ID3351929323710182842 -  { -    public: -      ID3351929323710182842 () {} - -      void ID5560374959326430988 (void) -      { -        int ID4993892634952068459 = 1; -        int ID10838281452030117757 = 2; -        int ID10959529184379665549 = 3; -      } -  }; -} - -int main(int ID3701972582333163920, const char **ID14643508047410943861) -{ -  /***hya**/ -  /* -   * -   * */ -  // /**/ -  int ID17697423301731741216; // this one -  int ID3227026850925696272; /* -  * -  */ -  /* "//" \\ \\\\ // */ -  //std::cout << "//" << "/**/" << "\n"; -  int/***/ ID5827489293749552374; -#if 0 -  std::ofstream myfile; -  myfile.open("./touch"); -  myfile << "line one.\n"; -  myfile.close(); -#endif -  int ID468926534229516570 = 100; -  int ID1567269223287109631 = 28; - -  ID8553886278371731254; -  ID5893689362230717210; -  ID806107362239807644(ID6457201339852078238, ID17001300751847036766); -  return ID806107362239807644(ID468926534229516570, ID1567269223287109631); - -  //return return123(); -} diff --git a/obfuscator/test/test.cpp b/obfuscator/test/test.cpp index 23c3f23..dc4b709 100644 --- a/obfuscator/test/test.cpp +++ b/obfuscator/test/test.cpp @@ -1,3 +1,4 @@ +#include "./header.hpp"  #if 0  #include <fstream> | 
