diff options
Diffstat (limited to 'int2tap.c')
-rw-r--r-- | int2tap.c | 132 |
1 files changed, 127 insertions, 5 deletions
@@ -20,6 +20,8 @@ ------------------------------------------------------------------------- + $Name$ + */ static const char id[]="$Id$"; @@ -30,8 +32,11 @@ static const char id[]="$Id$"; #include <time.h> #include <errno.h> +#include "intel.h" +#include "tap.h" + -/* ---------------------------------------- MACROS +/* ---------------------------------------- GLOBALS */ #undef TRUE #undef FALSE @@ -39,19 +44,136 @@ static const char id[]="$Id$"; #define TRUE 1 #define FALSE 0 - -/* ---------------------------------------- TYPES -*/ +const char *progname; -/* ---------------------------------------- PROTOS +/* ---------------------------------------- PRIVATE UTILS */ +static void Usage(void) +{ + fprintf(stderr,"%s: usage %s [ -b ] [ -s ] [ -a address ] " + "output-file input-file ... \n",progname,progname); +} /* ---------------------------------------- MAIN */ int main(int argc, char *argv[]) { + unsigned char mem[0x10000]; + IntelInfo *info; + char *outname; + unsigned exec_addr; + int bin_only; + int split; + int addr_defined; + int base; + int no; + int f; + int done; + + /* Set program name + */ + if ((progname=strrchr(argv[0],'/'))) + { + progname++; + } + else + { + progname=argv[0]; + } + + /* Set defaults and parse args + */ + addr_defined=FALSE; + bin_only=FALSE; + split=FALSE; + + done=FALSE; + f=1; + + while(f<argc && !done) + { + if (argv[f][0]!='-') + { + base=f; + done=TRUE; + } + else + { + switch(argv[f][1]) + { + case 'b': + bin_only=TRUE; + break; + + case 's': + split=TRUE; + break; + + case 'a': + if (f>argc-2) + { + Usage(); + } + + addr_defined=TRUE; + + exec_addr=(unsigned)strtoul(argv[++f],NULL,0); + + break; + + default: + Usage(); + break; + } + + f++; + } + } + + if (base>=argc-1) + { + Usage(); + } + + outname=argv[base++]; + + no=argc-base; + + if (!(info=malloc(sizeof *info * no))) + { + fprintf(stderr,"%s: malloc failed\n",progname); + } + + /* Process Intel files + */ + for(f=0;f<no;f++) + { + if (!IntelLoad(argv[base+f],mem,info+f)) + { + free(info); + exit(EXIT_FAILURE); + } + + printf("Memory altered from 0x%4.4x for 0x%4.4x bytes, base 0x%4.4x\n", + info[f].low,info[f].len,info[f].addr); + } + + /* TODO: Properly - just a quick test + */ + printf("Creating %s\n",outname); + + if (!TapOpen(outname)) + { + free(info); + exit(EXIT_FAILURE); + } + + TapWrite(mem,info[0].low,info[0].len,TRUE); + + TapClose(); + return EXIT_SUCCESS; } |