/***************************************************************************** * dcc decompiler * Reads the command line switches and then executes each major section in turn * (C) Cristina Cifuentes ****************************************************************************/ #include #include #include #include "dcc.h" #include "project.h" #include "CallGraph.h" /* Global variables - extern to other modules */ extern std::string asm1_name, asm2_name; /* Assembler output filenames */ extern SYMTAB symtab; /* Global symbol table */ extern STATS stats; /* cfg statistics */ //PROG prog; /* programs fields */ extern OPTION option; /* Command line options */ //Function * pProcList; /* List of procedures, topologically sort */ //Function * pLastProc; /* Pointer to last node in procedure list */ //FunctionListType pProcList; //CALL_GRAPH *callGraph; /* Call graph of the program */ static char *initargs(int argc, char *argv[]); static void displayTotalStats(void); #include #include #include #include #include #include #include #include #include #include #include #include #include #include /**************************************************************************** * main ***************************************************************************/ #include #include using namespace llvm; bool TVisitor(raw_ostream &OS, RecordKeeper &Records) { Record *rec = Records.getDef("ADD8i8"); if(rec) { if(not rec->getTemplateArgs().empty()) std::cout << "Has template args\n"; auto classes(rec->getSuperClasses()); for(auto val : rec->getSuperClasses()) std::cout << "Super "<getName()<<"\n"; // DagInit * in = rec->getValueAsDag(val.getName()); // in->dump(); for(const RecordVal &val : rec->getValues()) { // val.dump(); } rec->dump(); } // rec = Records.getDef("CCR"); // if(rec) // rec->dump(); for(auto val : Records.getDefs()) { //std::cout<< "Def "<createTargetMachine(TheTriple.getTriple(),MCPU,Features,opts); std::cerr<getInstrInfo()->getName(97)<<"\n"; const MCInstrDesc &ds(tm->getInstrInfo()->get(97)); const MCOperandInfo *op1=ds.OpInfo; uint16_t impl_def = ds.getImplicitDefs()[0]; std::cerr<."), QCoreApplication::translate("main", "file")); parser.addOption(targetFileOption); parser.addOption(assembly); //parser.addOption(forceOption); // Process the actual command line arguments given by the user parser.addPositionalArgument("source", QCoreApplication::translate("main", "Dos Executable file to decompile.")); parser.process(app); const QStringList args = parser.positionalArguments(); if(args.empty()) { parser.showHelp(); } // source is args.at(0), destination is args.at(1) option.verbose = parser.isSet(boolOpts[0]); option.VeryVerbose = parser.isSet(boolOpts[1]); if(parser.isSet(assembly)) { option.asm1 = parser.value(assembly).toInt()==1; option.asm2 = parser.value(assembly).toInt()==2; } option.Map = parser.isSet(boolOpts[3]); option.Stats = parser.isSet(boolOpts[4]); option.Interact = false; option.Calls = parser.isSet(boolOpts[2]); option.filename = args.first().toStdString(); if(parser.isSet(targetFileOption)) asm1_name = asm2_name = parser.value(targetFileOption).toStdString(); else if(option.asm1 || option.asm2) { asm1_name = option.filename+".a1"; asm2_name = option.filename+".a2"; } } int main(int argc, char **argv) { QCoreApplication app(argc,argv); QCoreApplication::setApplicationVersion("0.1"); setupOptions(app); /* Front end reads in EXE or COM file, parses it into I-code while * building the call graph and attaching appropriate bits of code for * each procedure. */ DccFrontend fe(option.filename); if(false==fe.FrontEnd ()) return -1; if(option.asm1) return 0; /* In the middle is a so called Universal Decompiling Machine. * It processes the procedure list and I-code and attaches where it can * to each procedure an optimised cfg and ud lists */ udm(); if(option.asm2) return 0; /* Back end converts each procedure into C using I-code, interval * analysis, data flow etc. and outputs it to output file ready for * re-compilation. */ BackEnd(!asm1_name.empty() ? asm1_name:option.filename, Project::get()->callGraph); Project::get()->callGraph->write(); if (option.Stats) displayTotalStats(); return 0; } static void displayTotalStats () /* Displays final statistics for the complete program */ { printf ("\nFinal Program Statistics\n"); printf (" Total number of low-level Icodes : %d\n", stats.totalLL); printf (" Total number of high-level Icodes: %d\n", stats.totalHL); printf (" Total reduction of instructions : %2.2f%%\n", 100.0 - (stats.totalHL * 100.0) / stats.totalLL); }