]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Fix reveng
authormarshmellow42 <marshmellowrf@gmail.com>
Sun, 7 Jun 2015 04:10:54 +0000 (00:10 -0400)
committermarshmellow42 <marshmellowrf@gmail.com>
Sun, 7 Jun 2015 04:10:54 +0000 (00:10 -0400)
client/cmdcrc.c
client/cmdcrc.h
client/cmdmain.c
client/reveng/cli.c
client/reveng/config.h
client/reveng/getopt.c
client/reveng/getopt.h

index 22eed561826dbb90ed84d55c8dd939cfa8d1b10e..7d021965a646cd25484a928b6caa27e549c6697f 100644 (file)
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
+//#include <stdlib.h>
+//#include <ctype.h>
 #include "cmdmain.h"
 #include "cmdmain.h"
-#include "cmdparser.h"
 #include "cmdcrc.h"
 #include "reveng/reveng.h"
 #include "cmdcrc.h"
 #include "reveng/reveng.h"
-//#include "reveng/cli.h"
-static int CmdHelp(const char *Cmd);
+#include "ui.h"
+#include "util.h"
 
 
-int CmdCrcCalc(const char *Cmd)
-{
-       int argc = 0;
-       char Cmd2[CMD_BUFFER_SIZE] = {0x00};
-       char *argv[3];
+#define MAX_ARGS 20
 
 
-       for (int i = 0; i < 50; i++)
-               if (Cmd[i]==0x00) argc=i;
+int split(char *str, char *arr[MAX_ARGS]){
+    int beginIndex = 0;
+    int endIndex;
+    int maxWords = MAX_ARGS;
+    int wordCnt = 0;
 
 
-       memcpy(Cmd2, Cmd, argc);
-       argv[1]=Cmd2;
-       reveng_main(argc, argv);
-       return 0;
+    while(1){
+        while(isspace(str[beginIndex])){
+            ++beginIndex;
+        }
+        if(str[beginIndex] == '\0')
+            break;
+        endIndex = beginIndex;
+        while (str[endIndex] && !isspace(str[endIndex])){
+            ++endIndex;
+        }
+        int len = endIndex - beginIndex;
+        char *tmp = calloc(len + 1, sizeof(char));
+        memcpy(tmp, &str[beginIndex], len);
+        arr[wordCnt++] = tmp;
+        //PrintAndLog("cnt: %d, %s",wordCnt-1, arr[wordCnt-1]);
+        beginIndex = endIndex;
+        if (wordCnt == maxWords)
+            break;
+    }
+    return wordCnt;
 }
 
 }
 
-static command_t CommandTable[] = 
-{
-       {"help",        CmdHelp,        1, "This help"},
-       {"calc",        CmdCrcCalc,     1, "{ Calculate CRC's }"},
-       {NULL, NULL, 0, NULL}
-};
-
 int CmdCrc(const char *Cmd)
 {
 int CmdCrc(const char *Cmd)
 {
-  CmdsParse(CommandTable, Cmd);
-  return 0; 
-}
+       char name[] = {"reveng "};
+       char Cmd2[50 + 7];
+       memcpy(Cmd2, name, 7);
+       memcpy(Cmd2 + 7, Cmd, 50);
+       char *argv[MAX_ARGS];
+       int argc = split(Cmd2, argv);
+       //PrintAndLog("argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
+       reveng_main(argc, argv);
+       for(int i = 0; i < argc; ++i){
+               //puts(arr[i]);
+               free(argv[i]);
+       }
 
 
-int CmdHelp(const char *Cmd)
-{
-  CmdsHelp(CommandTable);
-  return 0;
+       return 0;
 }
 }
+
index c37ba2b136298d984f4d76c477cc349bf1bb6c6c..ea02f884da026ac8951aeb91cf02b6ea9f822a8b 100644 (file)
@@ -12,5 +12,4 @@
 #define CMDCRC_H__
 
 int CmdCrc(const char *Cmd);
 #define CMDCRC_H__
 
 int CmdCrc(const char *Cmd);
-int CmdCrcCalc(const char *Cmd);
 #endif
 #endif
index 0cc578f61f6cb0b58febf865f75d3d325df3e799..e2a3358c851288d389438cc90e82b6c75f6062e9 100644 (file)
@@ -32,6 +32,7 @@ unsigned int current_command = CMD_UNKNOWN;
 
 static int CmdHelp(const char *Cmd);
 static int CmdQuit(const char *Cmd);
 
 static int CmdHelp(const char *Cmd);
 static int CmdQuit(const char *Cmd);
+static int CmdRev(const char *Cmd);
 
 //For storing command that are received from the device
 static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
 
 //For storing command that are received from the device
 static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
