3 #include <boost/tokenizer.hpp>
4 #include <boost/program_options.hpp>
5 #include <boost/lexical_cast.hpp>
10 #include "CInstrFactory.hpp"
12 using boost::lexical_cast;
13 using boost::bad_lexical_cast;
17 using namespace boost::program_options;
18 namespace po = boost::program_options;
22 int main(int argc, char* argv[])
27 po::options_description desc("Allowed options");
29 ("help,h","produce help message")
30 ("file,f",value<string>(), "input file")
33 po::positional_options_description p;
37 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
40 if(vm.count("help")) {
45 if(vm.count("file")) {
47 cout << "going to open file " << vm["file"].as<string>() << endl;
49 inFile.open(vm["file"].as<string>(), ios::in);
51 cerr << "Error opening file " << vm["file"].as<string>() << endl;
56 cout << "not input file given!" << endl << endl;
61 catch(std::exception& ex) {
62 cout << ex.what() << endl;
66 string dir = "./instr/";
68 map<short, Iinstr*> instr;
70 CInstrFactory instrFab;
73 cout << "Loaded " << instrFab.searchLibsInDir(dir) << " Libraryfiles" << endl;
75 instrFab.searchLibsInDir(dir);
77 while(instrFab.getNumFiles() >= 1) {
78 Iinstr* pinstr = instrFab.getNextInstr();
79 instr.insert(make_pair(pinstr->getOpcode(),pinstr));
81 cout << "found: " << instr->getName() << " its opcode is : " << instr->getOpcode() << endl;
85 catch(std::bad_alloc& e) {
86 cerr << progName << ": bad_alloc caught " << e.what() << endl;
94 boost::char_separator<char> sep(";", "", boost::keep_empty_tokens);
95 boost::tokenizer<boost::char_separator<char> > tokens(str, sep);
97 while(getline(inFile, str)) {
102 for(auto tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
103 if(tok_iter == tokens.begin()) {
105 type = lexical_cast<int>(*tok_iter);
109 catch(bad_lexical_cast &) {
122 if((*tok_iter).size() > 0) {
126 cout << *tok_iter << ":";
131 out << "[0x" << *tok_iter << "]: ";
133 else if(count == 2) {
134 out << disasm.decode(*tok_iter);
136 else if(count == 3) {
137 //code saved in hex-file
138 //cout << *tok_iter ;
140 else if(count == 4) {
142 if((*tok_iter).size() > 0) {
143 cout << *tok_iter << ":" << endl;
147 else if(count == 5) {
148 if((*tok_iter).size() > 0) {
158 cerr << "i was to lazy to implement the other format types for now" << endl;
162 if(type == 1 && count <= 4) {