Browse Source

Refactor parameters of write_xml for easier usage

dustin.born 6 years ago
parent
commit
71d042af86

+ 2 - 2
code/Attack/MembersMgmtCommAttack.py

@@ -491,7 +491,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
         # --> prefer XML input over CSV input (in case both are given)
         print_updates = False
         if filepath_csv and filepath_xml == self.DEFAULT_XML_PATH:
-            filepath_xml = OUT_DIR + os.path.splitext(os.path.basename(filepath_csv))[0]
+            filename = os.path.splitext(os.path.basename(filepath_csv))[0]
             filesize = os.path.getsize(filepath_csv) / 2**20  # get filesize in MB
             if filesize > 10:
                 print("\nParsing input CSV file...", end=" ")
@@ -502,7 +502,7 @@ class MembersMgmtCommAttack(BaseAttack.BaseAttack):
                 print("done.")
                 print("Writing corresponding XML file...", end=" ")
                 sys.stdout.flush()
-            filepath_xml = cpp_comm_proc.write_xml(filepath_xml)
+            filepath_xml = cpp_comm_proc.write_xml(Util.OUT_DIR, filename)
             Util.MISC_OUT_FILES[filepath_xml] = None
             if print_updates: print("done.")
         else:

+ 9 - 5
code_boost/src/cxx/botnet_comm_processor.cpp

@@ -152,19 +152,23 @@ unsigned int botnet_comm_processor::parse_xml(const std::string &filepath){
 
 /**
  * Writes the communication messages contained in the class member messages into an XML file (with respective notation).
- * @param filename The name the file should have (without extension).
+ * @param out_dir The directory the file is to be put in.
+ * @param basename The actual name of the file without directories or extension.
  * @return The filepath of the written XML file.
  */
-std::string botnet_comm_processor::write_xml(const std::string &filename){
-    std::string filepath = filename + ".xml";
-
+std::string botnet_comm_processor::write_xml(const std::string &out_dir, const std::string &basename){
+    std::string filepath;
+    if (out_dir[out_dir.length() - 1] == '/')
+        filepath = out_dir + basename + ".xml";
+    else
+        filepath = out_dir + "/" + basename + ".xml";
     std::ofstream xml_file;
     xml_file.open(filepath);
 
     // set number of digits after dot to 11
     xml_file << std::fixed << std::setprecision(11);
 
-    xml_file << "<trace name=\"" << filename << "\">";
+    xml_file << "<trace name=\"" << basename << "\">";
     for (const auto &msg : messages){
         xml_file << "<packet ";
         xml_file << "Src=\"" << msg.src << "\" Dst=\"" << msg.dst << "\" ";

+ 3 - 3
code_boost/src/cxx/botnet_comm_processor.h

@@ -115,13 +115,13 @@ public:
 
     int get_message_count();
 
-    unsigned int parse_csv(const std::string &);
+    unsigned int parse_csv(const std::string &filepath);
 
-    unsigned int parse_xml(const std::string &);
+    unsigned int parse_xml(const std::string &filepath);
 
     void set_messages(const py::list &messages_pyboost);
 
-    std::string write_xml(const std::string &);
+    std::string write_xml(const std::string &out_dir, const std::string &basename);
 
 private:
     /*