fix: TRUE/FALSE -> bools

fix: 'iclass'  filepath 255, to use FILE_PATH_SIZE
fix: unified params test
This commit is contained in:
iceman1001 2017-07-14 20:54:11 +02:00
commit e8015142cd
15 changed files with 129 additions and 176 deletions

View file

@ -87,9 +87,26 @@ static uint8_t calculateLRC( uint8_t* bytes, uint8_t len) {
LRC ^= bytes[i];
return LRC;
}
/*
static uint16_t matrixadd ( uint8_t* bytes, uint8_t len){
-----------
0x9c | 1001 1100
0x97 | 1001 0111
0x72 | 0111 0010
0x5e | 0101 1110
-----------------
C32F 9d74
return 0;
}
*/
/*
static uint16_t shiftadd ( uint8_t* bytes, uint8_t len){
return 0;
}
*/
static uint16_t calcSumCrumbAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum += CRUMB(bytes[i], 0);
sum += CRUMB(bytes[i], 2);
@ -103,7 +120,7 @@ static uint16_t calcSumCrumbAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask)
return (~calcSumCrumbAdd(bytes, len, mask) & mask);
}
static uint16_t calcSumNibbleAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum += NIBBLE_LOW(bytes[i]);
sum += NIBBLE_HIGH(bytes[i]);
@ -115,7 +132,7 @@ static uint16_t calcSumNibbleAddOnes( uint8_t* bytes, uint8_t len, uint32_t mask
return (~calcSumNibbleAdd(bytes, len, mask) & mask);
}
static uint16_t calcSumCrumbXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum ^= CRUMB(bytes[i], 0);
sum ^= CRUMB(bytes[i], 2);
@ -126,7 +143,7 @@ static uint16_t calcSumCrumbXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
return sum;
}
static uint16_t calcSumNibbleXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum ^= NIBBLE_LOW(bytes[i]);
sum ^= NIBBLE_HIGH(bytes[i]);
@ -135,14 +152,14 @@ static uint16_t calcSumNibbleXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
return sum;
}
static uint16_t calcSumByteXor( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++)
sum ^= bytes[i];
sum &= mask;
return sum;
}
static uint16_t calcSumByteAdd( uint8_t* bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++)
sum += bytes[i];
sum &= mask;
@ -301,7 +318,7 @@ int CmdAnalyseCHKSUM(const char *Cmd){
int len = 0;
memset(data, 0x0, sizeof(data));
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'b':
case 'B':
@ -328,10 +345,9 @@ int CmdAnalyseCHKSUM(const char *Cmd){
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_analyse_checksum();
if (errors || cmdp == 0 ) return usage_analyse_checksum();
if (useHeader) {
PrintAndLog(" add | sub | add 1's compl | sub 1's compl | xor");

View file

@ -295,10 +295,8 @@ int CmdPrintDemodBuff(const char *Cmd)
uint32_t offset = 0; //could be size_t but no param_get16...
uint32_t length = 512;
char cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_data_printdemodbuf();
@ -324,10 +322,9 @@ int CmdPrintDemodBuff(const char *Cmd)
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_data_printdemodbuf();
if (errors) return usage_data_printdemodbuf();
if (DemodBufferLen == 0) {
PrintAndLog("Demodbuffer is empty");

View file

@ -458,7 +458,6 @@ uint8_t iso14443A_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
* 1 : CRC-command, CRC ok
* 2 : Not crc-command
*/
uint8_t iso14443B_CRC_check(bool isResponse, uint8_t* data, uint8_t len)
{
uint8_t b1,b2;
@ -706,7 +705,6 @@ uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *trace, ui
case ISO_14443B: annotateIso14443b(explanation,sizeof(explanation),frame,data_len); break;
case TOPAZ: annotateTopaz(explanation,sizeof(explanation),frame,data_len); break;
case ISO_7816_4: annotateIso7816(explanation,sizeof(explanation),frame,data_len); break;
default: break;
}
}
@ -941,7 +939,7 @@ static command_t CommandTable[] = {
{"tune", CmdHFTune, 0, "Continuously measure HF antenna tuning"},
{"list", CmdHFList, 1, "List protocol data in trace buffer"},
{"search", CmdHFSearch, 1, "Search for known HF tags [preliminary]"},
{"snoop", CmdHFSnoop, 0, "<samples to skip (10000)> <triggers to skip (1)> Generic LF/HF Snoop in Testing stage"},
{"snoop", CmdHFSnoop, 0, "<samples to skip (10000)> <triggers to skip (1)> Generic HF Snoop"},
{NULL, NULL, 0, NULL}
};

View file

@ -12,7 +12,7 @@
#define CMDHF_H__
int CmdHF(const char *Cmd);
int CmdHFTune(const char *Cmd);
int CmdHFList(const char *Cmd);
int CmdHFSearch(const char *Cmd);
extern int CmdHFTune(const char *Cmd);
extern int CmdHFList(const char *Cmd);
extern int CmdHFSearch(const char *Cmd);
#endif

View file

@ -471,7 +471,7 @@ int CmdHF14ASim(const char *Cmd) {
bool verbose = false;
nonces_t data[1];
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -520,11 +520,10 @@ int CmdHF14ASim(const char *Cmd) {
errors = true;
break;
}
if(errors) break;
}
//Validations
if (errors) return usage_hf_14a_sim();
if (errors || cmdp == 0) return usage_hf_14a_sim();
if ( useUIDfromEML )
flags |= FLAG_UID_IN_EMUL;

View file

@ -135,7 +135,7 @@ int CmdHF14BSnoop(const char *Cmd) {
}
int CmdHF14BCmdRaw (const char *Cmd) {
bool reply = TRUE, power = FALSE, select = FALSE;
bool reply = true, power = false, select = false;
char buf[5] = "";
int i = 0;
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
@ -157,7 +157,7 @@ int CmdHF14BCmdRaw (const char *Cmd) {
return usage_hf_14b_raw();
case 'r':
case 'R':
reply = FALSE;
reply = false;
break;
case 'c':
case 'C':
@ -165,11 +165,11 @@ int CmdHF14BCmdRaw (const char *Cmd) {
break;
case 'p':
case 'P':
power = TRUE;
power = true;
break;
case 's':
case 'S':
select = TRUE;
select = true;
if (Cmd[i+2]=='s' || Cmd[i+2]=='S') {
flags |= ISO14B_SELECT_SR;
++i;
@ -218,7 +218,7 @@ int CmdHF14BCmdRaw (const char *Cmd) {
if (!reply) return 1;
bool success = TRUE;
bool success = true;
// get back iso14b_card_select_t, don't print it.
if (select)
success = waitCmd(FALSE);
@ -375,7 +375,7 @@ static void print_st_general_info(uint8_t *data, uint8_t len){
// 14b get and print Full Info (as much as we know)
bool HF14B_Std_Info(bool verbose){
//add more info here
return FALSE;
return false;
}
// SRx get and print full info (needs more info...)
@ -388,7 +388,7 @@ bool HF14B_ST_Info(bool verbose){
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
if (verbose) PrintAndLog("timeout while waiting for reply.");
return FALSE;
return false;
}
iso14b_card_select_t card;
@ -419,23 +419,23 @@ bool HF14B_ST_Info(bool verbose){
// if (datalen != resplen || !crc) return rawClose();
//print_ST_Lock_info(data[5]>>2);
switch_off_field_14b();
return TRUE;
return true;
}
// get and print all info known about any known 14b tag
bool HF14BInfo(bool verbose){
// try std 14b (atqb)
if (HF14B_Std_Info(verbose)) return TRUE;
if (HF14B_Std_Info(verbose)) return true;
// try st 14b
if (HF14B_ST_Info(verbose)) return TRUE;
if (HF14B_ST_Info(verbose)) return true;
// try unknown 14b read commands (to be identified later)
// could be read of calypso, CEPAS, moneo, or pico pass.
if (verbose) PrintAndLog("no 14443B tag found");
return FALSE;
return false;
}
// menu command to get and print all info known about any known 14b tag
@ -449,7 +449,7 @@ int CmdHF14Binfo(const char *Cmd){
bool HF14B_ST_Reader(bool verbose){
bool isSuccess = FALSE;
bool isSuccess = false;
switch_on_field_14b();
@ -460,7 +460,7 @@ bool HF14B_ST_Reader(bool verbose){
UsbCommand resp;
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
if (verbose) PrintAndLog("timeout while waiting for reply.");
return FALSE;
return false;
}
iso14b_card_select_t card;
@ -471,7 +471,7 @@ bool HF14B_ST_Reader(bool verbose){
switch( status ){
case 0:
print_st_general_info(card.uid, card.uidlen);
isSuccess = TRUE;
isSuccess = true;
break;
case 1:
if (verbose) PrintAndLog("iso14443-3 random chip id fail");
@ -493,7 +493,7 @@ bool HF14B_ST_Reader(bool verbose){
bool HF14B_Std_Reader(bool verbose){
bool isSuccess = FALSE;
bool isSuccess = false;
// 14b get and print UID only (general info)
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_STD | ISO14B_DISCONNECT, 0, 0}};
@ -503,7 +503,7 @@ bool HF14B_Std_Reader(bool verbose){
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
if (verbose) PrintAndLog("timeout while waiting for reply.");
return FALSE;
return false;
}
iso14b_card_select_t card;
@ -517,7 +517,7 @@ bool HF14B_Std_Reader(bool verbose){
PrintAndLog(" ATQB : %s", sprint_hex(card.atqb, sizeof(card.atqb)));
PrintAndLog(" CHIPID : %02X", card.chipid);
print_atqb_resp(card.atqb, card.cid);
isSuccess = TRUE;
isSuccess = true;
break;
case 2:
if (verbose) PrintAndLog("iso14443-3 ATTRIB fail");
@ -571,7 +571,7 @@ bool HF14B_Other_Reader(){
// PrintAndLog ("Unknown tag type answered to a 0x0A command ans:");
// // PrintAndLog ("%s", sprint_hex(data, datalen));
// rawClose();
// return TRUE;
// return true;
// }
// c.arg1 = 1;
@ -586,28 +586,28 @@ bool HF14B_Other_Reader(){
// PrintAndLog ("Unknown tag type answered to a 0x0C command ans:");
// PrintAndLog ("%s", sprint_hex(data, datalen));
// rawClose();
// return TRUE;
// return true;
// }
// rawClose();
return FALSE;
return false;
}
// get and print general info about all known 14b chips
bool HF14BReader(bool verbose){
// try std 14b (atqb)
if (HF14B_Std_Reader(verbose)) return TRUE;
if (HF14B_Std_Reader(verbose)) return true;
// try ST Microelectronics 14b
if (HF14B_ST_Reader(verbose)) return TRUE;
if (HF14B_ST_Reader(verbose)) return true;
// try unknown 14b read commands (to be identified later)
// could be read of calypso, CEPAS, moneo, or pico pass.
if (HF14B_Other_Reader()) return TRUE;
if (HF14B_Other_Reader()) return true;
if (verbose) PrintAndLog("no 14443B tag found");
return FALSE;
return false;
}
// menu command to get and print general info about all known 14b chips
@ -804,7 +804,7 @@ int srix4kValid(const char *Cmd){
bool waitCmd(bool verbose) {
bool crc = FALSE;
bool crc = false;
uint8_t b1 = 0, b2 = 0;
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
uint8_t status = 0;
@ -814,7 +814,7 @@ bool waitCmd(bool verbose) {
if (WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
status = (resp.arg[0] & 0xFF);
if ( status > 0 ) return FALSE;
if ( status > 0 ) return false;
len = (resp.arg[1] & 0xFFFF);
@ -836,10 +836,10 @@ bool waitCmd(bool verbose) {
PrintAndLog("[LEN %u] %s", len, sprint_hex(data, len) );
}
}
return TRUE;
return true;
} else {
PrintAndLog("timeout while waiting for reply.");
return FALSE;
return false;
}
}

View file

@ -200,7 +200,7 @@ int CmdHfEmvELoad(const char *Cmd) {
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -220,11 +220,9 @@ int CmdHfEmvELoad(const char *Cmd) {
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_hf_emv_eload();
if (errors || cmdp == 0) return usage_hf_emv_eload();
// open file
f = fopen(filename,"r");
@ -267,7 +265,7 @@ int CmdHfEmvDump(const char *Cmd){
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -277,11 +275,9 @@ int CmdHfEmvDump(const char *Cmd){
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_hf_emv_dump();
if (errors) return usage_hf_emv_dump();
UsbCommand c = {CMD_EMV_DUMP_CARD, {0, 0, 0}};
clearCommandBuffer();
@ -298,7 +294,7 @@ int CmdHfEmvSim(const char *Cmd) {
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -308,11 +304,9 @@ int CmdHfEmvSim(const char *Cmd) {
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_hf_emv_sim();
if (errors) return usage_hf_emv_sim();
UsbCommand c = {CMD_EMV_SIM, {0,0,0}};
clearCommandBuffer();

View file

@ -350,7 +350,7 @@ int HFiClassReader(const char *Cmd, bool loop, bool verbose) {
int CmdHFiClassReader(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (cmdp == 'h' || cmdp == 'H') return usage_hf_iclass_reader();
bool findone = (cmdp == '1') ? FALSE : TRUE;
bool findone = (cmdp == '1') ? false : true;
return HFiClassReader(Cmd, findone, true);
}
@ -683,10 +683,8 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_dump();
@ -754,10 +752,9 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_dump();
}
if (cmdp < 2) return usage_hf_iclass_dump();
if (errors || cmdp < 2) return usage_hf_iclass_dump();
// if no debit key given try credit key on AA1 (not for iclass but for some picopass this will work)
if (!have_debit_key && have_credit_key) use_credit_key = true;
@ -885,7 +882,6 @@ int CmdHFiClassReader_Dump(const char *Cmd) {
// print the dump
printf("------+--+-------------------------+\n");
printf("CSN |00| %s|\n", sprint_hex(tag_data, 8));
//printIclassDumpContents(tag_data, 1, (gotBytes/8)-1, gotBytes-8);
printIclassDumpContents(tag_data, 1, (gotBytes/8), gotBytes);
if (filename[0] == 0){
@ -940,10 +936,8 @@ int CmdHFiClass_WriteBlock(const char *Cmd) {
bool rawkey= false;
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_writeblock();
@ -1003,10 +997,9 @@ int CmdHFiClass_WriteBlock(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_writeblock();
}
if (errors || cmdp < 6) return usage_hf_iclass_writeblock();
if (cmdp < 6) return usage_hf_iclass_writeblock();
int ans = WriteBlock(blockno, bldata, KEY, use_credit_key, elite, rawkey, true);
ul_switch_off_field();
return ans;
@ -1026,10 +1019,8 @@ int CmdHFiClassCloneTag(const char *Cmd) {
bool rawkey = false;
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_clone();
@ -1097,10 +1088,9 @@ int CmdHFiClassCloneTag(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_clone();
}
if (cmdp < 8) return usage_hf_iclass_clone();
if (errors || cmdp < 8) return usage_hf_iclass_clone();
FILE *f;
@ -1214,10 +1204,8 @@ int CmdHFiClass_ReadBlock(const char *Cmd) {
bool rawkey = false;
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_readblock();
@ -1268,10 +1256,8 @@ int CmdHFiClass_ReadBlock(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_readblock();
}
if (cmdp < 4) return usage_hf_iclass_readblock();
if (errors || cmdp < 4) return usage_hf_iclass_readblock();
return ReadBlock(KEY, blockno, keyType, elite, rawkey, true);
}
@ -1294,7 +1280,7 @@ int CmdHFiClass_loclass(const char *Cmd) {
PrintAndLog(" ... totalling N*24 bytes");
return 0;
}
char fileName[255] = {0};
char fileName[FILE_PATH_SIZE] = {0};
if(opt == 'f') {
if(param_getstr(Cmd, 1, fileName) > 0) {
return bruteforceFileNoKeys(fileName);
@ -1449,10 +1435,8 @@ int CmdHFiClassCalcNewKey(const char *Cmd) {
bool elite = false;
bool errors = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_calc_newkey();
@ -1514,11 +1498,9 @@ int CmdHFiClassCalcNewKey(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_calc_newkey();
}
if (cmdp < 4) return usage_hf_iclass_calc_newkey();
if (errors || cmdp < 4) return usage_hf_iclass_calc_newkey();
if (!givenCSN)
if (!select_only(CSN, CCNR, false, true))
return 0;
@ -1598,10 +1580,8 @@ int CmdHFiClassManageKeys(const char *Cmd) {
char tempStr[20];
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00)
{
switch(param_getchar(Cmd, cmdp))
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_hf_iclass_managekeys();
@ -1655,8 +1635,9 @@ int CmdHFiClassManageKeys(const char *Cmd) {
errors = true;
break;
}
if(errors) return usage_hf_iclass_managekeys();
}
if (errors) return usage_hf_iclass_managekeys();
if (operation == 0){
PrintAndLog("no operation specified (load, save, or print)\n");
return usage_hf_iclass_managekeys();

View file

@ -541,7 +541,7 @@ int CmdLegicRfWrite(const char *Cmd) {
int len = 0, bg, en;
uint32_t offset = 0, IV = 0x55;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'd':
case 'D':
@ -602,10 +602,9 @@ int CmdLegicRfWrite(const char *Cmd) {
errors = true;
break;
}
if (errors) break;
}
//Validations
if (errors){
if (errors || cmdp == 0){
if (data)
free(data);
return usage_legic_write();
@ -676,7 +675,7 @@ int CmdLegicCalcCrc(const char *Cmd){
int len = 0;
int bg, en;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'd':
case 'D':
@ -733,10 +732,9 @@ int CmdLegicCalcCrc(const char *Cmd){
errors = true;
break;
}
if (errors) break;
}
//Validations
if (errors){
if (errors || cmdp == 0){
if (data) free(data);
return usage_legic_calccrc();
}
@ -848,7 +846,7 @@ int CmdLegicDump(const char *Cmd){
memset(filename, 0, sizeof(filename));
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -867,11 +865,9 @@ int CmdLegicDump(const char *Cmd){
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_legic_dump();
if (errors) return usage_legic_dump();
// tagtype
legic_card_select_t card;
@ -932,6 +928,7 @@ int CmdLegicDump(const char *Cmd){
return 5;
}
fwrite(data, 1, readlen, f);
fflush(f);
fclose(f);
free(data);
PrintAndLog("Wrote %d bytes to %s", readlen, filename);
@ -944,13 +941,13 @@ int CmdLegicRestore(const char *Cmd){
char filename[FILE_PATH_SIZE] = {0x00};
char *fnameptr = filename;
size_t fileNlen = 0;
bool errors = true;
bool errors = false;
uint16_t numofbytes;
uint8_t cmdp = 0;
memset(filename, 0, sizeof(filename));
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
@ -961,8 +958,6 @@ int CmdLegicRestore(const char *Cmd){
fileNlen = param_getstr(Cmd, cmdp+1, filename);
if (!fileNlen)
errors = true;
else
errors = false;
if (fileNlen > FILE_PATH_SIZE-5)
fileNlen = FILE_PATH_SIZE-5;
@ -973,11 +968,9 @@ int CmdLegicRestore(const char *Cmd){
errors = true;
break;
}
if (errors) break;
}
//Validations
if(errors) return usage_legic_restore();
if (errors || cmdp == 0) return usage_legic_restore();
// tagtype
legic_card_select_t card;

View file

@ -1400,7 +1400,7 @@ int CmdHF14AMfChk(const char *Cmd) {
res = mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6*c], &key64);
if (!res) {
e_sector[i].Key[trgKeyType] = key64;
e_sector[i].foundKey[trgKeyType] = TRUE;
e_sector[i].foundKey[trgKeyType] = true;
break;
}
}
@ -1566,7 +1566,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
bool setEmulatorMem = false;
nonces_t data[1];
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'e':
case 'E':
@ -1612,10 +1612,9 @@ int CmdHF14AMf1kSim(const char *Cmd) {
errors = true;
break;
}
if(errors) break;
}
//Validations
if(errors) return usage_hf14_mf1ksim();
if (errors || cmdp == 0) return usage_hf14_mf1ksim();
PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) "
, (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen>>1)
@ -2403,7 +2402,7 @@ int CmdHF14AMfCSave(const char *Cmd) {
memset(filename, 0, sizeof(filename));
memset(buf, 0, sizeof(buf));
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
ctmp = param_getchar(Cmd, cmdp);
switch(ctmp) {
case 'e':
@ -2462,14 +2461,13 @@ int CmdHF14AMfCSave(const char *Cmd) {
errors = true;
break;
}
if (errors) break;
}
// must have filename when saving.
if (!hasname && !fillFromEmulator) errors = true;
//Validations
if (errors) return usage_hf14_csave();
if (errors || cmdp == 0) return usage_hf14_csave();
if (fillFromEmulator) {
// put into emulator

View file

@ -131,7 +131,7 @@ int CmdLFCommandRead(const char *Cmd) {
uint8_t cmdp = 0;
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, {0,0,0}};
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
return usage_lf_cmdread();
@ -163,13 +163,10 @@ int CmdLFCommandRead(const char *Cmd) {
errors = 1;
break;
}
if(errors) break;
}
// No args
if (cmdp == 0) errors = true;
//Validations
if (errors) return usage_lf_cmdread();
if (errors || cmdp == 0) return usage_lf_cmdread();
// zero and one lengths
c.arg[1] = (uint32_t)(zero << 16 | one);
@ -486,7 +483,7 @@ int CmdLFSetConfig(const char *Cmd) {
uint8_t unsigned_trigg = 0;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
return usage_lf_config();
@ -527,14 +524,10 @@ int CmdLFSetConfig(const char *Cmd) {
errors = 1;
break;
}
if(errors) break;
}
// No args
if (cmdp == 0) errors = 1;
//Validations
if (errors) return usage_lf_config();
if (errors || cmdp == 0) return usage_lf_config();
//Bps is limited to 8
if (bps >> 4) bps = 8;
@ -552,25 +545,24 @@ int CmdLFRead(const char *Cmd) {
if (offline) return 0;
bool errors = FALSE;
bool arg1 = FALSE;
bool errors = false;
bool arg1 = false;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
case 'H':
return usage_lf_read();
case 's':
case 'S':
arg1 = TRUE;
arg1 = true;
cmdp++;
break;
default:
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = TRUE;
errors = true;
break;
}
if(errors) break;
}
//Validations
@ -660,7 +652,7 @@ int CmdLFfskSim(const char *Cmd)
int dataLen = 0;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)){
case 'h':
return usage_lf_simfsk();
@ -700,15 +692,13 @@ int CmdLFfskSim(const char *Cmd)
errors = true;
break;
}
if(errors) break;
}
// No args
if(cmdp == 0 && DemodBufferLen == 0)
errors = true;
if (cmdp == 0 && DemodBufferLen == 0) return usage_lf_simfsk();
//Validations
if(errors) return usage_lf_simfsk();
if (errors) return usage_lf_simfsk();
if (dataLen == 0){ //using DemodBuffer
if (clk == 0 || fcHigh == 0 || fcLow == 0){ //manual settings must set them all
@ -757,7 +747,7 @@ int CmdLFaskSim(const char *Cmd)
int dataLen = 0;
uint8_t cmdp = 0;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'H':
case 'h': return usage_lf_simask();
@ -801,15 +791,13 @@ int CmdLFaskSim(const char *Cmd)
errors = true;
break;
}
if(errors) break;
}
// No args
if(cmdp == 0 && DemodBufferLen == 0)
errors = true;
if (cmdp == 0 && DemodBufferLen == 0) return usage_lf_simask();
//Validations
if(errors) return usage_lf_simask();
if (errors) return usage_lf_simask();
if (dataLen == 0){ //using DemodBuffer
if (clk == 0)
@ -854,7 +842,7 @@ int CmdLFpskSim(const char *Cmd) {
uint8_t cmdp = 0;
uint8_t pskType = 1;
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
return usage_lf_simpsk();
@ -898,7 +886,6 @@ int CmdLFpskSim(const char *Cmd) {
errors = true;
break;
}
if (errors) break;
}
// No args
if (cmdp == 0 && DemodBufferLen == 0)

View file

@ -233,7 +233,7 @@ int CmdIOClone(const char *Cmd) {
static command_t CommandTable[] = {
{"help", CmdHelp, 1, "This help"},
//{"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
// {"demod", CmdIOProxDemod, 1, "Demodulate Stream"},
{"fskdemod",CmdIODemodFSK, 0, "['1'] Realtime IO FSK demodulator (option '1' for one tag only)"},
{"sim", CmdIOSim, 0, "<version> <facility-code> <card number> -- IOProx tag simulator"},
{"clone", CmdIOClone, 0, "<version> <facility-code> <card number> <Q5> -- Clone IOProx to T55x7"},

View file

@ -47,7 +47,7 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
int stringlen = 0;
memset(id, 0x00, sizeof(id));
while(param_getchar(Cmd, cmdp) != 0x00) {
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
switch(param_getchar(Cmd, cmdp)) {
case 'h':
return -1;
@ -74,13 +74,9 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
errors = 1;
break;
}
if(errors) break;
}
// No args
if(cmdp == 0) errors = 1;
//Validations
if(errors) return -1;
if (errors || cmdp == 0) return -1;
if (!hex) {
for (int index =0; index < strlen(id); ++index) {

View file

@ -189,11 +189,9 @@ int CmdT55xxSetConfig(const char *Cmd) {
uint8_t rates[9] = {8,16,32,40,50,64,100,128,0};
uint8_t cmdp = 0;
bool errors = false;
while(param_getchar(Cmd, cmdp) != 0x00 && !errors)
{
while(param_getchar(Cmd, cmdp) != 0x00 && !errors) {
tmp = param_getchar(Cmd, cmdp);
switch(tmp)
{
switch(tmp) {
case 'h':
case 'H':
return usage_t55xx_config();

View file

@ -162,20 +162,16 @@ int CmdRun(const char *Cmd)
printf("--- Executing: %s%s, args '%s'\n", script_name, suffix, arguments);
// run the Lua script
int error = luaL_loadfile(lua_state, script_path);
if(!error)
{
if (!error) {
lua_pushstring(lua_state, arguments);
lua_setglobal(lua_state, "args");
//Call it with 0 arguments
error = lua_pcall(lua_state, 0, LUA_MULTRET, 0); // once again, returns non-0 on error,
}
if(error) // if non-0, then an error
if (error) // if non-0, then an error
{
// the top of the stack should be the error string
if (!lua_isstring(lua_state, lua_gettop(lua_state)))