3 #include <boost/tokenizer.hpp>
4 #include <boost/program_options.hpp>
5 #include <boost/lexical_cast.hpp>
11 #include "CInstrFactory.hpp"
13 using boost::lexical_cast;
14 using boost::bad_lexical_cast;
18 using namespace boost::program_options;
19 namespace po = boost::program_options;
25 disasm* Iinstr::m_disasm;
27 int main(int argc, char* argv[])
32 po::options_description desc("Allowed options");
34 ("help,h","produce help message")
35 ("file,f",value<string>(), "input file")
38 po::positional_options_description p;
42 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
45 if(vm.count("help")) {
50 if(vm.count("file")) {
52 cout << "going to open file " << vm["file"].as<string>() << endl;
54 inFile.open(vm["file"].as<string>(), ios::in);
56 cerr << "Error opening file " << vm["file"].as<string>() << endl;
61 cout << "not input file given!" << endl << endl;
66 catch(std::exception& ex) {
67 cout << ex.what() << endl;
71 string dir = "./instr/";
73 map<short, Iinstr*> instr;
75 CInstrFactory instrFab;
77 instrFab.loadLibsIntoMap(instr, dir);
79 catch(std::bad_alloc& e) {
80 cerr << progName << ": bad_alloc caught " << e.what() << endl;
88 boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
89 boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
91 while(getline(inFile, str)) {
96 for(auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
97 if(tok_iter == tokens.begin()) {
99 type = lexical_cast<int>(*tok_iter);
103 catch(bad_lexical_cast &) {
116 if((*tok_iter).size() > 0) {
120 cout << *tok_iter << ":";
125 out << "[0x" << *tok_iter << "]: ";
127 else if(count == 2) {
128 out << disasm.decodeToString(*tok_iter);
130 else if(count == 3) {
131 //code saved in hex-file
132 //cout << *tok_iter ;
134 else if(count == 4) {
136 if((*tok_iter).size() > 0) {
137 cout << *tok_iter << ":" << endl;
141 else if(count == 5) {
142 if((*tok_iter).size() > 0) {
152 cerr << "i was to lazy to implement the other format types for now" << endl;
156 if(type == 1 && count <= 4) {