]> git.siccegge.de Git - frida/frida.git/blob - src/main.cxx
Rework API for getting at instructions
[frida/frida.git] / src / main.cxx
1 #include "disassembler/llvm/include_llvm.hxx"
2
3 #include <climits>
4
5 #include <QApplication>
6 #if QT_VERSION > QT_VERSION_CHECK(5, 2, 0)
7 #define ARGPARSE
8 #endif
9
10 #ifdef ARGPARSE
11 #include <QCommandLineParser>
12 #endif
13 #include <QTextEdit>
14
15 #include "log4cxx/logger.h"
16 #include "log4cxx/basicconfigurator.h"
17
18 #include "gui/Mainwindow.hxx"
19 #include "core/InformationManager.hxx"
20 #include "disassembler/llvm/LLVMDisassembler.hxx"
21 #include "Config.hxx"
22
23 int main(int argc, char** argv)
24 {
25 QApplication app(argc, argv);
26
27 log4cxx::BasicConfigurator::configure();
28 log4cxx::LoggerPtr _logger(log4cxx::Logger::getLogger("main"));
29
30 #ifdef ARGPARSE
31 QCommandLineParser parser;
32 #endif
33
34 QApplication::setApplicationName("frida");
35 QApplication::setApplicationVersion("0.0");
36 QApplication::addLibraryPath(CONFIG_LIBDIR "/frida/plugins/Interpreter");
37 #ifdef ARGPARSE
38 parser.addHelpOption();
39 parser.addVersionOption();
40
41 QCommandLineOption loglevelOption("loglevel", "Control verbosity of logging", "FATAL|ERROR|WARN|INFO|DEBUG|TRACE");
42 loglevelOption.setDefaultValue("INFO");
43 parser.addOption(loglevelOption);
44
45 parser.addPositionalArgument("filename", QCoreApplication::translate("main", "File to disassemble."));
46
47 parser.process(app);
48 #endif
49
50 log4cxx::LevelPtr level = log4cxx::Level::getInfo();
51 #ifdef ARGPARSE
52 if (parser.value(loglevelOption) != "") {
53 std::string levelstring = parser.value(loglevelOption).toStdString();
54 if (levelstring == "FATAL")
55 level = log4cxx::Level::getFatal();
56 if (levelstring == "ERROR")
57 level = log4cxx::Level::getError();
58 if (levelstring == "WARN")
59 level = log4cxx::Level::getWarn();
60 if (levelstring == "INFO")
61 level = log4cxx::Level::getInfo();
62 if (levelstring == "DEBUG")
63 level = log4cxx::Level::getDebug();
64 if (levelstring == "TRACE")
65 level = log4cxx::Level::getTrace();
66 }
67 #endif
68 log4cxx::Logger::getRootLogger()->setLevel(level);
69
70 InformationManager iman;
71
72 LOG4CXX_DEBUG(_logger, "Initializing LLVM");
73 llvm::InitializeAllTargetInfos();
74 llvm::InitializeAllTargetMCs();
75 llvm::InitializeAllAsmParsers();
76 llvm::InitializeAllDisassemblers();
77
78 LOG4CXX_DEBUG(_logger, "Initializing Qt");
79
80 std::string filename = "";
81 #ifdef ARGPARSE
82 if (! parser.positionalArguments().isEmpty()) {
83 filename = parser.positionalArguments().at(0).toStdString();
84 }
85 #endif
86
87 Mainwindow m(&iman);
88 m.show();
89 iman.reset(filename);
90 return app.exec();
91 }