#include "stdio.h"

#include "stdlib.h"

#include <fstream.h>

#include <string.h>



void main( int argc, char *argv[ ], char *envp[ ] )

{

	FILE *stream;

	char LineRead[4096];

	char LineWrite[4096];

	char Temp[200];

	int len=0;

	int i=0;

	int recn=0;

			

	//open input file

	ifstream SourceFile(argv[1],ios::nocreate); 



	//open output file

	if( (stream  = fopen(argv[2], "w" )) == NULL )

	{

		printf( "Error opening output file\n" );

		exit(1);

	}



	//parse file

	while (SourceFile)

	{

		memset(LineRead,'\0',sizeof(LineRead));

		memset(Temp,'\0',sizeof(Temp));

		SourceFile.getline(LineRead,sizeof(LineRead));



		if ((strcmp(LineRead,"")) != 0)

		{

			recn++;

			//determin string length

			len=strlen(LineRead);

			strcpy(Temp,LineRead);



			//construct virus name string

			sprintf(LineWrite,":%s%s",Temp,",");



			//print to outfut file

			fprintf(stream,"%s%s",LineWrite,"\n");

			

			//zero out temp space

			memset(Temp,'\0',sizeof(Temp));

			while (SourceFile)

			{

				SourceFile.getline(LineRead,sizeof(LineRead));

				len=strlen(LineRead);

				if (len > 0)

				{

					//initialize the beginning of the virus signature string

					strcpy(Temp,"\"\\x");

					while (i < len)

					{

						//append hex byte address

						if (strncmp(&LineRead[i]," ",1) == 0)

						{

							strncat(Temp,"\\x",2);

						}

						else

						{

							strncat(Temp,&LineRead[i],1);

						}

						i++;

					}

					//end the virus signature string

					strncat(Temp,"\"#",2);



					//print to outfut file

					fprintf(stream,"%s%s",Temp,"\n");

					fprintf(stream,"%s","\n");



					break;

				}

			}

	

			i=0;

		}

	}



	//close all streams

	fclose(stream);

	SourceFile.close();



	//flush all streams

	_flushall();



	if (recn == 0)

	{

		printf( "Error opening input file\n" );

		exit(1);

	}

	

}



