]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
begin reveng add-ons for lua
authormarshmellow42 <marshmellowrf@gmail.com>
Mon, 8 Jun 2015 16:25:50 +0000 (12:25 -0400)
committermarshmellow42 <marshmellowrf@gmail.com>
Mon, 8 Jun 2015 16:25:50 +0000 (12:25 -0400)
client/cmdcrc.c
client/cmdcrc.h
client/cmdmain.c

index 7d021965a646cd25484a928b6caa27e549c6697f..28d2cde0d24011be3bb48d52ce1e01d2af9c47ad 100644 (file)
@@ -8,6 +8,15 @@
 // CRC Calculations from the software reveng commands
 //-----------------------------------------------------------------------------
 
 // CRC Calculations from the software reveng commands
 //-----------------------------------------------------------------------------
 
+#include <stdlib.h>
+#ifdef _WIN32
+#  include <io.h>
+#  include <fcntl.h>
+#  ifndef STDIN_FILENO
+#    define STDIN_FILENO 0
+#  endif /* STDIN_FILENO */
+#endif /* _WIN32 */
+
 #include <stdio.h>
 #include <string.h>
 //#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 //#include <stdlib.h>
 #define MAX_ARGS 20
 
 int split(char *str, char *arr[MAX_ARGS]){
 #define MAX_ARGS 20
 
 int split(char *str, char *arr[MAX_ARGS]){
-    int beginIndex = 0;
-    int endIndex;
-    int maxWords = MAX_ARGS;
-    int wordCnt = 0;
+       int beginIndex = 0;
+       int endIndex;
+       int maxWords = MAX_ARGS;
+       int wordCnt = 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;
+       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;
 }
 
 int CmdCrc(const char *Cmd)
 }
 
 int CmdCrc(const char *Cmd)
@@ -66,3 +75,77 @@ int CmdCrc(const char *Cmd)
        return 0;
 }
 
        return 0;
 }
 
+int GetModels(char *Models[], int *count, uint32_t *width){
+       /* default values */
+       static model_t model = {
+               PZERO,          /* no CRC polynomial, user must specify */
+               PZERO,          /* Init = 0 */
+               P_BE,           /* RefIn = false, RefOut = false, plus P_RTJUST setting in reveng.h */
+               PZERO,          /* XorOut = 0 */
+               PZERO,          /* check value unused */
+               NULL            /* no model name */
+       };
+       //int ibperhx = 8, obperhx = 8;
+       //int rflags = 0, uflags = 0; /* search and UI flags */
+
+       //unsigned long width = 0UL;
+       //int c, mode = 0, args, psets, pass;
+       //poly_t apoly, crc, qpoly = PZERO, *apolys, *pptr = NULL, *qptr = NULL;
+       //model_t pset = model, *candmods, *mptr;
+       //char *string;
+
+       //myname = argv[0];
+
+       /* stdin must be binary */
+       #ifdef _WIN32
+               _setmode(STDIN_FILENO, _O_BINARY);
+       #endif /* _WIN32 */
+
+       SETBMP();
+       
+       //pos=0;
+       //optind=1;
+
+       if (*width == 0) { //reveng -D
+               *count = mcount();
+               //PrintAndLog("Count: %d",*count);
+               if(!*count){
+                       PrintAndLog("no preset models available");
+                       return 0;
+               }
+               for(int mode = 0; mode < *count; ++mode) {
+                       mbynum(&model, mode);
+                       mcanon(&model);
+                       size_t size = (model.name && *model.name) ? strlen(model.name) : 6;
+                       //PrintAndLog("Size: %d, %s",size,model.name);
+                       char *tmp = calloc(size+1, sizeof(char));
+                       if (tmp==NULL){
+                               PrintAndLog("out of memory?");
+                               return 0;
+                       }
+                       memcpy(tmp, model.name, size);
+                       Models[mode] = tmp;
+                       //ufound(&model);
+               }
+       } else { //reveng -s
+
+       }
+       //PrintAndLog("DONE");
+       return 1;
+}
+
+//test call to GetModels
+int CmdrevengTest(const char *Cmd){
+       char *Models[80];
+       int count = 0;
+       uint32_t width = 0;
+       int ans = GetModels(Models, &count, &width);
+       if (!ans) return 0;
+       
+       PrintAndLog("Count: %d",count);
+       for (int i = 0; i < count; i++){
+               PrintAndLog("Model %d: %s",i,Models[i]);
+               free(Models[i]);
+       }
+       return 1;
+}
index ea02f884da026ac8951aeb91cf02b6ea9f822a8b..f542fa270ab4acaefaae95cf16542c9e5c3aaecd 100644 (file)
@@ -12,4 +12,6 @@
 #define CMDCRC_H__
 
 int CmdCrc(const char *Cmd);
 #define CMDCRC_H__
 
 int CmdCrc(const char *Cmd);
+int CmdrevengTest(const char *Cmd);
+int GetModels(char *Models[], int *count, uint32_t *width);
 #endif
 #endif
index e2a3358c851288d389438cc90e82b6c75f6062e9..c3331fe0342a5ac5730632d2b01dcb82444d2730 100644 (file)
@@ -33,6 +33,7 @@ unsigned int current_command = CMD_UNKNOWN;
 static int CmdHelp(const char *Cmd);
 static int CmdQuit(const char *Cmd);
 static int CmdRev(const char *Cmd);
 static int CmdHelp(const char *Cmd);
 static int CmdQuit(const char *Cmd);
 static int CmdRev(const char *Cmd);
+static int CmdrevengT(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];
@@ -49,6 +50,7 @@ static command_t CommandTable[] =
   {"hw",    CmdHW,    1, "{ Hardware commands... }"},
   {"lf",    CmdLF,    1, "{ Low Frequency commands... }"},
   {"reveng",CmdRev,   1, "Crc calculations from the software reveng1-30"},
   {"hw",    CmdHW,    1, "{ Hardware commands... }"},
   {"lf",    CmdLF,    1, "{ Low Frequency commands... }"},
   {"reveng",CmdRev,   1, "Crc calculations from the software reveng1-30"},
+  {"revengt",CmdrevengT,1, "TEST Crc calculations from the software reveng1-30"},
   {"script",CmdScript,1, "{ Scripting commands }"},
   {"quit",  CmdQuit,  1, "Exit program"},
   {"exit",  CmdQuit,  1, "Exit program"},
   {"script",CmdScript,1, "{ Scripting commands }"},
   {"quit",  CmdQuit,  1, "Exit program"},
   {"exit",  CmdQuit,  1, "Exit program"},
@@ -76,6 +78,11 @@ int CmdRev(const char *Cmd)
   CmdCrc(Cmd);
   return 0;
 }
   CmdCrc(Cmd);
   return 0;
 }
+
+int CmdrevengT(const char *Cmd)
+{
+  return CmdrevengTest(Cmd);
+}
 /**
  * @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.
Impressum, Datenschutz