ADD: tnp3xxx identification in luascripts.

CHG: minor code clean up.
This commit is contained in:
iceman1001 2015-01-06 21:20:41 +01:00
parent bf8328e928
commit 9484ff3d6e
11 changed files with 142 additions and 147 deletions

View file

@ -10,7 +10,7 @@ APP_INCLUDES = apps.h
#remove one of the following defines and comment out the relevant line #remove one of the following defines and comment out the relevant line
#in the next section to remove that particular feature from compilation #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 #-DWITH_LCD
#SRC_LCD = fonts.c LCD.c #SRC_LCD = fonts.c LCD.c

View file

@ -12,10 +12,13 @@
#ifndef __STRING_H #ifndef __STRING_H
#define __STRING_H #define __STRING_H
#include <stdint.h>
#include <util.h>
int strlen(const char *str); 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); 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 *strncat(char *dest, const char *src, unsigned int n);
char *strcat(char *dest, const char *src); char *strcat(char *dest, const char *src);
void strreverse(char s[]); void strreverse(char s[]);

View file

@ -13,9 +13,9 @@ CXX=g++
VPATH = ../common VPATH = ../common
OBJDIR = obj 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) 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 LUAPLATFORM = generic
ifneq (,$(findstring MINGW,$(platform))) ifneq (,$(findstring MINGW,$(platform)))

View file

@ -133,15 +133,14 @@ bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeou
UsbCommand resp; UsbCommand resp;
if (response == NULL) { if (response == NULL)
response = &resp; response = &resp;
}
// Wait until the command is received // Wait until the command is received
for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) { for(size_t dm_seconds=0; dm_seconds < ms_timeout/10; dm_seconds++) {
while(getCommand(response)) while(getCommand(response)) {
{
if(response->cmd == cmd){ if(response->cmd == cmd){
return true; return true;
} }

View 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); free(odd);
free(even); free(even);
return 0; return 0;
} }
s = statelist; s = statelist;

View file

@ -280,7 +280,7 @@ void ProxWidget::paintEvent(QPaintEvent *event)
ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1) ProxWidget::ProxWidget(QWidget *parent) : QWidget(parent), GraphStart(0), GraphPixelsPerPoint(1)
{ {
resize(600, 500); resize(600, 300);
QPalette palette(QColor(0,0,0,0)); QPalette palette(QColor(0,0,0,0));
palette.setColor(QPalette::WindowText, QColor(255,255,255)); palette.setColor(QPalette::WindowText, QColor(255,255,255));

View file

@ -16,7 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
//#include "proxusb.h"
#include "proxmark3.h" #include "proxmark3.h"
#include "proxgui.h" #include "proxgui.h"
#include "cmdmain.h" #include "cmdmain.h"
@ -37,13 +37,8 @@ void SendCommand(UsbCommand *c) {
#if 0 #if 0
printf("Sending %d bytes\n", sizeof(UsbCommand)); printf("Sending %d bytes\n", sizeof(UsbCommand));
#endif #endif
/*
if (txcmd_pending) { if (offline) {
ERR("Sending command failed, previous command is still pending");
}
*/
if(offline)
{
PrintAndLog("Sending bytes to proxmark failed - offline"); PrintAndLog("Sending bytes to proxmark failed - offline");
return; return;
} }
@ -82,7 +77,7 @@ static void *uart_receiver(void *targ) {
continue; continue;
} }
cmd_count = (prx-rx) / sizeof(UsbCommand); 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++) { for (size_t i = 0; i < cmd_count; i++) {
UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand)))); UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
} }
@ -109,43 +104,38 @@ static void *main_loop(void *targ) {
if (arg->usb_present == 1) { if (arg->usb_present == 1) {
rarg.run = 1; rarg.run = 1;
// pthread_create(&reader_thread, NULL, &usb_receiver, &rarg);
pthread_create(&reader_thread, NULL, &uart_receiver, &rarg); pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
} }
FILE *script_file = NULL; FILE *script_file = NULL;
char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest
if (arg->script_cmds_file) if (arg->script_cmds_file) {
{
script_file = fopen(arg->script_cmds_file, "r"); script_file = fopen(arg->script_cmds_file, "r");
if (script_file) if (script_file) {
{
printf("using 'scripting' commands file %s\n", arg->script_cmds_file); printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
} }
} }
read_history(".history"); read_history(".history");
while(1)
{ while(1) {
// If there is a script file // If there is a script file
if (script_file) if (script_file)
{ {
if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
{
fclose(script_file); fclose(script_file);
script_file = NULL; script_file = NULL;
} } else {
else
{
char *nl; char *nl;
nl = strrchr(script_cmd_buf, '\r'); nl = strrchr(script_cmd_buf, '\r');
if (nl) *nl = '\0'; if (nl) *nl = '\0';
nl = strrchr(script_cmd_buf, '\n'); nl = strrchr(script_cmd_buf, '\n');
if (nl) *nl = '\0'; if (nl) *nl = '\0';
if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
{
memset(cmd, 0, strlen(script_cmd_buf)); memset(cmd, 0, strlen(script_cmd_buf));
strcpy(cmd, script_cmd_buf); strcpy(cmd, script_cmd_buf);
printf("%s\n", cmd); printf("%s\n", cmd);
@ -153,12 +143,15 @@ static void *main_loop(void *targ) {
} }
} }
if (!script_file) if (!script_file) {
{ PrintAndLog("FOO!!");
cmd = readline(PROXPROMPT); cmd = readline(PROXPROMPT);
PrintAndLog("BAR!!");
} }
PrintAndLog("SNAFU!!");
if (cmd) { if (cmd) {
while(cmd[strlen(cmd) - 1] == ' ') while(cmd[strlen(cmd) - 1] == ' ')
cmd[strlen(cmd) - 1] = 0x00; cmd[strlen(cmd) - 1] = 0x00;
@ -167,7 +160,6 @@ static void *main_loop(void *targ) {
exit(0); exit(0);
break; break;
} }
CommandReceived(cmd); CommandReceived(cmd);
add_history(cmd); add_history(cmd);
} }
@ -185,8 +177,7 @@ static void *main_loop(void *targ) {
pthread_join(reader_thread, NULL); pthread_join(reader_thread, NULL);
} }
if (script_file) if (script_file) {
{
fclose(script_file); fclose(script_file);
script_file = NULL; script_file = NULL;
} }

View file

@ -90,8 +90,10 @@ function GetCardInfo()
elseif 0x09 == result.sak then -- NXP MIFARE Mini 0.3k elseif 0x09 == result.sak then -- NXP MIFARE Mini 0.3k
-- MIFARE Classic mini offers 320 bytes split into five sectors. -- MIFARE Classic mini offers 320 bytes split into five sectors.
numSectors = 5 numSectors = 5
elseif 0x10 == result.sak then-- "NXP MIFARE Plus 2k" elseif 0x10 == result.sak then -- NXP MIFARE Plus 2k
numSectors = 32 numSectors = 32
elseif 0x01 == sak then -- NXP MIFARE TNP3xxx 1K
numSectors = 16
else else
print("I don't know how many sectors there are on this type of card, defaulting to 16") print("I don't know how many sectors there are on this type of card, defaulting to 16")
end end

View file

@ -133,6 +133,8 @@ function nested(key,sak)
typ = 0 typ = 0
elseif 0x10 == sak then-- "NXP MIFARE Plus 2k" elseif 0x10 == sak then-- "NXP MIFARE Plus 2k"
typ = 2 typ = 2
elseif 0x01 == sak then-- "NXP MIFARE TNP3xxx 1K"
typ = 1
else else
print("I don't know how many sectors there are on this type of card, defaulting to 16") print("I don't know how many sectors there are on this type of card, defaulting to 16")
end end

View file

@ -428,7 +428,7 @@ typedef struct _AT91S_PIO {
#define PIO_PDR (AT91_CAST(AT91_REG *) 0x00000004) // (PIO_PDR) PIO Disable Register #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_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_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_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_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 #define PIO_IFDR (AT91_CAST(AT91_REG *) 0x00000024) // (PIO_IFDR) Input Filter Disable Register

View file

@ -14,6 +14,7 @@
// Might as well have the hardware-specific defines everywhere. // Might as well have the hardware-specific defines everywhere.
#include "at91sam7s512.h" #include "at91sam7s512.h"
#include "config_gpio.h" #include "config_gpio.h"
#include "usb_cmd.h"
#define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001 #define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001
@ -67,8 +68,6 @@
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#include <usb_cmd.h>
//#define PACKED __attribute__((__packed__)) //#define PACKED __attribute__((__packed__))
#define LED_A_ON() HIGH(GPIO_LED_A) #define LED_A_ON() HIGH(GPIO_LED_A)