Merge branch 'master' into allin

update 201119
This commit is contained in:
tharexde 2020-11-19 23:21:19 +01:00
commit e642c05e5c
9 changed files with 259 additions and 164 deletions

View file

@ -2082,9 +2082,10 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card");
errormsg = MAGIC_UID; errormsg = MAGIC_UID;
mifare_classic_halt_ex(NULL);
break;
} }
mifare_classic_halt_ex(NULL); mifare_classic_halt_ex(NULL);
break;
} }
// wipe tag, fill it with zeros // wipe tag, fill it with zeros

View file

@ -1132,8 +1132,6 @@ e2a9e88bfe16
aade86b1f9c1 aade86b1f9c1
5ea088c824c9 5ea088c824c9
c67beb41ffbf c67beb41ffbf
5ea088c824c9
c67beb41ffbf
b84d52971107 b84d52971107
52b0d3f6116e 52b0d3f6116e
# #
@ -1209,3 +1207,72 @@ FEE2A3FBC5B6
0602721E8F06 0602721E8F06
FC0B50AF8700 FC0B50AF8700
F7BA51A9434E F7BA51A9434E
#
# eskart
# eskisehir transport card
E902395C1744
4051A85E7F2D
7357EBD483CC
D8BA1AA9ABA0
76939DDD9E97
3BF391815A8D
#
# muzekart
# museum card for turkey
7C87013A648A
E8794FB14C63
9F97C182585B
EC070A52E539
C229CE5123D5
E495D6E69D9C
26BF1A68B00F
B1D3BC5A7CCA
734EBE504CE8
974A36E2B1BA
C197AE6D6990
4D80A10649DF
037F64F470AD
C9CD8D7C65E5
B70B1957FE71
CE7712C5071D
C0AD1B72921A
45FEE09C1D06
E592ED478E59
F3C1F1DB1D83
704A81DDACED
89E00BC444EF
AFAAFCC40DEC
ECC58C5D34CA
57D83754711D
D0DDDF2933EC
240F0BB84681
9E7168064993
2F8A867B06B4
#
# bursakart
# bursa transport card
#
A0A1A2A3A4A5
755D49191A78
DAC7E0CBA8FD
68D3263A8CD6
865B6472B1C0
0860318A3A89
1927A45A83D3
B2FE3B2875A6
#
# playland
# maltepe park
#
ABCC1276FCB0
AABAFFCC7612
#
# lunasan
# kocaeli fair
#
26107E7006A0
#
# gamefactory
# ozdilek
#
17D071403C20

View file

