From f62ad6f4ec721bf89943146c30ca92be717fa68c Mon Sep 17 00:00:00 2001 From: Johan Oudinet Date: Thu, 22 Aug 2013 00:51:33 +0200 Subject: [PATCH] Add parser for uc4win logs. --- ChangeLog | 6 + configure.ac | 4 +- src/Makefile.am | 7 +- src/wintraceparser.cc | 288 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 src/wintraceparser.cc diff --git a/ChangeLog b/ChangeLog index 2d77e2d..736edce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2013-08-22 Johan Oudinet + + Add parser for uc4win logs. + * src/Makefile.am: Add wintraceparser program. + * src/wintraceparser.cc: New. + 2012-11-12 Johan Oudinet Fix a bug in simplification rule 5. diff --git a/configure.ac b/configure.ac index 05487e5..4a230d1 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -# Copyright (C) KIT, Johan Oudinet - 2011 +# Copyright (C) KIT, Johan Oudinet - 2011, 2013 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # AC_PREREQ(2.61) -AC_INIT([qdftgraph], [0.3], [oudinet@kit.edu]) +AC_INIT([qdftgraph], [0.4], [oudinet@kit.edu]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([1.10 -Wall -Werror tar-ustar no-define dist-bzip2 nostdinc]) diff --git a/src/Makefile.am b/src/Makefile.am index 0760059..d2e8887 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2011 Johan Oudinet +# Copyright (C) 2011, 2013 Johan Oudinet # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,10 +17,13 @@ AM_CPPFLAGS = -I$(srcdir)/../include $(BOOST_CPPFLAGS) -bin_PROGRAMS = example testlib +bin_PROGRAMS = example testlib wintraceparser example_SOURCES = example.cc example_LDADD = ../include/libqdftgraph.la testlib_SOURCES = test_lib.cc testlib_LDADD = ../include/libqdftgraph.la + +wintraceparser_SOURCES = wintraceparser.cc +wintraceparser_LDADD = ../include/libqdftgraph.la diff --git a/src/wintraceparser.cc b/src/wintraceparser.cc new file mode 100644 index 0000000..0e669cb --- /dev/null +++ b/src/wintraceparser.cc @@ -0,0 +1,288 @@ +// Copyright (C) 2011, 2012 Johan Oudinet +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +#ifndef QDFT_TEST_LIB_CC +# define QDFT_TEST_LIB_CC +# include +# include +# define SIMPLIFY +# include +#include +#include + +#define NS (7) +#define NC (10) + +#include +#include +#include +#include +#include +#include +using std::cout; +using std::endl; +using std::ifstream; + +#define MAX_CHARS 30000 /* chars per line */ +#define MAX_ENTRY 500000 /* rows in file */ +#define MAX_TOKENS_LINE 20 /* tokens per line */ +#define MAIN_DELIMITER "|" /* tokens delimiter */ +#define PARAM_DELIMITER "*" /* params name-value separator */ +#define DEBUG(x) (std::cout)<<"deb:"<< x <<"\n";fflush(stdout); /* was worth it ;-) */ + +#define PROCESS "ProcessName" //PID or ProcessName +#define TRUNCATE 1 //0-no truncate action 1-truncate + +typedef qdft::data_managers<> data_managers_t; + +int overwrite=0; + +typedef struct transfer_t { + char *event; + char *src; + char *dst; + long int size; +} Transfert; + +typedef struct parameter_t { + char *name; + char *value; +} Parameter; + + + +Parameter parse_parameter(char *str) { + Parameter param; + // param.name = (char *)malloc(sizeof(char)*MAX_CHARS); + //param.value = (char *)malloc(sizeof(char)*MAX_CHARS); + + if (str) { + param.name = strtok(str,PARAM_DELIMITER); + param.value = strtok(0, PARAM_DELIMITER); + } + return param; +} + + +void update_transfert(Transfert *transfer, Parameter param) { + + if (!strcmp(transfer->event,"ReadFile")){ + if (!strcmp(param.name, "InFileName")) { + transfer->src=(param.value); + } else if (!strcmp(param.name, PROCESS)) { + transfer->dst=(param.value); + } else if (!(strcmp(param.name, "ToReadBytes"))) { + transfer->size = std::atoi(param.value); + } + } else if(!strcmp(transfer->event,"WriteFile")){ + if (!strcmp(param.name, "InFileName")) { + transfer->dst=(param.value); + } else if (!strcmp(param.name, PROCESS)) { + transfer->src=(param.value); + } else if (!(strcmp(param.name, "ToWriteBytes"))) { + transfer->size = std::atoi(param.value); + } + } else if(!strcmp(transfer->event,"GetClipboardData")){ + if (!strcmp(param.name, PROCESS)) { + transfer->src=strdup("S-CLIPBOARD"); + transfer->dst=(param.value); + } else if (!(strcmp(param.name, "ClipboardSize"))) { + transfer->size = std::atoi(param.value); + } + } else if(!strcmp(transfer->event,"SetClipboardData")){ + if (!strcmp(param.name, PROCESS)) { + transfer->src=(param.value); + transfer->dst=strdup("S-CLIPBOARD"); + } else if (!(strcmp(param.name, "ClipboardSize"))) { + transfer->size = std::atoi(param.value); + } + } else if(!strcmp(transfer->event,"Send")){ + if (!strcmp(param.name, PROCESS)) { + transfer->src=(param.value); + } else if (!(strcmp(param.name, "RemoteAddress"))) { + transfer->dst=(param.value); + } else if (!(strcmp(param.name, "ToSendBytes"))) { + transfer->size = std::atoi(param.value); + } + } else if(!strcmp(transfer->event,"Recv")){ + if (!strcmp(param.name, PROCESS)) { + transfer->dst=(param.value); + } else if (!(strcmp(param.name, "RemoteAddress"))) { + transfer->src=(param.value); + } else if (!(strcmp(param.name, "ToReadBytes"))) { + transfer->size = std::atoi(param.value); + } + } else { + transfer->size=0; + transfer->src=strdup("NOSOURCE"); + transfer->dst=strdup("NODEST"); + } + + // printf ("\n\n current transfer (%s,%s,%l)\n",transfer->src,transfer->dst,transfer->size); +} + + +Transfert parse_row(char *row) { + + char *token[MAX_TOKENS_LINE]; + Parameter tmp; + Transfert result; + long int i; + long int count; + char* event=NULL; + + if (strcmp(row,"")==0){ + result.event=strdup(""); + result.src=strdup(""); + result.dst=strdup(""); + result.size=0; + // std::cout<< "empty row, leaving"; + return result; + } + + token[0] = strtok(row,MAIN_DELIMITER); + //std::cout << "token0:" << token[0]; + + if (token[0]) { + for (i=1; i < MAX_TOKENS_LINE; i++) { + token[i] = strtok(0, MAIN_DELIMITER); + //std::cout << "token["<0){ + tmp = parse_parameter(token[0]); //EVENT MUST BE FIRST PARAMETER TO MATCH + //printf ("pname=%s,pvalue=%s\n",tmp.name,tmp.value); + if (!(strcmp(tmp.name, "event"))) { + result.event=strdup(tmp.value); + // free (tmp.value); + //free (tmp.name); + } else { + //free (tmp.value); + //free (tmp.name); + return result; + } + } + + for (long int i=1; i existingContainers; + std::list::iterator findIter; + long int i=0; + char *secondargument=""; + unsigned sensitive_size=50000; + unsigned public_size=100; + data_managers_t dmanagers; + qdft::dname_type d = dmanagers.new_data (NS * sensitive_size, qdft::unknown, "D-phones"); + typedef std::vector strings_t; + strings_t sources (NS); + strings_t containers (NC); + char buff[MAX_CHARS]; + +#ifndef NO_SIMPLIFY + std::cerr << "Simplification rules: activated\n"; +#else + std::cerr << "Simplification rules: deactivated\n"; +#endif + + if (argc < 2) { + std::cout << "Too few arguments.\n\n Usage: testlib [initial sensitive container]"; + exit(-1); + } + + if (argc > 2) secondargument=strdup((char*)argv[2]); + + f.open((const char *)argv[1]); + + if (!f.good()) { + std::cout << "Non existing file"; + exit(-1); + } + + while (!f.eof() && i Adding "<< tran.src <<" to the list of containers (with initialization)"<< std::endl; + existingContainers.push_back(tran.src); + dmanagers.init (d, sensitive_size, tran.src); + } + } + findIter=std::find(existingContainers.begin(), existingContainers.end(), tran.dst); + if (findIter==existingContainers.end()){ + std::cerr<<"--> Adding "<< tran.dst <<" to the list of containers (no initialization)"<< std::endl; + existingContainers.push_back(tran.dst); + } + + if (!(strcmp(tran.event,"SetClipboardData"))&& TRUNCATE){ + dmanagers.truncate (d, tran.dst, 0); + } + + std::cerr << i << " - Event "<