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;
26 int main(int argc, char* argv[])
31 po::options_description desc("Allowed options");
33 ("help,h","produce help message")
34 ("file,f",value<string>(), "input file")
37 po::positional_options_description p;
41 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
44 if(vm.count("help")) {
49 if(vm.count("file")) {
51 cout << "going to open file " << vm["file"].as<string>() << endl;
53 inFile.open(vm["file"].as<string>(), ios::in);
55 cerr << "Error opening file " << vm["file"].as<string>() << endl;
60 cout << "not input file given!" << endl << endl;
65 catch(std::exception& ex) {
66 cout << ex.what() << endl;
70 string dir = "./instr/";
72 map<short, Iinstr*> instr;
74 CInstrFactory instrFab;
76 instrFab.loadLibsIntoMap(instr, dir);
78 catch(std::bad_alloc& e) {
79 cerr << progName << ": bad_alloc caught " << e.what() << endl;
87 boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
88 boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
90 while(getline(inFile, str)) {
95 for(auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
96 if(tok_iter == tokens.begin()) {
98 type = lexical_cast<int>(*tok_iter);
102 catch(bad_lexical_cast &) {
115 if((*tok_iter).size() > 0) {
119 cout << *tok_iter << ":";
124 out << "[0x" << *tok_iter << "]: ";
126 else if(count == 2) {
127 out << disasm.decodeToString(*tok_iter);
129 else if(count == 3) {
130 //code saved in hex-file
131 //cout << *tok_iter ;
133 else if(count == 4) {
135 if((*tok_iter).size() > 0) {
136 cout << *tok_iter << ":" << endl;
140 else if(count == 5) {
141 if((*tok_iter).size() > 0) {
151 cerr << "i was to lazy to implement the other format types for now" << endl;
155 if(type == 1 && count <= 4) {