@ -28,6 +28,7 @@
If you have access to datasheet, le me know! If you have access to datasheet, le me know!
LTO w Type info 00 01 has 101 blocks. LTO w Type info 00 01 has 101 blocks.
LTO w Type info 00 02 has 95 blocks.
LTO w Type info 00 03 has 255 blocks. LTO w Type info 00 03 has 255 blocks.
LTO w Type info 00 xx has NN blocks. LTO w Type info 00 xx has NN blocks.
*/ */
@ -242,18 +243,18 @@ static int CmdHfLTOList(const char *Cmd) {
return CmdTraceList(args); return CmdTraceList(args);
} }
static int lto_rdbl(uint8_t blk, uint8_t *block_responce, uint8_t *block_cnt_responce, bool verbose) { static int lto_rdbl(uint8_t blk, uint8_t *block_response, uint8_t *block_cnt_response, bool verbose) {
uint16_t resp_len = 18; uint16_t resp_len = 18;
uint8_t rdbl_cmd[] = {0x30, blk}; uint8_t rdbl_cmd[] = {0x30, blk};
uint8_t rdbl_cnt_cmd[] = {0x80}; uint8_t rdbl_cnt_cmd[] = {0x80};
int status = lto_send_cmd_raw(rdbl_cmd, sizeof(rdbl_cmd), block_responce, &resp_len, true, false, verbose); int status = lto_send_cmd_raw(rdbl_cmd, sizeof(rdbl_cmd), block_response, &resp_len, true, false, verbose);
if (status == PM3_ETIMEOUT || status == PM3_ESOFT) { if (status == PM3_ETIMEOUT || status == PM3_ESOFT) {
return PM3_EWRONGANSWER; // READ BLOCK failed return PM3_EWRONGANSWER; // READ BLOCK failed
} }
status = lto_send_cmd_raw(rdbl_cnt_cmd, sizeof(rdbl_cnt_cmd), block_cnt_responce, &resp_len, false, false, verbose); status = lto_send_cmd_raw(rdbl_cnt_cmd, sizeof(rdbl_cnt_cmd), block_cnt_response, &resp_len, false, false, verbose);
if (status == PM3_ETIMEOUT || status == PM3_ESOFT) { if (status == PM3_ETIMEOUT || status == PM3_ESOFT) {
return PM3_EWRONGANSWER; // READ BLOCK CONTINUE failed return PM3_EWRONGANSWER; // READ BLOCK CONTINUE failed
} }

View file

@ -42,6 +42,15 @@
#define status(x) ( ((uint16_t)(0x91<<8)) + (uint16_t)x ) #define status(x) ( ((uint16_t)(0x91<<8)) + (uint16_t)x )
#ifndef DropFieldDesfire
#define DropFieldDesfire() { \
clearCommandBuffer(); \
SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); \
tag->rf_field_on = false; \
PrintAndLogEx(DEBUG, "field dropped"); \
}
#endif
struct desfire_key default_key = {0}; struct desfire_key default_key = {0};
uint8_t desdefaultkeys[3][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //Official uint8_t desdefaultkeys[3][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //Official
@ -86,7 +95,7 @@ typedef struct mfdes_data {
uint8_t *data; uint8_t *data;
} PACKED mfdes_data_t; } PACKED mfdes_data_t;
typedef struct { typedef struct mfdes_info_res {
uint8_t isOK; uint8_t isOK;
uint8_t uid[7]; uint8_t uid[7];
uint8_t uidlen; uint8_t uidlen;
@ -443,7 +452,7 @@ static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu,
int res = 0; int res = 0;
if (activate_field) { if (activate_field) {
DropField(); DropFieldDesfire();
msleep(50); msleep(50);
} }
@ -466,6 +475,11 @@ static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu,
return res; return res;
} }
if (activate_field) {
PrintAndLogEx(DEBUG, "field up");
tag->rf_field_on = true;
}
if (GetAPDULogging() || (g_debugMode > 1)) if (GetAPDULogging() || (g_debugMode > 1))
PrintAndLogEx(SUCCESS, "<<<< %s", sprint_hex(result, *result_len)); PrintAndLogEx(SUCCESS, "<<<< %s", sprint_hex(result, *result_len));
@ -633,7 +647,7 @@ static int send_desfire_cmd(sAPDU *apdu, bool select, uint8_t *dest, uint32_t *r
int res = DESFIRESendApdu(select, true, *apdu, data, sizeof(data), &resplen, sw); int res = DESFIRESendApdu(select, true, *apdu, data, sizeof(data), &resplen, sw);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw)); PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
if (dest != NULL) { if (dest != NULL) {
@ -658,7 +672,7 @@ static int send_desfire_cmd(sAPDU *apdu, bool select, uint8_t *dest, uint32_t *r
res = DESFIRESendApdu(false, true, *apdu, data, sizeof(data), &resplen, sw); res = DESFIRESendApdu(false, true, *apdu, data, sizeof(data), &resplen, sw);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw)); PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -704,7 +718,7 @@ static int mfdes_get_info(mfdes_info_res_t *info) {
if (WaitForResponseTimeout(CMD_HF_DESFIRE_INFO, &resp, 1500) == false) { if (WaitForResponseTimeout(CMD_HF_DESFIRE_INFO, &resp, 1500) == false) {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
DropField(); DropFieldDesfire();
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
@ -1058,7 +1072,7 @@ static int test_desfire_authenticate(void) {
int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false);
if (res == PM3_SUCCESS) if (res == PM3_SUCCESS)
if (sw == status(MFDES_ADDITIONAL_FRAME)) { if (sw == status(MFDES_ADDITIONAL_FRAME)) {
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1073,7 +1087,7 @@ static int test_desfire_authenticate_iso(void) {
int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false);
if (res == PM3_SUCCESS) if (res == PM3_SUCCESS)
if (sw == status(MFDES_ADDITIONAL_FRAME)) { if (sw == status(MFDES_ADDITIONAL_FRAME)) {
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1088,7 +1102,7 @@ static int test_desfire_authenticate_aes(void) {
int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false);
if (res == PM3_SUCCESS) if (res == PM3_SUCCESS)
if (sw == status(MFDES_ADDITIONAL_FRAME)) { if (sw == status(MFDES_ADDITIONAL_FRAME)) {
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1161,27 +1175,40 @@ static int mifare_desfire_change_key(uint8_t key_no, uint8_t *new_key, uint8_t n
break; break;
} }
} }
/*
keyno 1b
key 8b
cpy 8b
crc 2b
padding
*/
// Variable length ciphered key data 26-42 bytes plus padding.. // Variable length ciphered key data 24-42 bytes plus padding..
uint8_t data[64] = {key_no}; uint8_t data[64] = {key_no};
sAPDU apdu = {0x90, MFDES_CHANGE_KEY, 0x00, 0x00, 0x01, data}; // 0xC4 sAPDU apdu = {0x90, MFDES_CHANGE_KEY, 0x00, 0x00, 0x01, data}; // 0xC4
size_t cmdcnt = 0;
uint8_t new_key_length = 16; uint8_t new_key_length = 16;
switch (new_algo) { switch (new_algo) {
case MFDES_ALGO_DES: case MFDES_ALGO_DES:
new_key_length = 8; // double
memcpy(data + cmdcnt + 1, new_key, new_key_length);
memcpy(data + cmdcnt + 1 + new_key_length, new_key, new_key_length);
break; break;
case MFDES_ALGO_3DES: case MFDES_ALGO_3DES:
case MFDES_ALGO_AES: case MFDES_ALGO_AES:
new_key_length = 16; new_key_length = 16;
memcpy(data + cmdcnt + 1, new_key, new_key_length);
break; break;
case MFDES_ALGO_3K3DES: case MFDES_ALGO_3K3DES:
new_key_length = 24; new_key_length = 24;
memcpy(data + cmdcnt + 1, new_key, new_key_length);
break; break;
} }
size_t cmdcnt = 0;
memcpy(data + cmdcnt + 1, new_key, new_key_length);
if ((tag->authenticated_key_no & 0x0f) != (key_no & 0x0f)) { if ((tag->authenticated_key_no & 0x0f) != (key_no & 0x0f)) {
if (old_key) { if (old_key) {
@ -1237,7 +1264,7 @@ static int mifare_desfire_change_key(uint8_t key_no, uint8_t *new_key, uint8_t n
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't change key -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't change key -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -1350,7 +1377,7 @@ static int handler_desfire_signature(uint8_t *signature, size_t *signature_len)
*signature_len = recv_len; *signature_len = recv_len;
} }
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -1558,10 +1585,15 @@ static int handler_desfire_select_application(uint8_t *aid) {
sAPDU apdu = {0x90, MFDES_SELECT_APPLICATION, 0x00, 0x00, 0x03, aid}; //0x5a sAPDU apdu = {0x90, MFDES_SELECT_APPLICATION, 0x00, 0x00, 0x03, aid}; //0x5a
uint32_t recv_len = 0; uint32_t recv_len = 0;
uint16_t sw = 0; uint16_t sw = 0;
int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, sizeof(dfname_t), true);
int res = send_desfire_cmd(&apdu, !tag->rf_field_on, NULL, &recv_len, &sw, sizeof(dfname_t), true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't select AID 0x%X -> %s"), (aid[2] << 16) + (aid[1] << 8) + aid[0], GetErrorString(res, &sw)); PrintAndLogEx(WARNING,
DropField(); _RED_(" Can't select AID 0x%X -> %s"),
(aid[2] << 16) + (aid[1] << 8) + aid[0],
GetErrorString(res, &sw)
);
DropFieldDesfire();
return res; return res;
} }
memcpy(&tag->selected_application, aid, 3); memcpy(&tag->selected_application, aid, 3);
@ -1603,7 +1635,7 @@ static int handler_desfire_fileids(uint8_t *dest, uint32_t *file_ids_len) {
int res = send_desfire_cmd(&apdu, false, dest, &recv_len, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, dest, &recv_len, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't get file ids -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't get file ids -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
*file_ids_len = recv_len; *file_ids_len = recv_len;
@ -1622,7 +1654,7 @@ static int handler_desfire_filesettings(uint8_t file_id, uint8_t *dest, uint32_t
int res = send_desfire_cmd(&apdu, false, dest, destlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, dest, destlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't get file settings -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't get file settings -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1662,7 +1694,7 @@ static int handler_desfire_createapp(aidhdr_t *aidhdr, bool usename, bool usefid
} }
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create aid -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create aid -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
} }
return res; return res;
} }
@ -1677,7 +1709,7 @@ static int handler_desfire_deleteapp(const uint8_t *aid) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't delete aid -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't delete aid -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
} }
return res; return res;
} }
@ -1695,7 +1727,7 @@ static int handler_desfire_credit(mfdes_value_t *value, uint8_t cs) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't credit value -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't credit value -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1714,7 +1746,7 @@ static int handler_desfire_limitedcredit(mfdes_value_t *value, uint8_t cs) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't credit limited value -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't credit limited value -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1733,7 +1765,7 @@ static int handler_desfire_debit(mfdes_value_t *value, uint8_t cs) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't debit value -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't debit value -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1755,7 +1787,7 @@ static int handler_desfire_readdata(mfdes_data_t *data, MFDES_FILE_TYPE_T type,
int res = send_desfire_cmd(&apdu, false, data->data, &resplen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, data->data, &resplen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -1785,7 +1817,7 @@ static int handler_desfire_getvalue(mfdes_value_t *value, uint32_t *resplen, uin
int res = send_desfire_cmd(&apdu, false, value->value, resplen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, value->value, resplen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
size_t dlen = (size_t)resplen; size_t dlen = (size_t)resplen;
@ -1840,7 +1872,7 @@ static int handler_desfire_writedata(mfdes_data_t *data, MFDES_FILE_TYPE_T type,
res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't write data -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't write data -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
offset += datasize; offset += datasize;
@ -1850,7 +1882,7 @@ static int handler_desfire_writedata(mfdes_data_t *data, MFDES_FILE_TYPE_T type,
if (type == MFDES_RECORD_FILE) { if (type == MFDES_RECORD_FILE) {
if (handler_desfire_commit_transaction() != PM3_SUCCESS) { if (handler_desfire_commit_transaction() != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
} }
@ -1865,7 +1897,7 @@ static int handler_desfire_deletefile(uint8_t fileno) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't delete file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't delete file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1879,13 +1911,13 @@ static int handler_desfire_clearrecordfile(uint8_t fileno) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't clear record file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't clear record file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} else { } else {
res = handler_desfire_commit_transaction(); res = handler_desfire_commit_transaction();
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
} }
@ -1902,7 +1934,7 @@ static int handler_desfire_create_value_file(mfdes_value_file_t *value) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create value -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create value -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1917,7 +1949,7 @@ static int handler_desfire_create_std_file(mfdes_file_t *file) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1933,7 +1965,7 @@ static int handler_desfire_create_linearrecordfile(mfdes_linear_t *file) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create linear record file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create linear record file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1949,7 +1981,7 @@ static int handler_desfire_create_cyclicrecordfile(mfdes_linear_t *file) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create cyclic record file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create cyclic record file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -1965,7 +1997,7 @@ static int handler_desfire_create_backup_file(mfdes_file_t *file) {
int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, _RED_(" Can't create backup file -> %s"), GetErrorString(res, &sw)); PrintAndLogEx(WARNING, _RED_(" Can't create backup file -> %s"), GetErrorString(res, &sw));
DropField(); DropFieldDesfire();
return res; return res;
} }
return res; return res;
@ -2066,7 +2098,7 @@ static int getKeySettings(uint8_t *aid) {
} }
} }
DropField(); DropFieldDesfire();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -2204,7 +2236,7 @@ static int CmdHF14ADesGetUID(const char *Cmd) {
uint8_t uid[16] = {0}; uint8_t uid[16] = {0};
int res = handler_desfire_getuid(uid); int res = handler_desfire_getuid(uid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
DropField(); DropFieldDesfire();
PrintAndLogEx(ERR, "Error on getting uid."); PrintAndLogEx(ERR, "Error on getting uid.");
return res; return res;
} }
@ -2238,9 +2270,9 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
} }
int res = handler_desfire_select_application(aid); int res = handler_desfire_select_application(aid);
DropField();
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Error on selecting aid."); PrintAndLogEx(ERR, "Error on selecting aid.");
DropFieldDesfire();
} else { } else {
PrintAndLogEx(SUCCESS, "Successfully selected aid."); PrintAndLogEx(SUCCESS, "Successfully selected aid.");
} }
@ -2373,15 +2405,17 @@ static int CmdHF14ADesCreateApp(const char *Cmd) {
if (usename) if (usename)
PrintAndLogEx(INFO, "DF Name %s", aidhdr.name); PrintAndLogEx(INFO, "DF Name %s", aidhdr.name);
/*
uint8_t rootaid[3] = {0x00, 0x00, 0x00}; uint8_t rootaid[3] = {0x00, 0x00, 0x00};
int res = handler_desfire_select_application(rootaid); int res = handler_desfire_select_application(rootaid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
DropField(); DropFieldDesfire();
return res; return res;
} }
*/
res = handler_desfire_createapp(&aidhdr, usename, usefid); int res = handler_desfire_createapp(&aidhdr, usename, usefid);
DropField(); DropFieldDesfire();
if (res == PM3_SUCCESS) { if (res == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "Successfully created aid."); PrintAndLogEx(SUCCESS, "Successfully created aid.");
} }
@ -2392,7 +2426,6 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfdes deleteaid", CLIParserInit(&ctx, "hf mfdes deleteaid",
"Delete Application ID", "Delete Application ID",
// "Usage:\n\t-a aid (3 hex bytes, big endian)\n\n"
"hf mfdes deleteaid -a 123456" "hf mfdes deleteaid -a 123456"
); );
@ -2417,14 +2450,9 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) {
return PM3_ESOFT; return PM3_ESOFT;
} }
uint8_t rootaid[3] = {0x00, 0x00, 0x00}; int res = handler_desfire_deleteapp(aid);
int res = handler_desfire_select_application(rootaid); DropFieldDesfire();
if (res != PM3_SUCCESS) {
DropField();
return res;
}
res = handler_desfire_deleteapp(aid);
DropField();
if (res == PM3_SUCCESS) { if (res == PM3_SUCCESS) {
PrintAndLogEx(SUCCESS, "Successfully deleted aid."); PrintAndLogEx(SUCCESS, "Successfully deleted aid.");
} }
@ -2514,7 +2542,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Error on deleting file : %d", res); PrintAndLogEx(ERR, "Error on deleting file : %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2574,7 +2602,7 @@ static int CmdHF14ADesDeleteFile(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Error on deleting file : %d", res); PrintAndLogEx(ERR, "Error on deleting file : %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2664,12 +2692,12 @@ static int CmdHF14ADesCreateFile(const char *Cmd) {
if (aidlength != 3 && aidlength != 0) { if (aidlength != 3 && aidlength != 0) {
PrintAndLogEx(ERR, _RED_(" The given aid must have 3 bytes (big endian).")); PrintAndLogEx(ERR, _RED_(" The given aid must have 3 bytes (big endian)."));
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} else if (aidlength == 0) { } else if (aidlength == 0) {
if (memcmp(&tag->selected_application, aid, 3) == 0) { if (memcmp(&tag->selected_application, aid, 3) == 0) {
PrintAndLogEx(ERR, _RED_(" You need to select an aid first.")); PrintAndLogEx(ERR, _RED_(" You need to select an aid first."));
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} }
memcpy(aid, (uint8_t *)&tag->selected_application, 3); memcpy(aid, (uint8_t *)&tag->selected_application, 3);
@ -2678,7 +2706,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) {
int res = handler_desfire_select_application(aid); int res = handler_desfire_select_application(aid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Couldn't select aid. Error %d", res); PrintAndLogEx(ERR, "Couldn't select aid. Error %d", res);
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2692,7 +2720,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) {
else else
PrintAndLogEx(ERR, "Couldn't create standard/backup file. Error %d", res); PrintAndLogEx(ERR, "Couldn't create standard/backup file. Error %d", res);
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2763,7 +2791,7 @@ static int CmdHF14ADesGetValueData(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res); PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2879,12 +2907,12 @@ static int CmdHF14ADesReadData(const char *Cmd) {
} }
} else { } else {
PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); PrintAndLogEx(ERR, "Couldn't read data. Error %d", res);
DropField(); DropFieldDesfire();
return res; return res;
} }
free(data); free(data);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -2980,7 +3008,7 @@ static int CmdHF14ADesChangeValue(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Couldn't change value in value file. Error %d", res); PrintAndLogEx(ERR, "Couldn't change value in value file. Error %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -3074,7 +3102,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
uint8_t cs = 0; uint8_t cs = 0;
if (selectfile(aid, _fileno[0], &cs) != PM3_SUCCESS) { if (selectfile(aid, _fileno[0], &cs) != PM3_SUCCESS) {
PrintAndLogEx(ERR, _RED_(" Error on selecting file.")); PrintAndLogEx(ERR, _RED_(" Error on selecting file."));
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} }
@ -3086,7 +3114,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); PrintAndLogEx(ERR, "Couldn't read data. Error %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -3222,7 +3250,7 @@ static int CmdHF14ADesCreateRecordFile(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Couldn't create linear/cyclic record file. Error %d", res); PrintAndLogEx(ERR, "Couldn't create linear/cyclic record file. Error %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -3354,7 +3382,7 @@ static int CmdHF14ADesCreateValueFile(const char *Cmd) {
} else { } else {
PrintAndLogEx(ERR, "Couldn't create value file. Error %d", res); PrintAndLogEx(ERR, "Couldn't create value file. Error %d", res);
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
@ -3380,13 +3408,13 @@ static int CmdHF14ADesFormatPICC(const char *Cmd) {
} else { } else {
PrintAndLogEx(INFO, "Card successfully reset"); PrintAndLogEx(INFO, "Card successfully reset");
} }
DropField(); DropFieldDesfire();
return res; return res;
} }
static int CmdHF14ADesInfo(const char *Cmd) { static int CmdHF14ADesInfo(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
DropField(); DropFieldDesfire();
mfdes_info_res_t info; mfdes_info_res_t info;
int res = mfdes_get_info(&info); int res = mfdes_get_info(&info);
@ -3493,7 +3521,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
*/ */
DropField(); DropFieldDesfire();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -3644,7 +3672,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
CLIParserFree(ctx); CLIParserFree(ctx);
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
DropField(); DropFieldDesfire();
uint8_t aid[3] = {0}; uint8_t aid[3] = {0};
uint8_t app_ids[78] = {0}; uint8_t app_ids[78] = {0};
@ -3660,7 +3688,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Can't get list of applications on tag"); PrintAndLogEx(ERR, "Can't get list of applications on tag");
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} }
@ -3724,7 +3752,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t));
if (data == NULL) { if (data == NULL) {
DropField(); DropFieldDesfire();
return PM3_EMALLOC; return PM3_EMALLOC;
} }
@ -3771,7 +3799,7 @@ static int CmdHF14ADesDump(const char *Cmd) {
memset(fdata.length, 0, 3); memset(fdata.length, 0, 3);
uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t));
if (data == NULL) { if (data == NULL) {
DropField(); DropFieldDesfire();
return PM3_EMALLOC; return PM3_EMALLOC;
} }
@ -3801,14 +3829,14 @@ static int CmdHF14ADesDump(const char *Cmd) {
} }
PrintAndLogEx(INFO, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
DropField(); DropFieldDesfire();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int CmdHF14ADesEnumApplications(const char *Cmd) { static int CmdHF14ADesEnumApplications(const char *Cmd) {
(void)Cmd; // Cmd is not used so far (void)Cmd; // Cmd is not used so far
DropField(); DropFieldDesfire();
uint8_t aid[3] = {0}; uint8_t aid[3] = {0};
uint8_t app_ids[78] = {0}; uint8_t app_ids[78] = {0};
@ -3822,7 +3850,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Can't get list of applications on tag"); PrintAndLogEx(ERR, "Can't get list of applications on tag");
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} }
@ -3892,12 +3920,12 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
} }
PrintAndLogEx(INFO, "-------------------------------------------------------------"); PrintAndLogEx(INFO, "-------------------------------------------------------------");
DropField(); DropFieldDesfire();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
static int CmdHF14ADesChangeKey(const char *Cmd) { static int CmdHF14ADesChangeKey(const char *Cmd) {
//DropField(); //DropFieldDesfire();
// NR DESC KEYLENGHT // NR DESC KEYLENGHT
// ------------------------ // ------------------------
// 1 = DES 8 // 1 = DES 8
@ -3998,7 +4026,7 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
// //
#define BUFSIZE 256 #define BUFSIZE 256
static int CmdHF14ADesAuth(const char *Cmd) { static int CmdHF14ADesAuth(const char *Cmd) {
//DropField(); //DropFieldDesfire();
// NR DESC KEYLENGHT // NR DESC KEYLENGHT
// ------------------------ // ------------------------
// 1 = DES 8 // 1 = DES 8
@ -4261,7 +4289,7 @@ static int AuthCheckDesfire(uint8_t *aid,
break; break;
} else if (error < 7) { } else if (error < 7) {
badlen = true; badlen = true;
DropField(); DropFieldDesfire();
res = handler_desfire_select_application(aid); res = handler_desfire_select_application(aid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
return res; return res;
@ -4293,7 +4321,7 @@ static int AuthCheckDesfire(uint8_t *aid,
break; break;
} else if (error < 7) { } else if (error < 7) {
badlen = true; badlen = true;
DropField(); DropFieldDesfire();
res = handler_desfire_select_application(aid); res = handler_desfire_select_application(aid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
return res; return res;
@ -4325,7 +4353,7 @@ static int AuthCheckDesfire(uint8_t *aid,
break; break;
} else if (error < 7) { } else if (error < 7) {
badlen = true; badlen = true;
DropField(); DropFieldDesfire();
res = handler_desfire_select_application(aid); res = handler_desfire_select_application(aid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
return res; return res;
@ -4357,7 +4385,7 @@ static int AuthCheckDesfire(uint8_t *aid,
break; break;
} else if (error < 7) { } else if (error < 7) {
badlen = true; badlen = true;
DropField(); DropFieldDesfire();
res = handler_desfire_select_application(aid); res = handler_desfire_select_application(aid);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
return res; return res;
@ -4372,7 +4400,7 @@ static int AuthCheckDesfire(uint8_t *aid,
} }
} }
} }
DropField(); DropFieldDesfire();
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -4570,7 +4598,7 @@ static int CmdHF14aDesChk(const char *Cmd) {
if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Can't get list of applications on tag"); PrintAndLogEx(ERR, "Can't get list of applications on tag");
DropField(); DropFieldDesfire();
return PM3_ESOFT; return PM3_ESOFT;
} }
@ -4670,7 +4698,7 @@ static int CmdHF14ADesList(const char *Cmd) {
/* /*
static int CmdHF14aDesNDEF(const char *Cmd) { static int CmdHF14aDesNDEF(const char *Cmd) {
DropField(); DropFieldDesfire();
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfdes ndef", CLIParserInit(&ctx, "hf mfdes ndef",
@ -4735,7 +4763,7 @@ static int CmdHF14aDesNDEF(const char *Cmd) {
uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t));
if (data == NULL) { if (data == NULL) {
DropField(); DropFieldDesfire();
return PM3_EMALLOC; return PM3_EMALLOC;
} }
@ -4774,7 +4802,7 @@ static int CmdHF14aDesNDEF(const char *Cmd) {
*/ */
/* /*
static int CmdHF14aDesMAD(const char *Cmd) { static int CmdHF14aDesMAD(const char *Cmd) {
DropField(); DropFieldDesfire();
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mfdes mad", CLIParserInit(&ctx, "hf mfdes mad",

View file

@ -50,7 +50,7 @@ static int CmdHelp(const char *Cmd);
static int usage_lf_fdxb_clone(void) { static int usage_lf_fdxb_clone(void) {
PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 or Q5/T5555 tag."); PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 or Q5/T5555 tag.");
PrintAndLogEx(NORMAL, "Usage: lf fdxb clone [h] [c <country code>] [a <national code>] [e <extended>] <s> <Q5>"); PrintAndLogEx(NORMAL, "Usage: lf fdxb clone [h] [c <country code>] [n <national code>] [e <extended>] <s> <Q5>");
PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h : This help"); PrintAndLogEx(NORMAL, " h : This help");
PrintAndLogEx(NORMAL, " c <country> : (dec) Country code"); PrintAndLogEx(NORMAL, " c <country> : (dec) Country code");

View file

@ -138,9 +138,9 @@ int demodHID(bool verbose) {
wiegand_message_t packed = initialize_message_object(hi2, hi, lo); wiegand_message_t packed = initialize_message_object(hi2, hi, lo);
if (HIDTryUnpack(&packed, false) == false) { if (HIDTryUnpack(&packed, false) == false) {
PrintAndLogEx(INFO, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo);
printDemodBuff(0, false, false, true); printDemodBuff(0, false, false, true);
} }
PrintAndLogEx(INFO, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo);
PrintAndLogEx(DEBUG, "DEBUG: HID idx: %d, Len: %zu, Printing Demod Buffer: ", idx, size); PrintAndLogEx(DEBUG, "DEBUG: HID idx: %d, Len: %zu, Printing Demod Buffer: ", idx, size);
if (g_debugMode) { if (g_debugMode) {

View file

@ -38,47 +38,10 @@
#include "util_posix.h" #include "util_posix.h"
#include "commonutil.h" // ARRAYLEN #include "commonutil.h" // ARRAYLEN
#include "preferences.h" #include "preferences.h"
#include "cliparser.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static int usage_hints(void) {
PrintAndLogEx(NORMAL, "Turn on/off hints");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hints [h] <0|1>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " <0|1> off or on");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" hints 1"));
return PM3_SUCCESS;
}
static int usage_msleep(void) {
PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: msleep <ms>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, " <ms> time in milliseconds");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" msleep 100"));
return PM3_SUCCESS;
}
static int usage_auto(void) {
PrintAndLogEx(NORMAL, "Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: auto <ms>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" auto"));
return PM3_SUCCESS;
}
static void AppendDate(char *s, size_t slen, const char *fmt) { static void AppendDate(char *s, size_t slen, const char *fmt) {
struct tm *ct, tm_buf; struct tm *ct, tm_buf;
time_t now = time(NULL); time_t now = time(NULL);
@ -157,18 +120,31 @@ static int lf_search_plus(const char *Cmd) {
return retval; return retval;
} }
static int CmdAuto(const char *Cmd) { static int CmdAuto(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0)); CLIParserContext *ctx;
if (ctmp == 'h') return usage_auto(); CLIParserInit(&ctx, "auto",
"Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE",
"auto"
);
void *argtable[] = {
arg_param_begin,
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
CLIParserFree(ctx);
PrintAndLogEx(INFO, "lf search");
int ret = CmdLFfind(""); int ret = CmdLFfind("");
if (ret == PM3_SUCCESS) if (ret == PM3_SUCCESS)
return ret; return ret;
PrintAndLogEx(INFO, "hf search");
ret = CmdHFSearch(""); ret = CmdHFSearch("");
if (ret == PM3_SUCCESS) if (ret == PM3_SUCCESS)
return ret; return ret;
PrintAndLogEx(INFO, "lf search - unknown");
ret = lf_search_plus(""); ret = lf_search_plus("");
if (ret == PM3_SUCCESS) if (ret == PM3_SUCCESS)
return ret; return ret;
@ -193,26 +169,35 @@ int CmdRem(const char *Cmd) {
} }
static int CmdHints(const char *Cmd) { static int CmdHints(const char *Cmd) {
uint32_t ms = 0;
char ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_hints();
if (strlen(Cmd) > 1) { CLIParserContext *ctx;
str_lower((char *)Cmd); CLIParserInit(&ctx, "hints",
if (str_startswith(Cmd, "of")) { "Turn on/off hints",
session.show_hints = false; "hints --on\n"
} else { "hints -1\n"
session.show_hints = true; );
}
} else if (strlen(Cmd) == 1) { void *argtable[] = {
if (param_getchar(Cmd, 0) != 0x00) { arg_param_begin,
ms = param_get32ex(Cmd, 0, 0, 10); arg_lit0("1", "on", "turn on hints"),
if (ms == 0) { arg_lit0("0", "off", "turn off hints"),
session.show_hints = false; arg_param_end
} else { };
session.show_hints = true; CLIExecWithReturn(ctx, Cmd, argtable, true);
}
} bool turn_on = arg_get_lit(ctx, 1);
bool turn_off = arg_get_lit(ctx, 2);
CLIParserFree(ctx);
if (turn_on && turn_off) {
PrintAndLogEx(ERR, "you can't turn off and on at the same time");
return PM3_EINVARG;
}
if (turn_off) {
session.show_hints = false;
} else if (turn_on) {
session.show_hints = true;
} }
PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF"); PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF");
@ -220,14 +205,26 @@ static int CmdHints(const char *Cmd) {
} }
static int CmdMsleep(const char *Cmd) { static int CmdMsleep(const char *Cmd) {
uint32_t ms = 0; CLIParserContext *ctx;
char ctmp = tolower(param_getchar(Cmd, 0)); CLIParserInit(&ctx, "msleep",
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_msleep(); "Sleep for given amount of milliseconds",
if (param_getchar(Cmd, 0) != 0x00) { "msleep 100"
ms = param_get32ex(Cmd, 0, 0, 10); );
if (ms == 0)
return usage_msleep(); void *argtable[] = {
arg_param_begin,
arg_int0("t", "ms", "<ms>", "time in milliseconds"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
uint32_t ms = arg_get_u32_def(ctx, 1, 0);
CLIParserFree(ctx);
if (ms == 0) {
PrintAndLogEx(ERR, "Specified invalid input. Can't be zero");
return PM3_EINVARG;
} }
msleep(ms); msleep(ms);
return PM3_SUCCESS; return PM3_SUCCESS;
} }

View file

@ -93,6 +93,7 @@ struct desfire_tag {
uint8_t *crypto_buffer; uint8_t *crypto_buffer;
size_t crypto_buffer_size; size_t crypto_buffer_size;
uint32_t selected_application; uint32_t selected_application;
bool rf_field_on;
}; };
typedef struct desfire_tag *desfiretag_t; typedef struct desfire_tag *desfiretag_t;

View file

@ -859,7 +859,7 @@ int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, uint8_
PrintAndLogEx(SUCCESS, "new block 0: %s", sprint_hex(block0, 16)); PrintAndLogEx(SUCCESS, "new block 0: %s", sprint_hex(block0, 16));
if (wipecard) params |= MAGIC_WIPE; if (wipecard) params |= MAGIC_WIPE;
if (oldUID == NULL) params |= MAGIC_UID; if (oldUID != NULL) params |= MAGIC_UID;
return mfCSetBlock(0, block0, oldUID, params); return mfCSetBlock(0, block0, oldUID, params);
} }