]> cvs.zerfleddert.de Git - proxmark3-svn/commitdiff
ADD: tnp3xxx identification in luascripts.
authoriceman1001 <iceman@iuse.se>
Tue, 6 Jan 2015 20:20:41 +0000 (21:20 +0100)
committericeman1001 <iceman@iuse.se>
Tue, 6 Jan 2015 20:20:41 +0000 (21:20 +0100)
CHG: minor code clean up.

armsrc/Makefile
armsrc/string.h
client/Makefile
client/cmdmain.c
client/nonce2key/crapto1.c
client/proxguiqt.cpp
client/proxmark3.c
client/scripts/formatMifare.lua
client/scripts/mifare_autopwn.lua
include/at91sam7s512.h
include/proxmark3.h

index f87cf0a195a6be6bd0b8f87b71628b42d8077200..b9019541e7d886a7fe573abf9eaa81f84f717a98 100644 (file)
@@ -10,7 +10,7 @@ APP_INCLUDES = apps.h
 
 #remove one of the following defines and comment out the relevant line
 #in the next section to remove that particular feature from compilation  
-APP_CFLAGS     = -DWITH_LF -DWITH_ISO15693 -DWITH_ISO14443a -DWITH_ISO14443b -DWITH_ICLASS -DWITH_LEGICRF -DWITH_HITAG
+APP_CFLAGS     = -DWITH_LF -DWITH_ISO15693 -DWITH_ISO14443a -DWITH_ISO14443b -DWITH_ICLASS -DWITH_LEGICRF -DWITH_HITAG -fno-strict-aliasing
 #-DWITH_LCD 
 
 #SRC_LCD = fonts.c LCD.c
index 46ee218d1a42947a3b109bc7e61a4d2a26ae7940..421c2bf0e21e3d9952786b0d89d1a2e3b8cd3dcc 100644 (file)
 #ifndef __STRING_H
 #define __STRING_H
 
+#include <stdint.h>
+#include <util.h>
+
 int strlen(const char *str);
-void *memcpy(void *dest, const void *src, int len);
+RAMFUNC void *memcpy(void *dest, const void *src, int len);
 void *memset(void *dest, int c, int len);
-int memcmp(const void *av, const void *bv, int len);
+RAMFUNC int memcmp(const void *av, const void *bv, int len);
 char *strncat(char *dest, const char *src, unsigned int n);
 char *strcat(char *dest, const char *src);
 void strreverse(char s[]);
index b2b215e177d899f71a40c7f3508073e477d9e8c0..93b1636168858a2cefef4d658cf8012df5589e99 100644 (file)
@@ -13,9 +13,9 @@ CXX=g++
 VPATH = ../common
 OBJDIR = obj
 
-LDLIBS = -L/opt/local/lib -L/usr/local/lib -lreadline -lpthread ../liblua/liblua.a
+LDLIBS = -L/opt/local/lib -L/usr/local/lib ../liblua/liblua.a -lreadline -lpthread -lm -lcrypto
 LDFLAGS = $(COMMON_FLAGS)
-CFLAGS = -std=c99 -lcrypto -I. -I../include -I../common -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4 
+CFLAGS = -std=c99 -I. -I../include -I../common -I/opt/local/include -I../liblua -Wall $(COMMON_FLAGS) -g -O4 
 LUAPLATFORM = generic
 
 ifneq (,$(findstring MINGW,$(platform)))
index df3d4b2e37f6a600d866c3945d5a73a107dbc0b5..8d590e9e6ce76ea0538cca4fa964ede1a0d79596 100644 (file)
@@ -133,15 +133,14 @@ bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeou
   
   UsbCommand resp;
 
