mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
coverity fix 286655
This commit is contained in:
parent
ba08d5794c
commit
5363385845
1 changed files with 112 additions and 121 deletions
|
@ -925,7 +925,7 @@ void AuthToError(int error) {
|
||||||
PrintAndLogEx(ERR, "Authentication failed. Invalid key number.");
|
PrintAndLogEx(ERR, "Authentication failed. Invalid key number.");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
PrintAndLogEx(ERR, "Authentication failed. Length of answer %d doesn't match algo length %d.");
|
PrintAndLogEx(ERR, "Authentication failed. Length of answer doesn't match algo length");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed");
|
PrintAndLogEx(ERR, "mbedtls_aes_setkey_dec failed");
|
||||||
|
@ -3161,6 +3161,7 @@ static int DecodeFileSettings(uint8_t *src, int src_len, int maclen) {
|
||||||
static int CmdHF14ADesDump(const char *Cmd) {
|
static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
(void)Cmd; // Cmd is not used so far
|
(void)Cmd; // Cmd is not used so far
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
uint8_t aid[3] = {0};
|
uint8_t aid[3] = {0};
|
||||||
uint8_t app_ids[78] = {0};
|
uint8_t app_ids[78] = {0};
|
||||||
uint8_t app_ids_len = 0;
|
uint8_t app_ids_len = 0;
|
||||||
|
@ -3205,11 +3206,14 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
uint8_t num_keys = 0;
|
uint8_t num_keys = 0;
|
||||||
uint8_t key_setting = 0;
|
uint8_t key_setting = 0;
|
||||||
res = handler_desfire_keysettings(&key_setting, &num_keys);
|
res = handler_desfire_keysettings(&key_setting, &num_keys);
|
||||||
if (res != PM3_SUCCESS) return res;
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
res = handler_desfire_select_application(aid);
|
res = handler_desfire_select_application(aid);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
|
res = handler_desfire_fileids(file_ids, &file_ids_len);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
if (handler_desfire_fileids(file_ids, &file_ids_len) == PM3_SUCCESS) {
|
|
||||||
for (int j = file_ids_len - 1; j >= 0; j--) {
|
for (int j = file_ids_len - 1; j >= 0; j--) {
|
||||||
PrintAndLogEx(SUCCESS, "\n\n Fileid %d (0x%02x)", file_ids[j], file_ids[j]);
|
PrintAndLogEx(SUCCESS, "\n\n Fileid %d (0x%02x)", file_ids[j], file_ids[j]);
|
||||||
|
|
||||||
|
@ -3217,20 +3221,24 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
int fileset_len = 0;
|
int fileset_len = 0;
|
||||||
|
|
||||||
res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len);
|
res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
int maclen = 0; // To be implemented
|
int maclen = 0; // To be implemented
|
||||||
|
|
||||||
if (res == PM3_SUCCESS) {
|
|
||||||
//if (DecodeFileSettings(filesettings, fileset_len, maclen) != PM3_SUCCESS) {
|
|
||||||
if (fileset_len == 1 + 1 + 2 + 3 + maclen) {
|
if (fileset_len == 1 + 1 + 2 + 3 + maclen) {
|
||||||
int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4];
|
int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4];
|
||||||
mfdes_data_t fdata;
|
mfdes_data_t fdata;
|
||||||
fdata.fileno = file_ids[j];
|
fdata.fileno = file_ids[j];
|
||||||
memset(fdata.offset, 0, 3);
|
memset(fdata.offset, 0, 3);
|
||||||
//memcpy(fdata.length,&filesettings[4],3);
|
|
||||||
memset(fdata.length, 0, 3);
|
memset(fdata.length, 0, 3);
|
||||||
uint8_t *data = (uint8_t *)malloc(filesize);
|
|
||||||
|
uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t));
|
||||||
|
if (data == NULL) {
|
||||||
|
DropField();
|
||||||
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
fdata.data = data;
|
fdata.data = data;
|
||||||
if (data) {
|
|
||||||
res = handler_desfire_readdata(&fdata, MFDES_DATA_FILE);
|
res = handler_desfire_readdata(&fdata, MFDES_DATA_FILE);
|
||||||
if (res == PM3_SUCCESS) {
|
if (res == PM3_SUCCESS) {
|
||||||
PrintAndLogEx(NORMAL, "\nOffset | Data | Ascii");
|
PrintAndLogEx(NORMAL, "\nOffset | Data | Ascii");
|
||||||
|
@ -3239,12 +3247,14 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
for (int n = 0; n < len; n += 16) {
|
for (int n = 0; n < len; n += 16) {
|
||||||
PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s", n, n, sprint_hex(&fdata.data[n], len > 16 ? 16 : len), sprint_ascii(&fdata.data[n], len > 16 ? 16 : len));
|
PrintAndLogEx(NORMAL, "%02d/0x%02X | %s| %s", n, n, sprint_hex(&fdata.data[n], len > 16 ? 16 : len), sprint_ascii(&fdata.data[n], len > 16 ? 16 : len));
|
||||||
}
|
}
|
||||||
free(data);
|
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
|
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
|
||||||
res = handler_desfire_select_application(aid);
|
res = handler_desfire_select_application(aid);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
} else if (fileset_len == 1 + 1 + 2 + 4 + 4 + 4 + 1 + maclen) {
|
} else if (fileset_len == 1 + 1 + 2 + 4 + 4 + 4 + 1 + maclen) {
|
||||||
PrintAndLogEx(NORMAL, "\n\nValue file: 0x%0x", file_ids[j]);
|
PrintAndLogEx(NORMAL, "\n\nValue file: 0x%0x", file_ids[j]);
|
||||||
mfdes_value_t value;
|
mfdes_value_t value;
|
||||||
|
@ -3260,17 +3270,22 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
|
PrintAndLogEx(ERR, "Couldn't read value. Error %d", res);
|
||||||
res = handler_desfire_select_application(aid);
|
res = handler_desfire_select_application(aid);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (fileset_len == 1 + 1 + 2 + 3 + 3 + 3 + maclen) {
|
} else if (fileset_len == 1 + 1 + 2 + 3 + 3 + 3 + maclen) {
|
||||||
int maxrecords = (filesettings[9] << 16) + (filesettings[8] << 8) + filesettings[7];
|
int maxrecords = (filesettings[9] << 16) + (filesettings[8] << 8) + filesettings[7];
|
||||||
int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4];
|
int filesize = (filesettings[6] << 16) + (filesettings[5] << 8) + filesettings[4];
|
||||||
mfdes_data_t fdata;
|
mfdes_data_t fdata;
|
||||||
fdata.fileno = file_ids[j];
|
fdata.fileno = file_ids[j];
|
||||||
memset(fdata.length, 0, 3);
|
memset(fdata.length, 0, 3);
|
||||||
//memcpy(fdata.length,&filesettings[4],3);
|
uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t));
|
||||||
uint8_t *data = (uint8_t *)malloc(filesize);
|
if (data == NULL) {
|
||||||
|
DropField();
|
||||||
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
fdata.data = data;
|
fdata.data = data;
|
||||||
if (data) {
|
|
||||||
for (int offset = 0; offset < maxrecords; offset++) {
|
for (int offset = 0; offset < maxrecords; offset++) {
|
||||||
PrintAndLogEx(NORMAL, "\n\nRecord offset: %024x", offset);
|
PrintAndLogEx(NORMAL, "\n\nRecord offset: %024x", offset);
|
||||||
memset(data, 0, filesize);
|
memset(data, 0, filesize);
|
||||||
|
@ -3287,24 +3302,24 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res = handler_desfire_select_application(aid);
|
res = handler_desfire_select_application(aid);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
||||||
DropField();
|
DropField();
|
||||||
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();
|
DropField();
|
||||||
// uint8_t isOK = 0x00;
|
|
||||||
uint8_t aid[3] = {0};
|
uint8_t aid[3] = {0};
|
||||||
uint8_t app_ids[78] = {0};
|
uint8_t app_ids[78] = {0};
|
||||||
uint8_t app_ids_len = 0;
|
uint8_t app_ids_len = 0;
|
||||||
|
@ -3315,8 +3330,6 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
dfname_t dfnames[255];
|
dfname_t dfnames[255];
|
||||||
uint8_t dfname_count = 0;
|
uint8_t dfname_count = 0;
|
||||||
|
|
||||||
int res = 0;
|
|
||||||
|
|
||||||
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();
|
DropField();
|
||||||
|
@ -3356,14 +3369,15 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = getKeySettings(aid);
|
int res = getKeySettings(aid);
|
||||||
if (res != PM3_SUCCESS) return res;
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
res = handler_desfire_select_application(aid);
|
res = handler_desfire_select_application(aid);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
|
res = handler_desfire_fileids(file_ids, &file_ids_len);
|
||||||
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
// Get File IDs
|
|
||||||
if (handler_desfire_fileids(file_ids, &file_ids_len) == PM3_SUCCESS) {
|
|
||||||
PrintAndLogEx(SUCCESS, " Tag report " _GREEN_("%d") " file%c", file_ids_len, (file_ids_len == 1) ? ' ' : 's');
|
PrintAndLogEx(SUCCESS, " Tag report " _GREEN_("%d") " file%c", file_ids_len, (file_ids_len == 1) ? ' ' : 's');
|
||||||
for (int j = file_ids_len - 1; j >= 0; j--) {
|
for (int j = file_ids_len - 1; j >= 0; j--) {
|
||||||
PrintAndLogEx(SUCCESS, " Fileid %d (0x%02x)", file_ids[j], file_ids[j]);
|
PrintAndLogEx(SUCCESS, " Fileid %d (0x%02x)", file_ids[j], file_ids[j]);
|
||||||
|
@ -3373,36 +3387,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
|
||||||
int maclen = 0; // To be implemented
|
int maclen = 0; // To be implemented
|
||||||
|
|
||||||
res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len);
|
res = handler_desfire_filesettings(file_ids[j], filesettings, &fileset_len);
|
||||||
if (res == PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) continue;
|
||||||
|
|
||||||
if (DecodeFileSettings(filesettings, fileset_len, maclen) != PM3_SUCCESS) {
|
if (DecodeFileSettings(filesettings, fileset_len, maclen) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(INFO, " Settings [%u] %s", fileset_len, sprint_hex(filesettings, fileset_len));
|
PrintAndLogEx(INFO, " Settings [%u] %s", fileset_len, sprint_hex(filesettings, fileset_len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Get ISO File IDs
|
|
||||||
{
|
|
||||||
uint8_t data[] = {GET_ISOFILE_IDS, 0x00, 0x00, 0x00}; // 0x61
|
|
||||||
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, DISCONNECT, sizeof(data), 0, data, sizeof(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!WaitForResponseTimeout(CMD_ACK, &respFiles, 1500)) {
|
|
||||||
PrintAndLogEx(WARNING, _RED_(" Timed-out"));
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
isOK = respFiles.data.asBytes[2] & 0xff;
|
|
||||||
if (!isOK) {
|
|
||||||
PrintAndLogEx(WARNING, _RED_(" Can't get ISO file ids"));
|
|
||||||
} else {
|
|
||||||
int respfileLen = resp.oldarg[1] - 3 - 2;
|
|
||||||
for (int j = 0; j < respfileLen; ++j) {
|
|
||||||
PrintAndLogEx(SUCCESS, " ISO Fileid %d :", resp.data.asBytes[j + 3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
||||||
DropField();
|
DropField();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue