]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/reveng/cli.c
small fix #416
[proxmark3-svn] / client / reveng / cli.c
index 7747b9af1f15d64ed5d7c228b9784546467111c2..224eedd606915f85d538afd852866158415a8fb2 100644 (file)
@@ -183,8 +183,10 @@ int reveng_main(int argc, char *argv[]) {
                                        return 0;
                                        //exit(EXIT_FAILURE);
                                }
                                        return 0;
                                        //exit(EXIT_FAILURE);
                                }
-                               if(c < 0)
+                               if(c < 0){
                                        uerror("no preset models available");
                                        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;
                                /* 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;
@@ -314,8 +316,10 @@ ippx:
                        break;
                case 'D': /* D  dump all models */
                        args = mcount();
                        break;
                case 'D': /* D  dump all models */
                        args = mcount();
-                       if(!args)
+                       if(!args){
                                uerror("no preset models available");
                                uerror("no preset models available");
+                               return 0;
+                       }
                        for(mode = 0; mode < args; ++mode) {
                                mbynum(&model, mode);
                                mcanon(&model);
                        for(mode = 0; mode < args; ++mode) {
                                mbynum(&model, mode);
                                mcanon(&model);
@@ -327,8 +331,10 @@ ippx:
                         * either attaching names to arbitrary models or forcing to a preset
                         * mmatch(&model, M_OVERWR);
                         */
                         * 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");
                                uerror("not a Williams model compliant algorithm");
+                               return 0;
+                       }
                        string = mtostr(&model);
                        puts(string);
                        free(string);
                        string = mtostr(&model);
                        puts(string);
                        free(string);
@@ -348,10 +354,14 @@ ippx:
                        }
                        break;
                case 's': /* s  search for algorithm */
                        }
                        break;
                case 's': /* s  search for algorithm */
-                       if(!width)
+                       if(!width){
                                uerror("must specify positive -k or -w before -s");
                                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");
                                uerror("cannot search for non-Williams compliant models");
+                               return 0;
+                       }
                        praloc(&model.spoly, width);
                        praloc(&model.init, width);
                        praloc(&model.xorout, width);
                        praloc(&model.spoly, width);
                        praloc(&model.init, width);
                        praloc(&model.xorout, width);
@@ -366,8 +376,10 @@ ippx:
 
                        /* allocate argument array */
                        args = argc - optind;
 
                        /* 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");
                                uerror("cannot allocate memory for argument list");
+                               return 0;
+                       }
 
                        for(pptr = apolys; optind < argc; ++optind) {
                                if(uflags & C_INFILE)
 
                        for(pptr = apolys; optind < argc; ++optind) {
                                if(uflags & C_INFILE)
@@ -432,11 +444,13 @@ ippx:
                        if(uflags & C_RESULT) {
                                for(qptr = apolys; qptr < pptr; ++qptr)
                                        pfree(qptr);
                        if(uflags & C_RESULT) {
                                for(qptr = apolys; qptr < pptr; ++qptr)
                                        pfree(qptr);
-                               return 1;
+                               //return 1;
                                //exit(EXIT_SUCCESS);
                        }
                                //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");
                                uerror("cannot search for crossed-endian models");
+                               return 0;
+                       }
                        pass = 0;
                        do {
                                mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
                        pass = 0;
                        do {
                                mptr = candmods = reveng(&model, qpoly, rflags, args, apolys);
@@ -465,7 +479,6 @@ ippx:
                        break;
                default:  /* no mode specified */
                        fprintf(stderr, "%s: no mode switch specified. Use %s -h for help.\n", myname, myname);
                        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);
        }
 
                        //exit(EXIT_FAILURE);
        }
 
@@ -592,7 +605,19 @@ usage(void) {
                        "\t-c calculate CRCs\t\t-d dump algorithm parameters\n"
                        "\t-D list preset algorithms\t-e echo (and reformat) input\n"
                        "\t-s search for algorithm\t\t-v calculate reversed CRCs\n"
                        "\t-c calculate CRCs\t\t-d dump algorithm parameters\n"
                        "\t-D list preset algorithms\t-e echo (and reformat) input\n"
                        "\t-s search for algorithm\t\t-v calculate reversed CRCs\n"
-                       "\t-h | -u | -? show this help\n"
+                       "\t-g search for alg given hex+crc\t-h | -u | -? show this help\n"
+                       "Common Use Examples:\n"
+                       "\t   reveng -g 01020304e3\n"
+                       "\t      Searches for a known/common crc preset that computes the crc\n"
+                       "\t      on the end of the given hex string\n"
+                       "\t   reveng -w 8 -s 01020304e3 010204039d\n"
+                       "\t      Searches for any possible 8 bit width crc calc that computes\n"
+                       "\t      the crc on the end of the given hex string(s)\n"
+                       "\t   reveng -m CRC-8 -c 01020304\n"
+                       "\t      Calculates the crc-8 of the given hex string\n"
+                       "\t   reveng -D\n"
+                       "\t      Outputs a list of all known/common crc models with their\n"
+                       "\t      preset values\n"
                        "\n"
                        "Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  Gregory Cook\n"
                        "This is free software; see the source for copying conditions.  There is NO\n"
                        "\n"
                        "Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015  Gregory Cook\n"
                        "This is free software; see the source for copying conditions.  There is NO\n"
Impressum, Datenschutz