-  if (response == NULL) {
+       if (response == NULL)
     response = &resp;
-  }
+
 
   // Wait until the command is received
   for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) {
 
-      while(getCommand(response))
-      {
+               while(getCommand(response)) {
           if(response->cmd == cmd){
           return true;
           }
@@ -173,30 +172,30 @@ void CommandReceived(char *Cmd) {
 //-----------------------------------------------------------------------------
 void UsbCommandReceived(UsbCommand *UC)
 {
-  switch(UC->cmd) {
-      // First check if we are handling a debug message
-    case CMD_DEBUG_PRINT_STRING: {
-                 char s[USB_CMD_DATA_SIZE+1] = {0x00};
-      size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE);
-      memcpy(s,UC->d.asBytes,len);
-      PrintAndLog("#db# %s       ", s);
-      return;
-    } break;
-
-    case CMD_DEBUG_PRINT_INTEGERS: {
-      PrintAndLog("#db# %08x, %08x, %08x       \r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
-      return;
-    } break;
-
-    case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: {
-      sample_buf_len += UC->arg[1];
-      memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]);
-    } break;
+       switch(UC->cmd) {
+               // First check if we are handling a debug message
+               case CMD_DEBUG_PRINT_STRING: {
+                       char s[USB_CMD_DATA_SIZE+1] = {0x00};
+                       size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE);
+                       memcpy(s,UC->d.asBytes,len);
+                       PrintAndLog("#db# %s       ", s);
+                       return;
+               } break;
+
+               case CMD_DEBUG_PRINT_INTEGERS: {
+                       PrintAndLog("#db# %08x, %08x, %08x       \r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
+                       return;
+               } break;
+
+               case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: {
+                       sample_buf_len += UC->arg[1];
+                       memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]);
+               } break;
 
                default:
-      break;
-  }
+                       break;
+       }
 
-  storeCommand(UC);
+       storeCommand(UC);
 }
 
index 61215420ff604ec464d40afd450998f0d0fada20..6c0fcafa09ef6bb9c038a6f593de93a0495d9400 100644 (file)
@@ -549,7 +549,6 @@ lfsr_common_prefix(uint32_t pfx, uint32_t rr, uint8_t ks[8], uint8_t par[8][8],
                                free(odd);\r
                                free(even);\r
                 return 0;\r
-\r
        }\r
 \r
        s = statelist;\r
