/* echo rulezz by pancake / CatHack! */
/* bin 2 shell converter */
/* 30/08/02 */

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>

int
main( int argc, char *argv[])
{
	int f,f2;
	char *p;
	unsigned char b;
	if (--argc)
	{
	printf("Using %s\n",argv[1]);
	f=open(argv[1],0);
 	p=(char *)malloc(strlen(argv[1])+4);
	sprintf(p,"%s.sh",argv[1]);
	f2=open(p,O_CREAT|O_WRONLY|O_TRUNC);
	p=(char *)realloc(p,5);
	write(f2,"echo -ne \"",10);
	while(read(f,&b,1)>0)
		{
		sprintf (p,"\\x%x",b);
		write(f2,p,strlen(p));
		}
	sprintf(p,"\" > %s.out\necho \"%s.out ok\"",argv[1],argv[1]);
	write(f2,p,strlen(p));
	close(f);
	close(f2);
	free(p);
	}
	else
	{
	printf("Usage %s bin-file\n output is bin-file.sh "\
			" prompt is here ->",argv[0]);
	}
}

