int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose)
{
- bool st = TRUE;
- if (!ASKDemod_ext(Cmd, FALSE, FALSE, 1, &st)) return 0;
+ bool st = true;
+ if (!ASKDemod_ext(Cmd, false, false, 1, &st)) return 0;
return AskEm410xDecode(verbose, hi, lo);
}
PrintAndLog(" : data rawdemod am 64 1 0 = demod an ask/manchester tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
- bool st = TRUE;
+ bool st = true;
if (Cmd[0]=='s')
- return ASKDemod_ext(Cmd++, TRUE, TRUE, 1, &st);
+ return ASKDemod_ext(Cmd++, true, true, 1, &st);
else if (Cmd[1] == 's')
- return ASKDemod_ext(Cmd+=2, TRUE, TRUE, 1, &st);
+ return ASKDemod_ext(Cmd+=2, true, true, 1, &st);
else
- return ASKDemod(Cmd, TRUE, TRUE, 1);
+ return ASKDemod(Cmd, true, true, 1);
}
//by marshmellow
PrintAndLog(" : data rawdemod ab 0 64 1 0 0 a = demod an ask/biph tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
return 0;
}
- return ASKbiphaseDemod(Cmd, TRUE);
+ return ASKbiphaseDemod(Cmd, true);
}
//by marshmellow
//if successful it will push askraw data back to demod buffer ready for emulation
int CmdG_Prox_II_Demod(const char *Cmd)
{
- if (!ASKbiphaseDemod(Cmd, FALSE)){
+ if (!ASKbiphaseDemod(Cmd, false)){
if (g_debugMode) PrintAndLog("Error gProxII: ASKbiphaseDemod failed 1st try");
return 0;
}
PrintAndLog(" : data rawdemod ar 64 1 0 0 a = demod an ask tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
return 0;
}
- return ASKDemod(Cmd, TRUE, FALSE, 0);
+ return ASKDemod(Cmd, true, false, 0);
}
int AutoCorrelate(int window, bool SaveGrph, bool verbose)
return usage_data_autocorr();
int window = 4000; //set default
char grph=0;
- bool updateGrph = FALSE;
+ bool updateGrph = false;
sscanf(Cmd, "%i %c", &window, &grph);
if (window >= GraphTraceLen) {
GraphTraceLen);
return 0;
}
- if (grph == 'g') updateGrph=TRUE;
- return AutoCorrelate(window, updateGrph, TRUE);
+ if (grph == 'g') updateGrph=true;
+ return AutoCorrelate(window, updateGrph, true);
}
int CmdBitsamples(const char *Cmd)
PrintAndLog(" : data rawdemod fs 50 1 10 8 = demod an fsk2a RF/50 tag from GraphBuffer");
return 0;
}
- return FSKrawDemod(Cmd, TRUE);
+ return FSKrawDemod(Cmd, true);
}
//by marshmellow (based on existing demod + holiman's refactor)
PrintAndLog(" : data rawdemod nr 64 1 0 = demod a nrz/direct tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
- return NRZrawDemod(Cmd, TRUE);
+ return NRZrawDemod(Cmd, true);
}
// by marshmellow
PrintAndLog(" : data rawdemod p1 64 1 0 = demod a psk1 tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
- ans = PSKDemod(Cmd, TRUE);
+ ans = PSKDemod(Cmd, true);
//output
if (!ans){
if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
PrintAndLog(" : data rawdemod p2 64 1 0 = demod a psk2 tag from GraphBuffer using a clock of RF/64, inverting output and allowing 0 demod errors");
return 0;
}
- ans=PSKDemod(Cmd, TRUE);
+ ans=PSKDemod(Cmd, true);
if (!ans){
if (g_debugMode) PrintAndLog("Error demoding: %d",ans);
return 0;
#include <stdio.h>
#include <string.h>
#include "proxmark3.h"
-#include "graph.h"
+#include "util.h"
#include "ui.h"
+#include "iso14443crc.h"
+#include "cmdmain.h"
#include "cmdparser.h"
#include "cmdhf.h"
#include "cmdhf14a.h"
int CmdHF14ACmdRaw(const char *cmd) {
UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}};
bool reply=1;
- bool crc = FALSE;
- bool power = FALSE;
- bool active = FALSE;
- bool active_select = FALSE;
+ bool crc = false;
+ bool power = false;
+ bool active = false;
+ bool active_select = false;
uint16_t numbits = 0;
- bool bTimeout = FALSE;
+ bool bTimeout = false;
uint32_t timeout = 0;
- bool topazmode = FALSE;
+ bool topazmode = false;
char buf[5]="";
int i = 0;
uint8_t data[USB_CMD_DATA_SIZE];
if (cmd[i]=='-') {
switch (cmd[i+1]) {
case 'r':
- reply = FALSE;
+ reply = false;
break;
case 'c':
- crc = TRUE;
+ crc = true;
break;
case 'p':
- power = TRUE;
+ power = true;
break;
case 'a':
- active = TRUE;
+ active = true;
break;
case 's':
- active_select = TRUE;
+ active_select = true;
break;
case 'b':
sscanf(cmd+i+2,"%d",&temp);
i-=2;
break;
case 't':
- bTimeout = TRUE;
+ bTimeout = true;
sscanf(cmd+i+2,"%d",&temp);
timeout = temp;
i+=3;
i-=2;
break;
case 'T':
- topazmode = TRUE;
+ topazmode = true;
break;
default:
PrintAndLog("Invalid option");
//-----------------------------------------------------------------------------\r
\r
#include <inttypes.h>\r
-#include "cmdhfmf.h"\r
-#include "./nonce2key/nonce2key.h"\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include "proxmark3.h"\r
+#include "cmdmain.h"\r
+#include "util.h"\r
+#include "ui.h"\r
+#include "mifarehost.h"\r
+#include "mifare.h"\r
+#include "nonce2key/nonce2key.h"\r
+\r
+#define NESTED_SECTOR_RETRY 10 // how often we try mfested() until we give up\r
+\r
\r
static int CmdHelp(const char *Cmd);\r
\r
return 0;\r
}\r
\r
+\r
+typedef struct {\r
+ uint64_t Key[2];\r
+ int foundKey[2];\r
+} sector_t;\r
+\r
+\r
int CmdHF14AMfNested(const char *Cmd)\r
{\r
int i, j, res, iterations;\r
- sector *e_sector = NULL;\r
+ sector_t *e_sector = NULL;\r
uint8_t blockNo = 0;\r
uint8_t keyType = 0;\r
uint8_t trgBlockNo = 0;\r
clock_t time1;\r
time1 = clock();\r
\r
- e_sector = calloc(SectorsCnt, sizeof(sector));\r
+ e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
if (e_sector == NULL) return 1;\r
\r
//test current key and additional standard keys first\r
{\r
uint8_t memBlock[16] = {0x00};\r
uint8_t blockNo = 0;\r
- bool wipeCard = FALSE;\r
+ bool wipeCard = false;\r
int res;\r
\r
if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {\r
#ifndef CMDHFMF_H__\r
#define CMDHFMF_H__\r
\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <ctype.h>\r
-#include "proxmark3.h"\r
-#include "iso14443crc.h"\r
-#include "data.h"\r
-#include "ui.h"\r
-#include "cmdparser.h"\r
-#include "common.h"\r
-#include "util.h"\r
-#include "mifarehost.h"\r
-\r
-int CmdHFMF(const char *Cmd);\r
+extern int CmdHFMF(const char *Cmd);\r
-int CmdHF14AMfDbg(const char* cmd);
-int CmdHF14AMfRdBl(const char* cmd);
-int CmdHF14AMfURdBl(const char* cmd);
-int CmdHF14AMfRdSc(const char* cmd);
-int CmdHF14SMfURdCard(const char* cmd);
-int CmdHF14AMfDump(const char* cmd);
-int CmdHF14AMfRestore(const char* cmd);
-int CmdHF14AMfWrBl(const char* cmd);
-int CmdHF14AMfUWrBl(const char* cmd);
-int CmdHF14AMfChk(const char* cmd);
-int CmdHF14AMifare(const char* cmd);
-int CmdHF14AMfNested(const char* cmd);
-int CmdHF14AMfSniff(const char* cmd);\r
-int CmdHF14AMf1kSim(const char* cmd);\r
-int CmdHF14AMfEClear(const char* cmd);\r
-int CmdHF14AMfEGet(const char* cmd);\r
-int CmdHF14AMfESet(const char* cmd);\r
-int CmdHF14AMfELoad(const char* cmd);\r
-int CmdHF14AMfESave(const char* cmd);\r
-int CmdHF14AMfECFill(const char* cmd);\r
-int CmdHF14AMfEKeyPrn(const char* cmd);\r
-int CmdHF14AMfCSetUID(const char* cmd);\r
-int CmdHF14AMfCSetBlk(const char* cmd);\r
-int CmdHF14AMfCGetBlk(const char* cmd);\r
-int CmdHF14AMfCGetSc(const char* cmd);\r
-int CmdHF14AMfCLoad(const char* cmd);\r
-int CmdHF14AMfCSave(const char* cmd);\r
+extern int CmdHF14AMfDbg(const char* cmd);
+extern int CmdHF14AMfRdBl(const char* cmd);
+extern int CmdHF14AMfURdBl(const char* cmd);
+extern int CmdHF14AMfRdSc(const char* cmd);
+extern int CmdHF14SMfURdCard(const char* cmd);
+extern int CmdHF14AMfDump(const char* cmd);
+extern int CmdHF14AMfRestore(const char* cmd);
+extern int CmdHF14AMfWrBl(const char* cmd);
+extern int CmdHF14AMfUWrBl(const char* cmd);
+extern int CmdHF14AMfChk(const char* cmd);
+extern int CmdHF14AMifare(const char* cmd);
+extern int CmdHF14AMfNested(const char* cmd);
+extern int CmdHF14AMfSniff(const char* cmd);\r
+extern int CmdHF14AMf1kSim(const char* cmd);\r
+extern int CmdHF14AMfEClear(const char* cmd);\r
+extern int CmdHF14AMfEGet(const char* cmd);\r
+extern int CmdHF14AMfESet(const char* cmd);\r
+extern int CmdHF14AMfELoad(const char* cmd);\r
+extern int CmdHF14AMfESave(const char* cmd);\r
+extern int CmdHF14AMfECFill(const char* cmd);\r
+extern int CmdHF14AMfEKeyPrn(const char* cmd);\r
+extern int CmdHF14AMfCSetUID(const char* cmd);\r
+extern int CmdHF14AMfCSetBlk(const char* cmd);\r
+extern int CmdHF14AMfCGetBlk(const char* cmd);\r
+extern int CmdHF14AMfCGetSc(const char* cmd);\r
+extern int CmdHF14AMfCLoad(const char* cmd);\r
+extern int CmdHF14AMfCSave(const char* cmd);\r
\r
#endif\r
//-----------------------------------------------------------------------------
// High frequency MIFARE ULTRALIGHT (C) commands
//-----------------------------------------------------------------------------
-#include <ctype.h>
+
+#include "proxmark3.h"
+#include "usb_cmd.h"
+#include "cmdmain.h"
+#include "ui.h"
#include "loclass/des.h"
#include "cmdhfmfu.h"
#include "cmdhfmf.h"
{
static char dummy[3] = {0x20,0x00,0x00};
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K};
- bool errors = FALSE;
+ bool errors = false;
//uint8_t divisor = 95; //125khz
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
uint8_t bps = 0; // Bits per sample
uint8_t decimation = 0; //How many to keep
bool averaging = 1; // Defaults to true
- bool errors = FALSE;
+ bool errors = false;
int trigger_threshold =-1;//Means no change
uint8_t unsigned_trigg = 0;
// otherwise will need FChigh, FClow, Clock, and bitstream
uint8_t fcHigh=0, fcLow=0, clk=0;
uint8_t invert=0;
- bool errors = FALSE;
+ bool errors = false;
char hexData[32] = {0x00}; // store entered hex data
uint8_t data[255] = {0x00};
int dataLen = 0;
case 'd':
dataLen = param_getstr(Cmd, cmdp+1, hexData);
if (dataLen==0) {
- errors=TRUE;
+ errors=true;
} else {
dataLen = hextobinarray((char *)data, hexData);
}
- if (dataLen==0) errors=TRUE;
+ if (dataLen==0) errors=true;
if (errors) PrintAndLog ("Error getting hex data");
cmdp+=2;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
- errors = TRUE;
+ errors = true;
break;
}
if(errors) break;
}
if(cmdp == 0 && DemodBufferLen == 0)
{
- errors = TRUE;// No args
+ errors = true;// No args
}
//Validations
// needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
uint8_t encoding = 1, separator = 0;
uint8_t clk=0, invert=0;
- bool errors = FALSE;
+ bool errors = false;
char hexData[32] = {0x00};
uint8_t data[255]= {0x00}; // store entered hex data
int dataLen = 0;
case 'd':
dataLen = param_getstr(Cmd, cmdp+1, hexData);
if (dataLen==0) {
- errors=TRUE;
+ errors=true;
} else {
dataLen = hextobinarray((char *)data, hexData);
}
- if (dataLen==0) errors=TRUE;
+ if (dataLen==0) errors=true;
if (errors) PrintAndLog ("Error getting hex data, datalen: %d",dataLen);
cmdp+=2;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
- errors = TRUE;
+ errors = true;
break;
}
if(errors) break;
}
if(cmdp == 0 && DemodBufferLen == 0)
{
- errors = TRUE;// No args
+ errors = true;// No args
}
//Validations
//will need carrier, Clock, and bitstream
uint8_t carrier=0, clk=0;
uint8_t invert=0;
- bool errors = FALSE;
+ bool errors = false;
char hexData[32] = {0x00}; // store entered hex data
uint8_t data[255] = {0x00};
int dataLen = 0;
case 'd':
dataLen = param_getstr(Cmd, cmdp+1, hexData);
if (dataLen==0) {
- errors=TRUE;
+ errors=true;
} else {
dataLen = hextobinarray((char *)data, hexData);
}
- if (dataLen==0) errors=TRUE;
+ if (dataLen==0) errors=true;
if (errors) PrintAndLog ("Error getting hex data");
cmdp+=2;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
- errors = TRUE;
+ errors = true;
break;
}
if (errors) break;
}
if (cmdp == 0 && DemodBufferLen == 0)
{
- errors = TRUE;// No args
+ errors = true;// No args
}
//Validations
}
if (dataLen == 0){ //using DemodBuffer
PrintAndLog("Getting Clocks");
- if (clk==0) clk = GetPskClock("", FALSE, FALSE);
+ if (clk==0) clk = GetPskClock("", false, false);
PrintAndLog("clk: %d",clk);
- if (!carrier) carrier = GetPskCarrier("", FALSE, FALSE);
+ if (!carrier) carrier = GetPskCarrier("", false, false);
PrintAndLog("carrier: %d", carrier);
} else {
setDemodBuf(data, dataLen, 0);
ans=CheckChipType(cmdp);
//test unknown tag formats (raw mode)0
PrintAndLog("\nChecking for Unknown tags:\n");
- ans=AutoCorrelate(4000, FALSE, FALSE);
+ ans=AutoCorrelate(4000, false, false);
if (ans > 0) PrintAndLog("Possible Auto Correlation of %d repeating samples",ans);
- ans=GetFskClock("",FALSE,FALSE);
+ ans=GetFskClock("",false,false);
if (ans != 0){ //fsk
- ans=FSKrawDemod("",TRUE);
+ ans=FSKrawDemod("",true);
if (ans>0) {
PrintAndLog("\nUnknown FSK Modulated Tag Found!");
return 1;
}
}
- bool st = TRUE;
- ans=ASKDemod_ext("0 0 0",TRUE,FALSE,1,&st);
+ bool st = true;
+ ans=ASKDemod_ext("0 0 0",true,false,1,&st);
if (ans>0) {
PrintAndLog("\nUnknown ASK Modulated and Manchester encoded Tag Found!");
PrintAndLog("\nif it does not look right it could instead be ASK/Biphase - try 'data rawdemod ab'");
//-----------------------------------------------------------------------------
// Low frequency COTAG commands
//-----------------------------------------------------------------------------
-#include "cmdlfcotag.h" // COTAG function declarations
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include "proxmark3.h"
+#include "ui.h"
+#include "cmddata.h"
+#include "data.h"
+#include "cmdlfcotag.h"
+#include "lfdemod.h"
+#include "usb_cmd.h"
+#include "cmdmain.h"
static int CmdHelp(const char *Cmd);
#ifndef CMDLFCOTAG_H__
#define CMDLFCOTAG_H__
-#include "proxmark3.h"// Definitions, USB controls, COTAG_BITS
-#include "util.h" // FALSE / TRUE
-#include "cmddata.h" // getSamples
-#include "cmdparser.h"// CmdsParse, CmdsHelp
-#include "cmdmain.h"
-#include "ui.h" // PrintAndLog
-#include "cmdlf.h" // Setconfig
-#include "lfdemod.h" // manrawdecode, bytebits_tobyteLSBF
-
#ifndef COTAG_BITS
#define COTAG_BITS 264
#endif
#define REGULAR_READ_MODE_BLOCK 0xFF\r
\r
// Default configuration\r
-t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = FALSE, .offset = 0x00, .block0 = 0x00, .Q5 = FALSE };\r
+t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = false, .offset = 0x00, .block0 = 0x00, .Q5 = false };\r
\r
t55xx_conf_block_t Get_t55xx_Config(){\r
return config;\r
uint8_t bitRate = 0;\r
uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};\r
uint8_t cmdp = 0;\r
- bool errors = FALSE;\r
+ bool errors = false;\r
while(param_getchar(Cmd, cmdp) != 0x00 && !errors)\r
{\r
tmp = param_getchar(Cmd, cmdp);\r
break;\r
}\r
}\r
- if (i==9) errors = TRUE;\r
+ if (i==9) errors = true;\r
}\r
cmdp+=2;\r
break;\r
config.inverted=0;\r
} else {\r
PrintAndLog("Unknown modulation '%s'", modulation);\r
- errors = TRUE;\r
+ errors = true;\r
}\r
break;\r
case 'i':\r
break;\r
case 'Q':\r
case 'q': \r
- config.Q5 = TRUE;\r
+ config.Q5 = true;\r
cmdp++;\r
break;\r
case 'S':\r
case 's': \r
- config.ST = TRUE;\r
+ config.ST = true;\r
cmdp++;\r
break;\r
default:\r
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));\r
- errors = TRUE;\r
+ errors = true;\r
break;\r
}\r
}\r
switch( config.modulation ){\r
case DEMOD_FSK:\r
snprintf(cmdStr, sizeof(buf),"%d %d", bitRate[config.bitrate], config.inverted );\r
- ans = FSKrawDemod(cmdStr, FALSE);\r
+ ans = FSKrawDemod(cmdStr, false);\r
break;\r
case DEMOD_FSK1:\r
case DEMOD_FSK1a:\r
snprintf(cmdStr, sizeof(buf),"%d %d 8 5", bitRate[config.bitrate], config.inverted );\r
- ans = FSKrawDemod(cmdStr, FALSE);\r
+ ans = FSKrawDemod(cmdStr, false);\r
break;\r
case DEMOD_FSK2:\r
case DEMOD_FSK2a:\r
snprintf(cmdStr, sizeof(buf),"%d %d 10 8", bitRate[config.bitrate], config.inverted );\r
- ans = FSKrawDemod(cmdStr, FALSE);\r
+ ans = FSKrawDemod(cmdStr, false);\r
break;\r
case DEMOD_ASK:\r
snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
- ans = ASKDemod_ext(cmdStr, FALSE, FALSE, 1, &ST);\r
+ ans = ASKDemod_ext(cmdStr, false, false, 1, &ST);\r
break;\r
case DEMOD_PSK1:\r
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
save_restoreGB(1);\r
CmdLtrim("160");\r
snprintf(cmdStr, sizeof(buf),"%d %d 6", bitRate[config.bitrate], config.inverted );\r
- ans = PSKDemod(cmdStr, FALSE);\r
+ ans = PSKDemod(cmdStr, false);\r
//undo trim samples\r
save_restoreGB(0);\r
break;\r
save_restoreGB(1);\r
CmdLtrim("160");\r
snprintf(cmdStr, sizeof(buf),"%d 0 6", bitRate[config.bitrate] );\r
- ans = PSKDemod(cmdStr, FALSE);\r
+ ans = PSKDemod(cmdStr, false);\r
psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
//undo trim samples\r
save_restoreGB(0);\r
break;\r
case DEMOD_NRZ:\r
snprintf(cmdStr, sizeof(buf),"%d %d 1", bitRate[config.bitrate], config.inverted );\r
- ans = NRZrawDemod(cmdStr, FALSE);\r
+ ans = NRZrawDemod(cmdStr, false);\r
break;\r
case DEMOD_BI:\r
case DEMOD_BIa:\r
snprintf(cmdStr, sizeof(buf),"0 %d %d 1", bitRate[config.bitrate], config.inverted );\r
- ans = ASKbiphaseDemod(cmdStr, FALSE);\r
+ ans = ASKbiphaseDemod(cmdStr, false);\r
break;\r
default:\r
- return FALSE;\r
+ return false;\r
}\r
return (bool) ans;\r
}\r
DemodBufferLen = 0x00;\r
\r
// According to datasheet. Always: RF/64, not inverted, Manchester\r
- return (bool) ASKDemod("64 0 1", FALSE, FALSE, 1);\r
+ return (bool) ASKDemod("64 0 1", false, false, 1);\r
}\r
\r
int CmdT55xxDetect(const char *Cmd){\r
- bool errors = FALSE;\r
- bool useGB = FALSE;\r
- bool usepwd = FALSE;\r
+ bool errors = false;\r
+ bool useGB = false;\r
+ bool usepwd = false;\r
uint32_t password = 0;\r
uint8_t cmdp = 0;\r
\r
case 'p':\r
case 'P':\r
password = param_get32ex(Cmd, cmdp+1, 0, 16);\r
- usepwd = TRUE;\r
+ usepwd = true;\r
cmdp += 2;\r
break;\r
case '1':\r
// use Graphbuffer data\r
- useGB = TRUE;\r
+ useGB = true;\r
cmdp++;\r
break;\r
default:\r
t55xx_conf_block_t tests[15];\r
int bitRate=0;\r
uint8_t fc1 = 0, fc2 = 0, clk=0;\r
- if (GetFskClock("", FALSE, FALSE)){ \r
- fskClocks(&fc1, &fc2, &clk, FALSE);\r
- if ( FSKrawDemod("0 0", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if (GetFskClock("", false, false)){ \r
+ fskClocks(&fc1, &fc2, &clk, false);\r
+ if ( FSKrawDemod("0 0", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_FSK;\r
if (fc1==8 && fc2 == 5)\r
tests[hits].modulation = DEMOD_FSK1a;\r
else if (fc1==10 && fc2 == 8)\r
tests[hits].modulation = DEMOD_FSK2;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
- if ( FSKrawDemod("0 1", FALSE) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if ( FSKrawDemod("0 1", false) && test(DEMOD_FSK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_FSK;\r
if (fc1 == 8 && fc2 == 5)\r
tests[hits].modulation = DEMOD_FSK1;\r
else if (fc1 == 10 && fc2 == 8)\r
tests[hits].modulation = DEMOD_FSK2a;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = TRUE;\r
+ tests[hits].inverted = true;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
} else {\r
- clk = GetAskClock("", FALSE, FALSE);\r
+ clk = GetAskClock("", false, false);\r
if (clk>0) {\r
- tests[hits].ST = TRUE;\r
- if ( ASKDemod_ext("0 0 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ tests[hits].ST = true;\r
+ if ( ASKDemod_ext("0 0 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_ASK;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
++hits;\r
}\r
- tests[hits].ST = TRUE;\r
- if ( ASKDemod_ext("0 1 1", FALSE, FALSE, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ tests[hits].ST = true;\r
+ if ( ASKDemod_ext("0 1 1", false, false, 1, &tests[hits].ST) && test(DEMOD_ASK, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_ASK;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = TRUE;\r
+ tests[hits].inverted = true;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
++hits;\r
}\r
- if ( ASKbiphaseDemod("0 0 0 2", FALSE) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
+ if ( ASKbiphaseDemod("0 0 0 2", false) && test(DEMOD_BI, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
tests[hits].modulation = DEMOD_BI;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
- if ( ASKbiphaseDemod("0 0 1 2", FALSE) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
+ if ( ASKbiphaseDemod("0 0 1 2", false) && test(DEMOD_BIa, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5) ) {\r
tests[hits].modulation = DEMOD_BIa;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = TRUE;\r
+ tests[hits].inverted = true;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
}\r
//undo trim from ask\r
//save_restoreGB(0);\r
- clk = GetNrzClock("", FALSE, FALSE);\r
+ clk = GetNrzClock("", false, false);\r
if (clk>0) {\r
- if ( NRZrawDemod("0 0 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if ( NRZrawDemod("0 0 1", false) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_NRZ;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
\r
- if ( NRZrawDemod("0 1 1", FALSE) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if ( NRZrawDemod("0 1 1", false) && test(DEMOD_NRZ, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_NRZ;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = TRUE;\r
+ tests[hits].inverted = true;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
}\r
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)\r
save_restoreGB(1);\r
CmdLtrim("160");\r
- clk = GetPskClock("", FALSE, FALSE);\r
+ clk = GetPskClock("", false, false);\r
if (clk>0) {\r
- if ( PSKDemod("0 0 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if ( PSKDemod("0 0 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_PSK1;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
- if ( PSKDemod("0 1 6", FALSE) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
+ if ( PSKDemod("0 1 6", false) && test(DEMOD_PSK1, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)) {\r
tests[hits].modulation = DEMOD_PSK1;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = TRUE;\r
+ tests[hits].inverted = true;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
// PSK2 - needs a call to psk1TOpsk2.\r
- if ( PSKDemod("0 0 6", FALSE)) {\r
+ if ( PSKDemod("0 0 6", false)) {\r
psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
if (test(DEMOD_PSK2, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
tests[hits].modulation = DEMOD_PSK2;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
} // inverse waves does not affect this demod\r
// PSK3 - needs a call to psk1TOpsk2.\r
- if ( PSKDemod("0 0 6", FALSE)) {\r
+ if ( PSKDemod("0 0 6", false)) {\r
psk1TOpsk2(DemodBuffer, DemodBufferLen);\r
if (test(DEMOD_PSK3, &tests[hits].offset, &bitRate, clk, &tests[hits].Q5)){\r
tests[hits].modulation = DEMOD_PSK3;\r
tests[hits].bitrate = bitRate;\r
- tests[hits].inverted = FALSE;\r
+ tests[hits].inverted = false;\r
tests[hits].block0 = PackBits(tests[hits].offset, 32, DemodBuffer);\r
- tests[hits].ST = FALSE;\r
+ tests[hits].ST = false;\r
++hits;\r
}\r
} // inverse waves does not affect this demod\r
config.Q5 = tests[0].Q5;\r
config.ST = tests[0].ST;\r
printConfiguration( config );\r
- return TRUE;\r
+ return true;\r
}\r
\r
if ( hits > 1) {\r
printConfiguration( tests[i] );\r
}\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
bool testModulation(uint8_t mode, uint8_t modread){\r
switch( mode ){\r
case DEMOD_FSK:\r
- if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return TRUE;\r
+ if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return true;\r
break;\r
case DEMOD_ASK:\r
- if (modread == DEMOD_ASK) return TRUE;\r
+ if (modread == DEMOD_ASK) return true;\r
break;\r
case DEMOD_PSK1:\r
- if (modread == DEMOD_PSK1) return TRUE;\r
+ if (modread == DEMOD_PSK1) return true;\r
break;\r
case DEMOD_PSK2:\r
- if (modread == DEMOD_PSK2) return TRUE;\r
+ if (modread == DEMOD_PSK2) return true;\r
break;\r
case DEMOD_PSK3:\r
- if (modread == DEMOD_PSK3) return TRUE;\r
+ if (modread == DEMOD_PSK3) return true;\r
break;\r
case DEMOD_NRZ:\r
- if (modread == DEMOD_NRZ) return TRUE;\r
+ if (modread == DEMOD_NRZ) return true;\r
break;\r
case DEMOD_BI:\r
- if (modread == DEMOD_BI) return TRUE;\r
+ if (modread == DEMOD_BI) return true;\r
break;\r
case DEMOD_BIa:\r
- if (modread == DEMOD_BIa) return TRUE;\r
+ if (modread == DEMOD_BIa) return true;\r
break; \r
default:\r
- return FALSE;\r
+ return false;\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
bool testQ5Modulation(uint8_t mode, uint8_t modread){\r
switch( mode ){\r
case DEMOD_FSK:\r
- if (modread >= 4 && modread <= 5) return TRUE;\r
+ if (modread >= 4 && modread <= 5) return true;\r
break;\r
case DEMOD_ASK:\r
- if (modread == 0) return TRUE;\r
+ if (modread == 0) return true;\r
break;\r
case DEMOD_PSK1:\r
- if (modread == 1) return TRUE;\r
+ if (modread == 1) return true;\r
break;\r
case DEMOD_PSK2:\r
- if (modread == 2) return TRUE;\r
+ if (modread == 2) return true;\r
break;\r
case DEMOD_PSK3:\r
- if (modread == 3) return TRUE;\r
+ if (modread == 3) return true;\r
break;\r
case DEMOD_NRZ:\r
- if (modread == 7) return TRUE;\r
+ if (modread == 7) return true;\r
break;\r
case DEMOD_BI:\r
- if (modread == 6) return TRUE;\r
+ if (modread == 6) return true;\r
break;\r
default:\r
- return FALSE;\r
+ return false;\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
int convertQ5bitRate(uint8_t bitRateRead) {\r
\r
bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk){\r
\r
- if ( DemodBufferLen < 64 ) return FALSE;\r
+ if ( DemodBufferLen < 64 ) return false;\r
uint8_t si = 0;\r
for (uint8_t idx = 28; idx < 64; idx++){\r
si = idx;\r
if (*fndBitRate < 0) continue;\r
*offset = idx;\r
\r
- return TRUE;\r
+ return true;\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
bool testBitRate(uint8_t readRate, uint8_t clk){\r
\r
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5){\r
\r
- if ( DemodBufferLen < 64 ) return FALSE;\r
+ if ( DemodBufferLen < 64 ) return false;\r
uint8_t si = 0;\r
for (uint8_t idx = 28; idx < 64; idx++){\r
si = idx;\r
//uint8_t nml02 = PackBits(si, 2, DemodBuffer); si += 2;\r
\r
//if extended mode\r
- bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? TRUE : FALSE;\r
+ bool extMode =( (safer == 0x6 || safer == 0x9) && extend) ? true : false;\r
\r
if (!extMode){\r
if (xtRate) continue; //nml01 || nml02 || caused issues on noralys tags\r
if (!testBitRate(bitRate, clk)) continue;\r
*fndBitRate = bitRate;\r
*offset = idx;\r
- *Q5 = FALSE;\r
- return TRUE;\r
+ *Q5 = false;\r
+ return true;\r
}\r
if (testQ5(mode, offset, fndBitRate, clk)) {\r
- *Q5 = TRUE;\r
- return TRUE;\r
+ *Q5 = true;\r
+ return true;\r
}\r
- return FALSE;\r
+ return false;\r
}\r
\r
void printT55xxBlock(const char *blockNum){\r
\r
PrintAndLog("Testing %08X", testpwd);\r
\r
- if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, testpwd)) {\r
+ if ( !AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, testpwd)) {\r
PrintAndLog("Aquireing data from device failed. Quitting");\r
free(keyBlock);\r
return 0;\r
return 0;\r
}\r
\r
- if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, TRUE, i)) {\r
+ if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, i)) {\r
PrintAndLog("Aquireing data from device failed. Quitting");\r
free(keyBlock);\r
return 0;\r
#ifndef CMDMAIN_H__
#define CMDMAIN_H__
+#include <stdint.h>
+#include <stddef.h>
#include "usb_cmd.h"
#include "cmdparser.h"
-void UsbCommandReceived(UsbCommand *UC);
-int CommandReceived(char *Cmd);
-bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
-bool WaitForResponse(uint32_t cmd, UsbCommand* response);
-void clearCommandBuffer();
-command_t* getTopLevelCommandTable();
+
+extern void UsbCommandReceived(UsbCommand *UC);
+extern int CommandReceived(char *Cmd);
+extern bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout);
+extern bool WaitForResponse(uint32_t cmd, UsbCommand* response);
+extern void clearCommandBuffer();
+extern command_t* getTopLevelCommandTable();
+
#endif
#include <stdlib.h> \r
#include <string.h>\r
#include <pthread.h>\r
-#include "mifarehost.h"\r
+\r
+#include "nonce2key/crapto1.h"\r
#include "proxmark3.h"\r
+#include "usb_cmd.h"\r
+#include "cmdmain.h"\r
+#include "ui.h"\r
+#include "util.h"\r
+#include "iso14443crc.h"\r
+#include "mifarehost.h"\r
+\r
+// mifare tracer flags used in mfTraceDecode()\r
+#define TRACE_IDLE 0x00\r
+#define TRACE_AUTH1 0x01\r
+#define TRACE_AUTH2 0x02\r
+#define TRACE_AUTH_OK 0x03\r
+#define TRACE_READ_DATA 0x04\r
+#define TRACE_WRITE_OK 0x05\r
+#define TRACE_WRITE_DATA 0x06\r
+#define TRACE_ERROR 0xFF\r
+\r
\r
// MIFARE\r
+int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
+\r
+ *key = 0;\r
+\r
+ UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
+ memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
+ SendCommand(&c);\r
+\r
+ UsbCommand resp;\r
+ if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
+ if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
+ *key = bytes_to_num(resp.d.asBytes, 6);\r
+ return 0;\r
+}\r
+\r
int compar_int(const void * a, const void * b) {\r
// didn't work: (the result is truncated to 32 bits)\r
//return (*(uint64_t*)b - *(uint64_t*)a);\r
return 0;\r
}\r
\r
-int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key){\r
-\r
- *key = 0;\r
-\r
- UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
- memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
- SendCommand(&c);\r
-\r
- UsbCommand resp;\r
- if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
- if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
- *key = bytes_to_num(resp.d.asBytes, 6);\r
- return 0;\r
-}\r
-\r
// EMULATOR\r
\r
int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
\r
// "MAGIC" CARD\r
\r
-int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
- uint8_t oldblock0[16] = {0x00};\r
- uint8_t block0[16] = {0x00};\r
+int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
+ uint8_t isOK = 0;\r
\r
- int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
- if (old == 0) {\r
- memcpy(block0, oldblock0, 16);\r
- PrintAndLog("old block 0: %s", sprint_hex(block0,16));\r
- } else {\r
- PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
- }\r
+ UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
+ SendCommand(&c);\r
\r
- // fill in the new values\r
- // UID\r
- memcpy(block0, uid, 4); \r
- // Mifare UID BCC\r
- block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
- // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
- if (sak!=NULL)\r
- block0[5]=sak[0];\r
- if (atqa!=NULL) {\r
- block0[6]=atqa[1];\r
- block0[7]=atqa[0];\r
+ UsbCommand resp;\r
+ if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
+ isOK = resp.arg[0] & 0xff;\r
+ memcpy(data, resp.d.asBytes, 16);\r
+ if (!isOK) return 2;\r
+ } else {\r
+ PrintAndLog("Command execute timeout");\r
+ return 1;\r
}\r
- PrintAndLog("new block 0: %s", sprint_hex(block0,16));\r
- return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
+ return 0;\r
}\r
\r
int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params) {\r
return 0;\r
}\r
\r
-int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {\r
- uint8_t isOK = 0;\r
-\r
- UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
- SendCommand(&c);\r
+int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe) {\r
+ uint8_t oldblock0[16] = {0x00};\r
+ uint8_t block0[16] = {0x00};\r
\r
- UsbCommand resp;\r
- if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
- isOK = resp.arg[0] & 0xff;\r
- memcpy(data, resp.d.asBytes, 16);\r
- if (!isOK) return 2;\r
+ int old = mfCGetBlock(0, oldblock0, CSETBLOCK_SINGLE_OPER);\r
+ if (old == 0) {\r
+ memcpy(block0, oldblock0, 16);\r
+ PrintAndLog("old block 0: %s", sprint_hex(block0,16));\r
} else {\r
- PrintAndLog("Command execute timeout");\r
- return 1;\r
+ PrintAndLog("Couldn't get old data. Will write over the last bytes of Block 0.");\r
}\r
- return 0;\r
+\r
+ // fill in the new values\r
+ // UID\r
+ memcpy(block0, uid, 4); \r
+ // Mifare UID BCC\r
+ block0[4] = block0[0]^block0[1]^block0[2]^block0[3];\r
+ // mifare classic SAK(byte 5) and ATQA(byte 6 and 7, reversed)\r
+ if (sak!=NULL)\r
+ block0[5]=sak[0];\r
+ if (atqa!=NULL) {\r
+ block0[6]=atqa[1];\r
+ block0[7]=atqa[0];\r
+ }\r
+ PrintAndLog("new block 0: %s", sprint_hex(block0,16));\r
+ return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER);\r
}\r
\r
// SNIFFER\r
return ((blockN & 0x03) == 0x03);\r
}\r
\r
+int saveTraceCard(void) {\r
+ FILE * f;\r
+ \r
+ if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
+ \r
+ f = fopen(traceFileName, "w+");\r
+ if ( !f ) return 1;\r
+ \r
+ for (int i = 0; i < 64; i++) { // blocks\r
+ for (int j = 0; j < 16; j++) // bytes\r
+ fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
+ fprintf(f,"\n");\r
+ }\r
+ fclose(f);\r
+ return 0;\r
+}\r
+\r
int loadTraceCard(uint8_t *tuid) {\r
FILE * f;\r
char buf[64] = {0x00};\r
return 0;\r
}\r
\r
-int saveTraceCard(void) {\r
- FILE * f;\r
- \r
- if ((!strlen(traceFileName)) || (isTraceCardEmpty())) return 0;\r
- \r
- f = fopen(traceFileName, "w+");\r
- if ( !f ) return 1;\r
- \r
- for (int i = 0; i < 64; i++) { // blocks\r
- for (int j = 0; j < 16; j++) // bytes\r
- fprintf(f, "%02x", *(traceCard + i * 16 + j)); \r
- fprintf(f,"\n");\r
- }\r
- fclose(f);\r
- return 0;\r
-}\r
-\r
int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile) {\r
\r
if (traceCrypto1) \r
// High frequency ISO14443A commands\r
//-----------------------------------------------------------------------------\r
\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-#include "common.h"\r
-#include "cmdmain.h"\r
-#include "ui.h"\r
+#include <stdint.h>\r
+#include <stdbool.h>\r
#include "data.h"\r
-#include "util.h"\r
-#include "nonce2key/nonce2key.h"\r
-#include "nonce2key/crapto1.h"\r
-#include "iso14443crc.h"\r
-\r
-#define MEM_CHUNK 1000000\r
-#define NESTED_SECTOR_RETRY 10\r
\r
// mfCSetBlock work flags\r
#define CSETBLOCK_UID 0x01\r
#define CSETBLOCK_WUPC 0x02\r
#define CSETBLOCK_HALT 0x04\r
-#define CSETBLOCK_INIT_FIELD 0x08\r
-#define CSETBLOCK_RESET_FIELD 0x10\r
-#define CSETBLOCK_SINGLE_OPER 0x1F\r
-\r
-// mifare tracer flags\r
-#define TRACE_IDLE 0x00\r
-#define TRACE_AUTH1 0x01\r
-#define TRACE_AUTH2 0x02\r
-#define TRACE_AUTH_OK 0x03\r
-#define TRACE_READ_DATA 0x04\r
-#define TRACE_WRITE_OK 0x05\r
-#define TRACE_WRITE_DATA 0x06\r
-\r
-#define TRACE_ERROR 0xFF\r
+#define CSETBLOCK_INIT_FIELD 0x08\r
+#define CSETBLOCK_RESET_FIELD 0x10\r
+#define CSETBLOCK_SINGLE_OPER 0x1F\r
\r
-typedef struct {\r
- uint64_t Key[2];\r
- int foundKey[2];\r
-} sector;\r
- \r
extern char logHexFileName[FILE_PATH_SIZE];\r
\r
-int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate);\r
-int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key);\r
+extern int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t * ResultKeys, bool calibrate);\r
+extern int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, uint64_t * key);\r
\r
-int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
-int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
+extern int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount);\r
+extern int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount);\r
\r
-int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe);\r
-int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);\r
-int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);\r
+extern int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, bool wantWipe);\r
+extern int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uint8_t params);\r
+extern int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params);\r
\r
-int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);\r
-int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);\r
+extern int mfTraceInit(uint8_t *tuid, uint8_t *atqa, uint8_t sak, bool wantSaveToEmlFile);\r
+extern int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile);\r
\r
-int isTraceCardEmpty(void);\r
-int isBlockEmpty(int blockN);\r
-int isBlockTrailer(int blockN);\r
-int loadTraceCard(uint8_t *tuid);\r
-int saveTraceCard(void);\r
-int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);\r
+extern int isTraceCardEmpty(void);\r
+extern int isBlockEmpty(int blockN);\r
+extern int isBlockTrailer(int blockN);\r
+extern int loadTraceCard(uint8_t *tuid);\r
+extern int saveTraceCard(void);\r
+extern int tryDecryptWord(uint32_t nt, uint32_t ar_enc, uint32_t at_enc, uint8_t *data, int len);\r
// MIFARE Darkside hack
//-----------------------------------------------------------------------------
-#define __STDC_FORMAT_MACROS
#include <inttypes.h>
+#include <time.h>
#include "nonce2key.h"
#include "mifarehost.h"
#include "ui.h"
+#include "util.h"
int compar_state(const void * a, const void * b) {
// didn't work: (the result is truncated to 32 bits)
uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
uint32_t ar1_enc = data.ar2; // second encrypted reader response
clock_t t1 = clock();
- bool isSuccess = FALSE;
+ bool isSuccess = false;
uint8_t counter=0;
s = lfsr_recovery32(ar0_enc ^ prng_successor(nt, 64), 0);
uint32_t nt1 = data.nonce2; // second tag challenge (nonce)
uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
uint32_t ar1_enc = data.ar2; // second encrypted reader response
- bool isSuccess = FALSE;
+ bool isSuccess = false;
int counter = 0;
//PrintAndLog("Enter mfkey32_moebius");
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
-#define TRUE 1
-#define FALSE 0
#define EVEN 0
#define ODD 1
if (!fgets(buffer, sizeof(buffer), maps))
break;
- if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
+ if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
{
uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
if (low <= addr && addr <= high)