Browse Source

add small main.cpp to debug pcap processor

main.cpp is only build in debug mode
Jens Keim 5 years ago
parent
commit
92bf236296
2 changed files with 44 additions and 0 deletions
  1. 10 0
      code_boost/src/CMakeLists.txt
  2. 34 0
      code_boost/src/cxx/main.cpp

+ 10 - 0
code_boost/src/CMakeLists.txt

@@ -28,6 +28,11 @@ SET(SOURCE_FILES cxx/pcap_processor.cpp cxx/pcap_processor.h cxx/statistics.cpp
 # Add botnet comm processor source files
 SET(BOT_COMM_PROC_SOURCE cxx/botnet_comm_processor.h cxx/botnet_comm_processor.cpp)
 
+# Add the debugging source files
+IF (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+    SET(DEBUG_FILES cxx/main.cpp cxx/pcap_processor.cpp cxx/pcap_processor.h cxx/statistics.cpp cxx/statistics.h cxx/statistics_db.cpp cxx/statistics_db.h cxx/utilities.h cxx/utilities.cpp)
+ENDIF ()
+
 # Include SQLiteCpp library and build it
 option(SQLITECPP_RUN_CPPLINT OFF)
 include_directories(SQLiteCpp/include)
@@ -62,6 +67,11 @@ TARGET_LINK_LIBRARIES(pcapreader "${TINS_LIBRARY}" ${PYTHON_LIBRARIES} SQLiteCpp
 ADD_LIBRARY(botnetcomm SHARED ${BOT_COMM_PROC_SOURCE})
 TARGET_LINK_LIBRARIES(botnetcomm ${PYTHON_LIBRARIES})
 
+IF (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
+    ADD_EXECUTABLE(main ${DEBUG_FILES})
+    TARGET_LINK_LIBRARIES(main pcapreader ${PYTHON_LIBRARIES})
+ENDIF ()
+
 IF (APPLE)
   SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
 ENDIF ()

+ 34 - 0
code_boost/src/cxx/main.cpp

@@ -0,0 +1,34 @@
+#include "pcap_processor.h"
+#include <pybind11/pybind11.h>
+#include <pybind11/embed.h>
+
+namespace py = pybind11;
+
+int main(int argc, char *argv[]){
+    if (argc > 4) {
+        // get user arguments
+        std::string pcap_path = argv[1];
+        std::string extra_tests = argv[2];
+        std::string resource_path = argv[3];
+        std::string db_path = argv[4];
+        py::float_ elem = *reinterpret_cast<double*>(argv[5]);
+
+        // init other needed vars
+        py::scoped_interpreter guard{};
+        bool del = true;
+        py::list intervals;
+        intervals.append(elem);
+
+        // execute pcap processor
+        pcap_processor pp(pcap_path, extra_tests, resource_path, db_path);
+        pp.collect_statistics(intervals);
+        pp.write_to_database(db_path, intervals, del);
+
+        return 0;
+    } else {
+        // display error and example execution
+        std::cerr << "Error with argument parsing." << std::endl;
+        std::cerr <<  "example execution inside ID2T-toolkit dir (all arg paths should be absolute):" << std::endl;
+        std::cerr <<  "$ code_boost/src/build/main <path_to_pcap_file> <extra_tests> <path_to_id2t_resource_dir> <path_to_db_file> <interval_length>" << std::endl;
+    }
+}