+ }
+
+ codecEngine->setDictionary(d);
+ //LOGDEBUG(anna::Logger::debug(codecEngine->asString(), ANNA_FILE_LOCATION));
+
+ if(lst.size() > 1) {
+ std::string all_in_one = "./dictionary-all-in-one.xml";
+ std::ofstream out(all_in_one, std::ifstream::out);
+ std::string buffer = d->asXMLString();
+ out.write(buffer.c_str(), buffer.size());
+ out.close();
+ std::cout << "Written accumulated '" << all_in_one
+ << "' (provide it next time to be more comfortable)." << std::endl;
+ }
+ } catch(anna::RuntimeException &ex) {
+ _exit(ex.asString());
+ }
+
+ codecEngine->ignoreFlagsOnValidation(ignoreFlags);
+ // Tracing:
+ //if (cl.exists("trace"))
+ // anna::Logger::setLevel(anna::Logger::asLevel(cl.getValue("trace")));
+ // Check hex content input file (look extension):
+ anna::DataBlock db_aux(true);
+
+ if(isHex) {
+ if(!getDataBlockFromHexFile(inputFile, db_aux))
+ _exit("Error reading hex file provided");
+
+ try {
+ G_codecMsg.decode(db_aux);
+ } catch(RuntimeException &ex) {
+ _exit(ex.asString());
+ }
+
+ // Open output file:
+ outputFile += ".as.xml";
+ std::ofstream out(outputFile, std::ifstream::out);
+ out << G_codecMsg.asXMLString();
+ // Close output file:
+ out.close();
+ std::string msg = "Open '"; msg += filetrace; msg += "' in order to see process traces.\n";
+ msg += "Open '"; msg += outputFile; msg += "' to see decoding results.";
+ _exit(msg, 0);
+ }
+
+ // Normal input: pcap file:
+ // SNIFFING //////////////////////////////////////////////////////////////////////////////////////////////7
+ //temporary packet buffers
+ struct pcap_pkthdr header; // The header that pcap gives us
+ const u_char *packet; // The actual packet
+ //------------------
+ //open the pcap file
+ pcap_t *handle;
+ char errbuf[PCAP_ERRBUF_SIZE]; //not sure what to do with this, oh well
+ handle = pcap_open_offline(inputFile.c_str(), errbuf); //call pcap library function
+
+ if(handle == NULL) _exit(errbuf, 2);
+
+ //begin processing the packets in this particular file
+ int packets = -1;
+
+ try {
+ while(packets != 0)
+ packets = pcap_dispatch(handle, -1, (pcap_handler) my_callback, NULL);
+ } catch(RuntimeException &ex) {
+ _exit(ex.asString());
+ }
+
+ pcap_close(handle); //close the pcap file
+ // Print payloads //////////////////////////////////////////////////////////////////////////////////////////////
+ // Open output file:
+ outputFile += ".report";
+ std::ofstream out(outputFile, std::ifstream::out);
+
+ for(payloads_it it = G_payloads.begin(); it != G_payloads.end(); it++) {
+ LOGDEBUG(
+ Logger::debug(anna::functions::asString("Dumping frame %d", it->first), ANNA_FILE_LOCATION));
+ time_t ts = (it->second).getTimestamp();
+ int tsu = (it->second).getTimestampU();
+ std::string ts_str = ctime(&ts);
+ ts_str.erase(ts_str.find("\n"));
+ out << std::endl;
+ out
+ << "==================================================================================================="
+ << std::endl;
+ out << "Date: " << ts_str << std::endl;
+ out << "Timestamp: " << std::to_string(ts) << "."
+ << std::to_string(tsu) << std::endl;
+ out << "Origin IP: " << (it->second).getSourceIP() << std::endl;
+ out << "Destination IP: " << (it->second).getDestinationIP() << std::endl;
+ out << std::endl;
+ // decode hex string:
+ anna::functions::fromHexString((it->second).getDataAsHex(), db_aux);
+
+ try {
+ G_codecMsg.decode(db_aux);
+ } catch(RuntimeException &ex) {
+ _exit(ex.asString());
+ }
+
+ out << G_codecMsg.asXMLString();
+ }