# parsesnip source



## calvary1980 (Jun 1, 2008)

*C++: Parsesnip Source*

being a security enthusiast I usually find my self writing little tools like this on the fly I wrote this a couple years ago and planned on releasing it but never did, since the programming section is pretty quiet these days I see no harm. 


```
// parsesnip
// version 1.0
// author Christine "calvary" C.
// this tool is used to parse common combinations from selected
// input file to output file with the option of a histogram
// available format http://*:*@* to *:*

// coming soon support for Zima and Crime formats

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>

#define DUP_THRESHOLD 20

using namespace std;

void print_vector(vector<string> & vec);

int main(int argc, char * argv[]){

	string input_fn;
	string output_fn;
	string make_hist;
	int threshold;
	cout<<"enter the path of the input file: ";
	cin>>input_fn;
	cout<<"enter the path of the output file: ";
	cin>>output_fn;
	cout<<"how many instances constitues a common combination (num > 1) : ";
	cin>>threshold;
	cout<<"would you like to make a histogram (y/n): ";
	cin>>make_hist;
	cout<<endl;
	
	vector<string> vl_vec;
	vector<string>::iterator new_end;
	string line;
	string::iterator line_iter;
	string base;
	ifstream in(input_fn.c_str());
	if(!in.good()){
		cout<<"error: "<<input_fn<<" could not be opened \n";
		cin>>input_fn;
		exit(1);
	}
	while (!in.eof()){
		in>>line;
		line_iter = line.begin();
		line_iter += 7;
		
		while(*(++line_iter) != '/');
		line_iter++;
		base.erase(base.begin(),base.end());
		base.resize(line_iter - line.begin() + 1);
		copy(line.begin(), line_iter,base.begin());
		vl_vec.push_back(base);
	}
	sort(vl_vec.begin(),vl_vec.end());
	new_end = unique(vl_vec.begin(),vl_vec.end());
	vl_vec.erase(new_end + 1,vl_vec.end());

	vector<string> combo_vec;
	for(vector<string>::iterator cur = vl_vec.begin();
		cur < new_end;
		cur++){
			line_iter = cur->begin();
			line_iter += 7;
			while(*(++line_iter) != '@');
			base.erase(base.begin(),base.end());
			base.resize(line_iter - cur->begin() - 6);
			copy(cur->begin()+7,line_iter,base.begin());
			combo_vec.push_back(base);
		};

	ofstream out(output_fn.c_str());
	int dups;
	string cur_combo;
	for(vector<string>::iterator cur2 = combo_vec.begin();
		cur2 < combo_vec.end();
		cur2++){
			dups = 0;
			cur_combo = *cur2;
			while(cur_combo == *cur2 && cur2 < combo_vec.end() - 1){ 
				cur2++; 
				dups++;
			};
			
			if(toupper(make_hist[0]) == 'Y'){
				out.width(25);
			}
			if(dups >= threshold){
				out<<cur_combo<<" ";
				if(toupper(make_hist[0]) == 'Y'){
					cout<<" ";
					for(int i=0; i<dups; i++)
						out<<"|";
				}
				out<<endl;
			}
		}
		
	return 0;
}


void print_vector(vector<string> & vec){ // debug
	for(vector<string>::iterator cur = vec.begin();
		cur < vec.end();
		cur++){
			cout<<*cur<<endl;
		}
}// end print_vector
```

- Christine


----------



## Kreij (Jun 7, 2008)

Thanks Christine, this is good stuff and I just wanted to bump it once more so it does not fade into oblivion too soon 

One quick suggestion. When you post a code example , prefix the title with the language you are using. Helps with searching.


----------



## calvary1980 (Jun 7, 2008)

Will do. 

- Christine


----------



## Solaris17 (Jun 7, 2008)

man you guys know so much cool stuff i wish i could code like you guys.


----------



## Kreij (Jun 7, 2008)

Solaris17 said:


> man you guys know so much cool stuff i wish i could code like you guys.




You can, you just have to stick with it and learn.


----------



## Oliver_FF (Jun 8, 2008)

Seriously cool code, between myself and all of my mates I'm usually the first to attempt to make some code run as fast as possible XD 

As far as I know I hold the record at my university for the fastest time to search modem connection logs to determine the times that all modems are concurrently connected - running the code on a server for everyones times to be comparable. Gotta love Algorithm assignments 

You know, if you first poster goes to Edit their post, in this case, Christine, then pick Advanced View, you can change the title of the thread?


----------



## calvary1980 (Jun 8, 2008)

done.

- Christine


----------



## calvary1980 (Jun 9, 2008)

check out my new sig! what do you think 

- Christine


----------



## Solaris17 (Jun 9, 2008)

thiats nice cristine whant to know what gives it away?


nobody writes a smiley face side ways 

and even though you did a good job congrats on finding the font...the slight pixilation can be seen if you have good eyes.

maybe i cant program but i do make things


----------



## Solaris17 (Jun 9, 2008)

awww s#$%T i just burned the final of that disk to 


i used cd menu pro 6 to make an autorun splash


----------



## calvary1980 (Jun 9, 2008)

what about now?  

- Christine


----------



## Solaris17 (Jun 9, 2008)

hahaha  leave me alone your a programmer you know ill spend 27 hours perfecting this it was a late night running on cold coffe and dreams. dont tell me you dont know what im talking about  ill fix it though thanks


----------



## PaulieG (Jun 9, 2008)

Nice code Christine. I wish I could enjoy writing code. It's so damn useful.


----------



## calvary1980 (Jun 9, 2008)

Thanks Paulie  ok my sides hurt, im done.

- Christine


----------



## Solaris17 (Jun 9, 2008)

easy christine...the forum rules say no nudity just a heads.


----------



## calvary1980 (Jun 9, 2008)

lighten up, what is this a family forum all of a sudden. they are just boobs you should see the collage of me 

- Christine


----------



## Solaris17 (Jun 9, 2008)

lol i dont care in the slightest i just didnt want you to get in trouble im not a prude.


----------



## intel igent (Jun 9, 2008)

i can't programm but i can laugh!   

i like the new sig's


----------



## PaulieG (Jun 9, 2008)

Christine, YHPM


----------

