]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/reveng/cli.c
fix reveng memory bug + @iceman1001 s scripting
[proxmark3-svn] / client / reveng / cli.c
index a24445db7fd08410780ae3fc398f99fa4ecf51eb..538fab199f8d6c4a74ea0b1669fc1be5777dabb9 100644 (file)
@@ -89,7 +89,7 @@ int reveng_main(int argc, char *argv[]) {
        model_t pset = model, *candmods, *mptr;
        char *string;
 
-       //myname = argv[0];
+       myname = argv[0];
 
        /* stdin must be binary */
 #ifdef _WIN32
@@ -97,7 +97,9 @@ int reveng_main(int argc, char *argv[]) {
 #endif /* _WIN32 */
 
        SETBMP();
-
+       
+       pos=0;
+       optind=1;
        do {
                c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
                switch(c) {
@@ -181,8 +183,10 @@ int reveng_main(int argc, char *argv[]) {
                                        return 0;
                                        //exit(EXIT_FAILURE);
                                }
-                               if(c < 0)
+                               if(c < 0){
                                        uerror("no preset models available");
+                                       return 0;
+                               }
                                /* must set width so that parameter to -ipx is not zeroed */
                                width = plen(model.spoly);
                                rflags |= R_HAVEP | R_HAVEI | R_HAVERI | R_HAVERO | R_HAVEX;
@@ -312,8 +316,10 @@ ippx:
                        break;
                case 'D': /* D  dump all models */
                        args = mcount();
-                       if(!args)
+                       if(!args){
                                uerror("no preset models available");
+                               return 0;
+                       }
                        for(mode = 0; mode < args; ++mode) {
                                mbynum(&model, mode);
                                mcanon(&model);
@@ -325,8 +331,10 @@ ippx:
                         * either attaching names to arbitrary models or forcing to a preset
                         * mmatch(&model, M_OVERWR);
                         */
-                       if(~model.flags & P_MULXN)
+                       if(~model.flags & P_MULXN){
                                uerror("not a Williams model compliant algorithm");
+                               return 0;
+                       }
                        string = mtostr(&model);
                        puts(string);
                        free(string);
@@ -346,10 +354,14 @@ ippx:
                        }
                        break;
                case 's': /* s  search for algorithm */
-                       if(!width)
+                       if(!width){
                                uerror("must specify positive -k or -w before -s");
-                       if(~model.flags & P_MULXN)
+                               return 0;
+                       }
+                       if(~model.flags & P_MULXN){
                                uerror("cannot search for non-Williams compliant models");
+                               return 0;
+                       }
                        praloc(&model.spoly, width);
                        praloc(&model.init, width);
                        praloc(&model.xorout, width);
@@ -364,8 +376,10 @@ ippx:
 
                        /* allocate argument array */
                        args = argc - optind;
-                       if(!(apolys = malloc(args * sizeof(poly_t))))
+                       if(!(apolys = malloc(args * sizeof(poly_t)))){
                                uerror("cannot allocate memory for argument list");
+                               return 0;
+                       }
 
                        for(pptr = apolys; optind < argc; ++optind) {
                                if(uflags & C_INFILE)
@@ -430,11 +444,13 @@ ippx:
                        if(uflags & C_RESULT) {
                                for(qptr = apolys; qptr < pptr; ++qptr)
                                        pfree(qptr);
-                               return 1;
+                               //return 1;
                                //exit(EXIT_SUCCESS);
                        }
-                       if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT))
+                       if(!(model.flags & P_REFIN) != !(model.flags & P_REFOUT)){
                                uerror("cannot search for crossed-endian models");
+                               return 0;
+                       }
                        pass = 0;
                        do {
                                mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
@@ -463,7 +479,6 @@ ippx:
                        break;
                default:  /* no mode specified */
                        fprintf(stderr, "%s: no mode switch specified. Use %s -h for help.\n", myname, myname);
-                       return 0;
                        //exit(EXIT_FAILURE);
        }
 
@@ -487,7 +502,8 @@ void
 uerror(const char *msg) {
        /* Callback function to report fatal errors */
        fprintf(stderr, "%s: %s\n", myname, msg);
-       exit(EXIT_FAILURE);
+       return;
+       //exit(EXIT_FAILURE);
 }
 
 void
@@ -545,7 +561,8 @@ oread(const char *name) {
                return(stdin);
        if(!(handle = fopen(name, "rb"))) {
                fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, name);
-               exit(EXIT_FAILURE);
+               return 0;
+               //exit(EXIT_FAILURE);
        }
        return(handle);
 }
Impressum, Datenschutz