index a820fe419d44f0ba604cc3c323667b1e07101e2a..3e9bdfd5f7add82182a3675c015f560e44e84313 100644 (file)
@@ -280,7 +280,7 @@ void ProxWidget::paintEvent(QPaintEvent *event)
 
 ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
 {
-       resize(600, 500);
+       resize(600, 300);
 
        QPalette palette(QColor(0,0,0,0));
        palette.setColor(QPalette::WindowText, QColor(255,255,255));
index 16a8fa02da81e0b55d38c476dca9f512b83055f4..059cc345ef8f670bee72bbe650236672c7d3816c 100644 (file)
@@ -16,7 +16,7 @@
 #include <unistd.h>
 #include <readline/readline.h>
 #include <readline/history.h>
-//#include "proxusb.h"
+
 #include "proxmark3.h"
 #include "proxgui.h"
 #include "cmdmain.h"
@@ -34,16 +34,11 @@ static UsbCommand txcmd;
 volatile static bool txcmd_pending = false;
 
 void SendCommand(UsbCommand *c) {
-#if 0
-  printf("Sending %d bytes\n", sizeof(UsbCommand));
-#endif
-/*
-  if (txcmd_pending) {
-    ERR("Sending command failed, previous command is still pending");
-  }
-*/
-  if(offline)
-    {
+       #if 0
+               printf("Sending %d bytes\n", sizeof(UsbCommand));
+       #endif
+
+       if (offline) {
       PrintAndLog("Sending bytes to proxmark failed - offline");
       return;
     }
@@ -52,122 +47,119 @@ void SendCommand(UsbCommand *c) {
        or disconnected. The main console thread is alive, but comm thread just spins here.
        Not good.../holiman
        **/
-  while(txcmd_pending);
-  txcmd = *c;
-  txcmd_pending = true;
+       while(txcmd_pending);
+       txcmd = *c;
+       txcmd_pending = true;
 }
 
 struct receiver_arg {
-  int run;
+       int run;
 };
 
 struct main_loop_arg {
-  int usb_present;
-  char *script_cmds_file;
+       int usb_present;
+       char *script_cmds_file;
 };
 
 byte_t rx[0x1000000];
 byte_t* prx = rx;
 
 static void *uart_receiver(void *targ) {
-  struct receiver_arg *arg = (struct receiver_arg*)targ;
-  size_t rxlen;
-  size_t cmd_count;
-  
-  while (arg->run) {
-    rxlen = sizeof(UsbCommand);
-    if (uart_receive(sp,prx,&rxlen)) {
-      prx += rxlen;
-      if (((prx-rx) % sizeof(UsbCommand)) != 0) {
-        continue;
-      }
-      cmd_count = (prx-rx) / sizeof(UsbCommand);
-      //      printf("received %d bytes, which represents %d commands\n",(prx-rx), cmd_count);
-      for (size_t i=0; i<cmd_count; i++) {
-        UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
-      }
-    }
-    prx = rx;
-    
-    if(txcmd_pending) {
-      if (!uart_send(sp,(byte_t*)&txcmd,sizeof(UsbCommand))) {
-        PrintAndLog("Sending bytes to proxmark failed");
-      }
-      txcmd_pending = false;
-    }
-  }
-  
-  pthread_exit(NULL);
-  return NULL;
+       struct receiver_arg *arg = (struct receiver_arg*)targ;
+       size_t rxlen;
+       size_t cmd_count;
+
+       while (arg->run) {
+               rxlen = sizeof(UsbCommand);
+               if (uart_receive(sp, prx, &rxlen)) {
+                       prx += rxlen;
+                       if (((prx-rx) % sizeof(UsbCommand)) != 0) {
+                               continue;
+                       }
+                       cmd_count = (prx-rx) / sizeof(UsbCommand);
+
+                       for (size_t i = 0; i < cmd_count; i++) {
+                               UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
+                       }
+               }
+               prx = rx;
+
+               if(txcmd_pending) {
+                       if (!uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand))) {
+                               PrintAndLog("Sending bytes to proxmark failed");
+                       }
+                       txcmd_pending = false;
+               }
+       }
+
+       pthread_exit(NULL);
+       return NULL;
 }
 
 static void *main_loop(void *targ) {
-  struct main_loop_arg *arg = (struct main_loop_arg*)targ;
-  struct receiver_arg rarg;
-  char *cmd = NULL;
-  pthread_t reader_thread;
+       struct main_loop_arg *arg = (struct main_loop_arg*)targ;
+       struct receiver_arg rarg;
+       char *cmd = NULL;
+       pthread_t reader_thread;
   
-  if (arg->usb_present == 1) {
-    rarg.run=1;
-    // pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
-    pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
-  }
-  
-  FILE *script_file = NULL;
-  char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
-  
-  if (arg->script_cmds_file)
-  {
-    script_file = fopen(arg->script_cmds_file, "r");
-    if (script_file)
-    {
-      printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
-    }
-  }
+       if (arg->usb_present == 1) {
+               rarg.run = 1;
+               pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
+       }
+
+       FILE *script_file = NULL;
+       char script_cmd_buf[256];  // iceman, needs lua script the same file_path_buffer as the rest
+
+       if (arg->script_cmds_file) {
+               script_file = fopen(arg->script_cmds_file, "r");
+               if (script_file) {
+                       printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
+               }
+       }
 
        read_history(".history");
-       while(1)
-  {
-    // If there is a script file
-    if (script_file)
-    {
-      if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file))
-      {
-        fclose(script_file);
-        script_file = NULL;
-      }
-      else
-      {
-        char *nl;
-        nl = strrchr(script_cmd_buf, '\r');
-        if (nl) *nl = '\0';
-        nl = strrchr(script_cmd_buf, '\n');
-        if (nl) *nl = '\0';
-        
-        if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL)
-        {
-          memset(cmd, 0, strlen(script_cmd_buf));
-          strcpy(cmd, script_cmd_buf);
-          printf("%s\n", cmd);
-        }
-      }
-    }
-               
-               if (!script_file)
+
+       while(1)  {
+
+               // If there is a script file
+               if (script_file)
                {
-      cmd = readline(PROXPROMPT);
+                       if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
+                               fclose(script_file);
+                               script_file = NULL;
+                       } else {
+                               char *nl;
+                               nl = strrchr(script_cmd_buf, '\r');
+                               if (nl) *nl = '\0';
+                               
+                               nl = strrchr(script_cmd_buf, '\n');
+                               if (nl) *nl = '\0';
+
+                               if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
+                                       memset(cmd, 0, strlen(script_cmd_buf));
+                                       strcpy(cmd, script_cmd_buf);
+                                       printf("%s\n", cmd);
+                               }
+                       }
                }
                
