From 954af9179665457b40453a0417ddf5b3949a0449 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 4 Mar 2007 18:35:36 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- bin2db.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bin2db.c (limited to 'bin2db.c') diff --git a/bin2db.c b/bin2db.c new file mode 100644 index 0000000..2f7cb6b --- /dev/null +++ b/bin2db.c @@ -0,0 +1,60 @@ +/* + Convert a binary file to a set of assembly DB instructions +*/ +#include +#include +#include + +#define PERLINE 8 + +int main(int argc, char *argv[]) +{ + char *name="bfile"; + FILE *in,*out; + unsigned char num; + int col; + + in=stdin; + out=stdout; + + if (argc>1) + { + if (!(in=fopen(argv[1],"rb"))) + { + perror(argv[1]); + exit(EXIT_FAILURE); + } + } + + if (argc>2) + { + if (!(out=fopen(argv[2],"w"))) + { + perror(argv[0]); + exit(EXIT_FAILURE); + } + } + + if (argc>1) + fprintf(out,"; Auto-generated binary of %s\n\n",argv[1]); + else + fprintf(out,"; Auto-generated binary\n\n"); + + col=0; + num=0; + + while(!feof(in)) + { + fread(&num,sizeof num,1,in); + + if (col==0) + fprintf(out,"\n\tDB\t"); + + fprintf(out,"%s0x%2.2X",col==0?"":",",num); + + col=(col+1)%PERLINE; + } + + fclose(in); + fclose(out); +} -- cgit v1.2.3