@@ -43,12 +44,12 @@ static int cmd_tail;//Starts as 0
 static command_t CommandTable[] = 
 {
   {"help",  CmdHelp,  1, "This help. Use '<command> help' for details of a particular command."},
 static command_t CommandTable[] = 
 {
   {"help",  CmdHelp,  1, "This help. Use '<command> help' for details of a particular command."},
-  {"crc",   CmdCrc,   1, "Crc calculations from the software reveng1-30"},
   {"data",  CmdData,  1, "{ Plot window / data buffer manipulation... }"},
   {"hf",    CmdHF,    1, "{ High Frequency commands... }"},
   {"hw",    CmdHW,    1, "{ Hardware commands... }"},
   {"lf",    CmdLF,    1, "{ Low Frequency commands... }"},
   {"data",  CmdData,  1, "{ Plot window / data buffer manipulation... }"},
   {"hf",    CmdHF,    1, "{ High Frequency commands... }"},
   {"hw",    CmdHW,    1, "{ Hardware commands... }"},
   {"lf",    CmdLF,    1, "{ Low Frequency commands... }"},
-  {"script",CmdScript,1,"{ Scripting commands }"},
+  {"reveng",CmdRev,   1, "Crc calculations from the software reveng1-30"},
+  {"script",CmdScript,1, "{ Scripting commands }"},
   {"quit",  CmdQuit,  1, "Exit program"},
   {"exit",  CmdQuit,  1, "Exit program"},
   {NULL, NULL, 0, NULL}
   {"quit",  CmdQuit,  1, "Exit program"},
   {"exit",  CmdQuit,  1, "Exit program"},
   {NULL, NULL, 0, NULL}
@@ -69,6 +70,12 @@ int CmdQuit(const char *Cmd)
   exit(0);
   return 0;
 }
   exit(0);
   return 0;
 }
+
+int CmdRev(const char *Cmd)
+{
+  CmdCrc(Cmd);
+  return 0;
+}
 /**
  * @brief This method should be called when sending a new command to the pm3. In case any old
  *  responses from previous commands are stored in the buffer, a call to this method should clear them.
 /**
  * @brief This method should be called when sending a new command to the pm3. In case any old
  *  responses from previous commands are stored in the buffer, a call to this method should clear them.
index a24445db7fd08410780ae3fc398f99fa4ecf51eb..7747b9af1f15d64ed5d7c228b9784546467111c2 100644 (file)
@@ -89,7 +89,7 @@ int reveng_main(int argc, char *argv[]) {
        model_t pset = model, *candmods, *mptr;
        char *string;
 
        model_t pset = model, *candmods, *mptr;
        char *string;
 
-       //myname = argv[0];
+       myname = argv[0];
 
        /* stdin must be binary */
 #ifdef _WIN32
 
        /* stdin must be binary */
 #ifdef _WIN32
@@ -97,7 +97,9 @@ int reveng_main(int argc, char *argv[]) {
 #endif /* _WIN32 */
 
        SETBMP();
 #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) {
        do {
                c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
                switch(c) {
@@ -487,7 +489,8 @@ void
 uerror(const char *msg) {
        /* Callback function to report fatal errors */
        fprintf(stderr, "%s: %s\n", myname, msg);
 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
 }
 
 void
@@ -545,7 +548,8 @@ oread(const char *name) {
                return(stdin);
        if(!(handle = fopen(name, "rb"))) {
                fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, 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);
 }
        }
        return(handle);
 }
index 88957e8cdbcb56913b581f72cb00f83f0f74e924..084c79ab423b9eca4b5720964e376a90607e6896 100644 (file)
  * specific.
  */
 
  * specific.
  */
 
-/* #define PRESETS  1 */
+#ifdef _WIN32
+ #define PRESETS  1 //
+#endif
+
 
 /* Macros defining the size of a bmp_t.
  * Their values only matter if PRESETS and/or BMPMACRO are defined, in
 
 /* Macros defining the size of a bmp_t.
  * Their values only matter if PRESETS and/or BMPMACRO are defined, in
index 55d8e8c57fa8f697d66db86d730c2fd17124f811..abe99634a29590adbadf70b27b5350087d29720e 100644 (file)
 
 char *optarg;
 int optind = 1, opterr, optopt;
 
 char *optarg;
 int optind = 1, opterr, optopt;
-
+int pos = 0;
 int getopt(int argc, char *argv[], const char *optstring)
 {
 int getopt(int argc, char *argv[], const char *optstring)
 {
-    static int pos = 0;
+    //static int pos = 0;
     char *str;
     
     if (pos == 0) {
     char *str;
     
     if (pos == 0) {
index e9a8354078e749e340ed6ecdd0f7b8bcca1254ff..bf66d9b135d7040668722a995ba24e14935dc078 100644 (file)
@@ -21,5 +21,5 @@
 */
 
 extern char *optarg;
 */
 
 extern char *optarg;
-extern int optind, opterr, optopt;
+extern int optind, opterr, optopt, pos;
 int getopt(int argc, char *argv[], const char *optstring);
 int getopt(int argc, char *argv[], const char *optstring);
Impressum, Datenschutz