+               if (!script_file) {
+                       PrintAndLog("FOO!!");
+                       cmd = readline(PROXPROMPT);
+                       PrintAndLog("BAR!!");
+               }
+               
+               PrintAndLog("SNAFU!!");
                if (cmd) {
+
                        while(cmd[strlen(cmd) - 1] == ' ')
-        cmd[strlen(cmd) - 1] = 0x00;
+                               cmd[strlen(cmd) - 1] = 0x00;
                        
                        if (cmd[0] != 0x00) {
                                if (strncmp(cmd, "quit", 4) == 0) {
                                        exit(0);
                                        break;
                                }
-                               
                                CommandReceived(cmd);
                                add_history(cmd);
                        }
@@ -180,20 +172,19 @@ static void *main_loop(void *targ) {
   
        write_history(".history");
   
-  if (arg->usb_present == 1) {
-    rarg.run = 0;
-    pthread_join(reader_thread, NULL);
-  }
-  
-  if (script_file)
-  {
-    fclose(script_file);
-    script_file = NULL;
-  }
-  
-  ExitGraphics();
-  pthread_exit(NULL);
-  return NULL;
+       if (arg->usb_present == 1) {
+               rarg.run = 0;
+               pthread_join(reader_thread, NULL);
+       }
+
+       if (script_file) {
+               fclose(script_file);
+               script_file = NULL;
+       }
+
+       ExitGraphics();
+       pthread_exit(NULL);
+       return NULL;
 }
 
 static void dumpAllHelp(int markdown)
index 1ced0c28d245f02c01b347ffa032b37b7075998e..0d735e98f72a7ce4d3c099fbfe916894cdca92a9 100644 (file)
@@ -90,8 +90,10 @@ function GetCardInfo()
        elseif 0x09 == result.sak then -- NXP MIFARE Mini 0.3k\r
                -- MIFARE Classic mini offers 320 bytes split into five sectors.\r
                numSectors = 5\r
-       elseif  0x10 == result.sak then-- "NXP MIFARE Plus 2k"\r
+       elseif  0x10 == result.sak then -- NXP MIFARE Plus 2k\r
                numSectors = 32\r
+       elseif  0x01 == sak then        -- NXP MIFARE TNP3xxx 1K\r
+               numSectors = 16\r
        else\r
                print("I don't know how many sectors there are on this type of card, defaulting to 16")\r
        end     \r
index 8d0d358fa72590936992ac147dff9cab4c55d015..eb98ffbf753809d64188a47448286e5760735498 100644 (file)
@@ -133,6 +133,8 @@ function nested(key,sak)
                typ = 0
        elseif  0x10 == sak then-- "NXP MIFARE Plus 2k"
                typ = 2
+       elseif  0x01 == sak then-- "NXP MIFARE TNP3xxx 1K"
+               typ = 1
        else
                print("I don't know how many sectors there are on this type of card, defaulting to 16")
        end
index 5be13622336448edb7bea32d11239d1f7d8efdb6..2cdcbce3873b09ed6fea4f7bf6c4c5632f1c0b6e 100644 (file)
@@ -428,7 +428,7 @@ typedef struct _AT91S_PIO {
 #define PIO_PDR         (AT91_CAST(AT91_REG *)         0x00000004) // (PIO_PDR) PIO Disable Register
 #define PIO_PSR         (AT91_CAST(AT91_REG *)         0x00000008) // (PIO_PSR) PIO Status Register
 #define PIO_OER         (AT91_CAST(AT91_REG *)         0x00000010) // (PIO_OER) Output Enable Register
-#define PIO_ODR         (AT91_CAST(AT91_REG *)         0x00000014) // (PIO_ODR) Output Disable Registerr
+#define PIO_ODR         (AT91_CAST(AT91_REG *)         0x00000014) // (PIO_ODR) Output Disable Register
 #define PIO_OSR         (AT91_CAST(AT91_REG *)         0x00000018) // (PIO_OSR) Output Status Register
 #define PIO_IFER        (AT91_CAST(AT91_REG *)         0x00000020) // (PIO_IFER) Input Filter Enable Register
 #define PIO_IFDR        (AT91_CAST(AT91_REG *)         0x00000024) // (PIO_IFDR) Input Filter Disable Register
index 8c9417da5e26d8d45fbc170af70c1f3e769fafd3..b3530c64f2ae22b920458e05e4f483340b1baac4 100644 (file)
@@ -14,6 +14,7 @@
 // Might as well have the hardware-specific defines everywhere.
 #include "at91sam7s512.h"
 #include "config_gpio.h"
+#include "usb_cmd.h"
 
 #define WDT_HIT()                                                              AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001
 
@@ -67,8 +68,6 @@
 #define TRUE 1
 #define FALSE 0
 
-#include <usb_cmd.h>
-
 //#define PACKED __attribute__((__packed__))
 
 #define LED_A_ON()             HIGH(GPIO_LED_A)
Impressum, Datenschutz