mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 10:37:23 -07:00
fix cpp warnings
This commit is contained in:
parent
1a437d4a18
commit
a2d10d7910
8 changed files with 82 additions and 62 deletions
|
@ -1749,7 +1749,7 @@ void SimulateIso14443aTag(uint8_t tagType, uint16_t flags, uint8_t *useruid, uin
|
|||
|
||||
bool risky = false;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
risky |= orig[i] & ~receivedCmd[2 + i];
|
||||
risky |= (orig[i] & ~receivedCmd[2 + i]);
|
||||
}
|
||||
|
||||
if (risky) {
|
||||
|
|
|
@ -253,7 +253,7 @@ out:
|
|||
* @param card_select Pointer to the descriptor of the detected card.
|
||||
* @return Status code indicating success or failure of the operation.
|
||||
*/
|
||||
static int sam_set_card_detected_picopass(picopass_hdr_t *card_select) {
|
||||
static int sam_set_card_detected_picopass(const picopass_hdr_t *card_select) {
|
||||
int res = PM3_SUCCESS;
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
DbpString("start sam_set_card_detected");
|
||||
|
@ -379,15 +379,15 @@ int sam_picopass_get_pacs(PacketCommandNG *c) {
|
|||
print_result("Response data", sam_response, sam_response_len);
|
||||
|
||||
goto out;
|
||||
goto off;
|
||||
|
||||
err:
|
||||
res = PM3_ENOPACS;
|
||||
reply_ng(CMD_HF_SAM_PICOPASS, res, NULL, 0);
|
||||
goto off;
|
||||
|
||||
out:
|
||||
reply_ng(CMD_HF_SAM_PICOPASS, PM3_SUCCESS, sam_response, sam_response_len);
|
||||
goto off;
|
||||
|
||||
off:
|
||||
if (disconnectAfter) {
|
||||
switch_off();
|
||||
|
|
|
@ -125,9 +125,11 @@ out:
|
|||
* @return Status code indicating success or failure of the operation.
|
||||
*/
|
||||
static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t request_len, uint8_t *response, uint8_t *response_len) {
|
||||
|
||||
int res = PM3_SUCCESS;
|
||||
if (g_dbglevel >= DBG_DEBUG)
|
||||
if (g_dbglevel >= DBG_DEBUG) {
|
||||
DbpString("start sam_send_request_iso14a");
|
||||
}
|
||||
|
||||
uint8_t *buf1 = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
uint8_t *buf2 = BigBuf_malloc(ISO7816_MAX_FRAME);
|
||||
|
@ -178,23 +180,13 @@ static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t r
|
|||
switch_clock_to_countsspclk();
|
||||
nfc_tx_len = sam_copy_payload_sam2nfc(nfc_tx_buf, sam_rx_buf);
|
||||
|
||||
nfc_rx_len = iso14_apdu(
|
||||
nfc_tx_buf,
|
||||
nfc_tx_len,
|
||||
false,
|
||||
nfc_rx_buf,
|
||||
ISO7816_MAX_FRAME,
|
||||
NULL
|
||||
);
|
||||
nfc_rx_len = iso14_apdu(nfc_tx_buf, nfc_tx_len, false, nfc_rx_buf, ISO7816_MAX_FRAME, NULL);
|
||||
// iceman: should check nfc_rx_len , if negative something went wrong...
|
||||
|
||||
switch_clock_to_ticks();
|
||||
sam_tx_len = sam_copy_payload_nfc2sam(sam_tx_buf, nfc_rx_buf, nfc_rx_len - 2);
|
||||
|
||||
sam_send_payload(
|
||||
0x14, 0x0a, 0x14,
|
||||
sam_tx_buf, &sam_tx_len,
|
||||
sam_rx_buf, &sam_rx_len
|
||||
);
|
||||
sam_send_payload(0x14, 0x0a, 0x14, sam_tx_buf, &sam_tx_len, sam_rx_buf, &sam_rx_len);
|
||||
|
||||
// last SAM->TAG
|
||||
// c1 61 c1 00 00 a1 02 >>82<< 00 90 00
|
||||
|
@ -240,13 +232,15 @@ static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t r
|
|||
// 07
|
||||
// 90 00
|
||||
if (request_len == 0) {
|
||||
|
||||
if (
|
||||
!(sam_rx_buf[5] == 0xbd && sam_rx_buf[5 + 2] == 0x8a && sam_rx_buf[5 + 4] == 0x03)
|
||||
&&
|
||||
!(sam_rx_buf[5] == 0xbd && sam_rx_buf[5 + 2] == 0x8a && sam_rx_buf[5 + 4] == 0x03) &&
|
||||
!(sam_rx_buf[5] == 0xbd && sam_rx_buf[5 + 2] == 0xb3 && sam_rx_buf[5 + 4] == 0xa0)
|
||||
) {
|
||||
if (g_dbglevel >= DBG_ERROR)
|
||||
|
||||
if (g_dbglevel >= DBG_ERROR) {
|
||||
Dbprintf("No PACS data in SAM response");
|
||||
}
|
||||
res = PM3_ESOFT;
|
||||
}
|
||||
}
|
||||
|
@ -254,8 +248,6 @@ static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t r
|
|||
*response_len = sam_rx_buf[5 + 1] + 2;
|
||||
memcpy(response, sam_rx_buf + 5, *response_len);
|
||||
|
||||
goto out;
|
||||
|
||||
out:
|
||||
BigBuf_free();
|
||||
return res;
|
||||
|
@ -290,13 +282,13 @@ int sam_seos_get_pacs(PacketCommandNG *c) {
|
|||
// step 1: ping SAM
|
||||
sam_get_version();
|
||||
|
||||
if (!skipDetect) {
|
||||
if (skipDetect == false) {
|
||||
// step 2: get card information
|
||||
iso14a_card_select_t card_a_info;
|
||||
|
||||
// implicit StartSspClk() happens here
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
|
||||
if (!iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false)) {
|
||||
if (iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false) == 0) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -313,19 +305,21 @@ int sam_seos_get_pacs(PacketCommandNG *c) {
|
|||
if (res != PM3_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
if (g_dbglevel >= DBG_INFO)
|
||||
|
||||
if (g_dbglevel >= DBG_INFO) {
|
||||
print_result("Response data", sam_response, sam_response_len);
|
||||
}
|
||||
|
||||
goto out;
|
||||
goto off;
|
||||
|
||||
err:
|
||||
res = PM3_ENOPACS;
|
||||
reply_ng(CMD_HF_SAM_SEOS, res, NULL, 0);
|
||||
goto off;
|
||||
|
||||
out:
|
||||
reply_ng(CMD_HF_SAM_SEOS, PM3_SUCCESS, sam_response, sam_response_len);
|
||||
goto off;
|
||||
|
||||
off:
|
||||
if (disconnectAfter) {
|
||||
switch_off();
|
||||
|
|
|
@ -1839,15 +1839,13 @@ void annotateSeos(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool is
|
|||
}
|
||||
|
||||
if (memcmp(cmd + pos, "\x00\x87\x00", 3) == 0) {
|
||||
|
||||
uint8_t ks = cmd[pos + 3];
|
||||
if (memcmp(cmd + pos + 3 + 1, "\x04\x7c\x02\x81\x00", 5) == 0) {
|
||||
snprintf(exp, size, "GET CHALLENGE " _WHITE_("(") " key " _MAGENTA_("%02X") " )", ks);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (memcmp(cmd + pos, "\x00\x87\x00", 3) == 0) {
|
||||
uint8_t ks = cmd[pos + 3];
|
||||
if (memcmp(cmd + pos + 3 + 1, "\x2C\x7C\x2A\x82\x28", 5) == 0) {
|
||||
snprintf(exp, size, "MUTUAL AUTHENTICATION " _WHITE_("(") " key " _MAGENTA_("%02X") " )", ks);
|
||||
}
|
||||
|
|
|
@ -705,10 +705,12 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
PacketResponseNG resp;
|
||||
|
||||
if (hts) {
|
||||
|
||||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
for (size_t step = 0; step < 3; step++) {
|
||||
|
||||
switch (step) {
|
||||
case 0: {
|
||||
hitags_config_t config = {0};
|
||||
|
@ -722,18 +724,21 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
config.RES4 = 0x01;
|
||||
config.RES5 = 0x01;
|
||||
switch (clk) {
|
||||
case 64:
|
||||
case 64: {
|
||||
// 2 kBit/s
|
||||
config.TTFDR = 0x02;
|
||||
break;
|
||||
case 32:
|
||||
}
|
||||
case 32: {
|
||||
// 4 kBit/s
|
||||
config.TTFDR = 0x00;
|
||||
break;
|
||||
case 16:
|
||||
}
|
||||
case 16: {
|
||||
// 8 kBit/s
|
||||
config.TTFDR = 0x01;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//TODO: keep other fields?
|
||||
memcpy(packet.data, &config, sizeof(config));
|
||||
|
@ -741,30 +746,35 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
packet.page = 1;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 1: {
|
||||
memcpy(packet.data, &data[HITAGS_PAGE_SIZE * 0], HITAGS_PAGE_SIZE);
|
||||
packet.page = 4;
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
case 2: {
|
||||
memcpy(packet.data, &data[HITAGS_PAGE_SIZE * 1], HITAGS_PAGE_SIZE);
|
||||
packet.page = 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packet.cmd = HTSF_82xx;
|
||||
memcpy(packet.pwd, "\xBB\xDD\x33\x99", HITAGS_PAGE_SIZE);
|
||||
packet.mode = HITAGS_UID_REQ_FADV;
|
||||
|
||||
SendCommandNG(CMD_LF_HITAGS_WRITE, (uint8_t *)&packet, sizeof(packet));
|
||||
if (WaitForResponseTimeout(CMD_LF_HITAGS_WRITE, &resp, 4000) == false) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
PrintAndLogEx(WARNING, "Something went wrong in step %zu", step);
|
||||
return resp.status;
|
||||
}
|
||||
}
|
||||
} else if (htu) {
|
||||
|
||||
lf_hitag_data_t packet;
|
||||
memset(&packet, 0, sizeof(packet));
|
||||
|
||||
|
@ -774,6 +784,7 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
// memcpy(packet.pwd, "\x9A\xC4\x99\x9C", HITAGU_BLOCK_SIZE);
|
||||
|
||||
for (size_t step = 0; step < 3; step++) {
|
||||
|
||||
switch (step) {
|
||||
case 0: {
|
||||
// Configure datarate based on clock
|
||||
|
@ -789,27 +800,32 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
config.ttf = 0x01; // enable TTF
|
||||
|
||||
switch (clk) {
|
||||
case 64:
|
||||
case 64: {
|
||||
break;
|
||||
case 32:
|
||||
}
|
||||
case 32: {
|
||||
config.datarate = 0x01;
|
||||
break;
|
||||
case 16:
|
||||
}
|
||||
case 16: {
|
||||
config.datarate = 0x02;
|
||||
break;
|
||||
}
|
||||
}
|
||||
packet.data[0] = reflect8(*(uint8_t *)&config);
|
||||
packet.page = HITAGU_CONFIG_PADR; // Config block
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
case 1: {
|
||||
memcpy(packet.data, &data[HITAGU_BLOCK_SIZE * 0], HITAGU_BLOCK_SIZE);
|
||||
packet.page = 0; // Start writing EM410x data
|
||||
break;
|
||||
case 2:
|
||||
}
|
||||
case 2: {
|
||||
memcpy(packet.data, &data[HITAGU_BLOCK_SIZE * 1], HITAGU_BLOCK_SIZE);
|
||||
packet.page = 1; // Continue with second block
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SendCommandNG(CMD_LF_HITAGU_WRITE, (uint8_t *)&packet, sizeof(packet));
|
||||
|
@ -859,7 +875,7 @@ static int CmdEM410xClone(const char *Cmd) {
|
|||
switch (resp.status) {
|
||||
case PM3_SUCCESS: {
|
||||
PrintAndLogEx(SUCCESS, "Done!");
|
||||
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf em 410x reader`") " to verify");
|
||||
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("lf em 410x reader") "` to verify");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -210,7 +210,6 @@ static int process_hitagu_common_args(CLIParserContext *ctx, lf_hitag_data_t *co
|
|||
|
||||
int res = CLIParamHexToBuf(arg_get_str(ctx, 2), key, HITAG_PASSWORD_SIZE, &key_len);
|
||||
if (res != 0) {
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
|
@ -341,6 +340,7 @@ static int CmdLFHitagURead(const char *Cmd) {
|
|||
lf_hitag_data_t packet;
|
||||
|
||||
if (process_hitagu_common_args(ctx, &packet) < 0) {
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
|
@ -613,7 +613,10 @@ static int CmdLFHitagUWrite(const char *Cmd) {
|
|||
|
||||
lf_hitag_data_t packet;
|
||||
|
||||
if (process_hitagu_common_args(ctx, &packet) < 0) return PM3_EINVARG;
|
||||
if (process_hitagu_common_args(ctx, &packet) < 0) {
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
int page = arg_get_int_def(ctx, 3, 0);
|
||||
|
||||
|
|
|
@ -1916,15 +1916,14 @@ void DesfirePrintAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS
|
|||
}
|
||||
|
||||
if (appList[i].numberOfKeys > 0) {
|
||||
|
||||
PrintKeySettings(appList[i].keySettings, appList[i].numKeysRaw, true, true);
|
||||
|
||||
if (appList[i].numberOfKeys > 0) {
|
||||
PrintAndLogEx(SUCCESS, "Key versions [0..%d] " NOLF, appList[i].numberOfKeys - 1);
|
||||
for (uint8_t keyn = 0; keyn < appList[i].numberOfKeys; keyn++) {
|
||||
PrintAndLogEx(NORMAL, "%s %02x" NOLF, (keyn == 0) ? "" : ",", appList[i].keyVersions[keyn]);
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "\n");
|
||||
PrintAndLogEx(SUCCESS, "Key versions [0..%d] " NOLF, appList[i].numberOfKeys - 1);
|
||||
for (uint8_t keyn = 0; keyn < appList[i].numberOfKeys; keyn++) {
|
||||
PrintAndLogEx(NORMAL, "%s %02x" NOLF, (keyn == 0) ? "" : ",", appList[i].keyVersions[keyn]);
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "\n");
|
||||
|
||||
if (appList[i].filesReaded) {
|
||||
PrintAndLogEx(SUCCESS, "Application have " _GREEN_("%zu") " files", appList[i].filesCount);
|
||||
|
@ -1935,10 +1934,11 @@ void DesfirePrintAppList(DesfireContext_t *dctx, PICCInfo_t *PICCInfo, AppListS
|
|||
PrintAndLogEx(SUCCESS, "--------------------------------- " _CYAN_("File %02x") " ----------------------------------", appList[i].fileList[fnum].fileNum);
|
||||
PrintAndLogEx(SUCCESS, "File ID : " _GREEN_("%02x"), appList[i].fileList[fnum].fileNum);
|
||||
if (appList[i].isoPresent) {
|
||||
if (appList[i].fileList[fnum].fileISONum != 0)
|
||||
if (appList[i].fileList[fnum].fileISONum != 0) {
|
||||
PrintAndLogEx(SUCCESS, "File ISO ID : %04x", appList[i].fileList[fnum].fileISONum);
|
||||
else
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "File ISO ID : " _YELLOW_("n/a"));
|
||||
}
|
||||
}
|
||||
DesfirePrintFileSettingsExtended(&appList[i].fileList[fnum].fileSettings);
|
||||
}
|
||||
|
@ -2289,16 +2289,19 @@ static void PrintKeySettingsApp(uint8_t keysettings, uint8_t numkeys, bool print
|
|||
PrintAndLogEx(SUCCESS, "Application level rights");
|
||||
uint8_t rights = ((keysettings >> 4) & 0x0F);
|
||||
switch (rights) {
|
||||
case 0x0:
|
||||
case 0x0: {
|
||||
PrintAndLogEx(SUCCESS, " - AMK authentication is necessary to change any key (default)");
|
||||
break;
|
||||
case 0xE:
|
||||
}
|
||||
case 0xE: {
|
||||
PrintAndLogEx(SUCCESS, " - Authentication with the key to be changed (same KeyNo) is necessary to change a key");
|
||||
break;
|
||||
case 0xF:
|
||||
}
|
||||
case 0xF: {
|
||||
PrintAndLogEx(SUCCESS, " - All keys (except AMK,see Bit0) within this application are frozen");
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
PrintAndLogEx(SUCCESS,
|
||||
" - Authentication with the specified key " _YELLOW_("(0x%02x)") " is necessary to change any key.\n"
|
||||
"A change key and a PICC master key (CMK) can only be changed after authentication with the master key.\n"
|
||||
|
@ -2306,6 +2309,7 @@ static void PrintKeySettingsApp(uint8_t keysettings, uint8_t numkeys, bool print
|
|||
rights & 0x0f
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "[%c...] AMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : _RED_("NO (frozen)"));
|
||||
|
@ -2324,10 +2328,11 @@ static void PrintKeySettingsApp(uint8_t keysettings, uint8_t numkeys, bool print
|
|||
}
|
||||
|
||||
void PrintKeySettings(uint8_t keysettings, uint8_t numkeys, bool applevel, bool print2ndbyte) {
|
||||
if (applevel)
|
||||
if (applevel) {
|
||||
PrintKeySettingsApp(keysettings, numkeys, print2ndbyte);
|
||||
else
|
||||
} else {
|
||||
PrintKeySettingsPICC(keysettings, numkeys, print2ndbyte);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *DesfireUnknownStr = "unknown";
|
||||
|
|
|
@ -503,18 +503,22 @@ uint8_t DesfireKeyAlgoToType(DesfireCryptoAlgorithm keyType) {
|
|||
|
||||
void DesfirePrintCardKeyType(uint8_t keyType) {
|
||||
switch (keyType) {
|
||||
case 00:
|
||||
case 00: {
|
||||
PrintAndLogEx(SUCCESS, "Key type... " _YELLOW_("2TDEA"));
|
||||
break;
|
||||
case 01:
|
||||
}
|
||||
case 01: {
|
||||
PrintAndLogEx(SUCCESS, "Key type... " _YELLOW_("3TDEA"));
|
||||
break;
|
||||
case 02:
|
||||
}
|
||||
case 02: {
|
||||
PrintAndLogEx(SUCCESS, "Key type... " _YELLOW_("AES"));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
PrintAndLogEx(SUCCESS, "Key type... " _YELLOW_("unknown") " - 0x%02x", keyType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue