diff options
| author | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
|---|---|---|
| committer | Ian C <ianc@noddybox.co.uk> | 2007-03-04 18:35:36 +0000 |
| commit | 954af9179665457b40453a0417ddf5b3949a0449 (patch) | |
| tree | e3772817de5c79e29b602ebe47fe0129793f1470 /bin2db.c | |
| parent | 892e6e107dbf2386831bd00e7f1c2a0bbe8b2cbb (diff) | |
This commit was generated by cvs2svn to compensate for changes in r2,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'bin2db.c')
| -rw-r--r-- | bin2db.c | 60 |
1 files changed, 60 insertions, 0 deletions
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 <stdlib.h> +#include <stdio.h> +#include <errno.h> + +#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); +} |
