summaryrefslogtreecommitdiff
path: root/bin2db.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin2db.c')
-rw-r--r--bin2db.c60
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);
+}