make style

This commit is contained in:
Philippe Teuwen committed 2026-06-07 23:01:20 +02:00
1 parent ff04e1ea9a
commit efcc34a698
9 files changed
+910 -197

No files matched your search

+1 -1
View File
@@ -133,7 +133,7 @@ static size_t ansi_byte_count(const char *s) {
n += 2;
s += 2;
while (*s) {
unsigned char c = (unsigned char)*s++;
unsigned char c = (unsigned char) * s++;
n++;
if (c >= 0x40 && c <= 0x7E) {
break;
+28 -27
View File
@@ -844,9 +844,9 @@ int mfp_data_crypt(mf4Session_t *mf4session, uint8_t *dati, uint8_t *dato, bool
}
if (rev) {
aes_decode(IV, kenc, dati, dato, MFBLOCK_SIZE*bc);
aes_decode(IV, kenc, dati, dato, MFBLOCK_SIZE * bc);
} else {
aes_encode(IV, kenc, dati, dato, MFBLOCK_SIZE*bc);
aes_encode(IV, kenc, dati, dato, MFBLOCK_SIZE * bc);
}
return PM3_SUCCESS;
@@ -2244,10 +2244,10 @@ static int CmdHFMFPDump(const char *Cmd) {
int STRead;
uint8_t mac[8] = {0};
chunkCycle:
ki_pA[1] = sl3Count*2;
ki_pA[1] = sl3Count * 2;
MifareAuth4(&_session, ki_pA, &aesFoundKeys[MF_KEY_A][sl3Count][1], nonfirst, !nonfirst, true, true, verbose, false);
nonfirst = true;
MFPReadBlock(&_session, false, false, true, 3+sl3Count*4, 1, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
MFPReadBlock(&_session, false, false, true, 3 + sl3Count * 4, 1, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
PrintAndLogEx(ERR, "\nTrailer read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
goto chunkBlank;
@@ -2257,17 +2257,17 @@ chunkCycle:
}
mfp_data_crypt(&_session, &STBuffer[1], &STBuffer[1], true, 1);
// Multiblock reads do not allow reading out STs, as such this is the time to save them into the final dump
memcpy(carddata + ((3+4*sl3Count) * MFBLOCK_SIZE), &STBuffer[1], 1 * MFBLOCK_SIZE);
memcpy(carddata + ((3 + 4 * sl3Count) * MFBLOCK_SIZE), &STBuffer[1], 1 * MFBLOCK_SIZE);
// Check if any block is encrypted only
ki_pB[1] = 0x01+sl3Count*2;
ki_pB[1] = 0x01+sl3Count * 2;
MifareAuth4(&_session, ki_pB, &aesFoundKeys[MF_KEY_B][sl3Count][1], true, false, true, true, verbose, false);
if (STBuffer[6] & 0xF0) { // At least one bit is set to force enc. only
MFPReadBlock(&_session, false, false, true, sl3Count*4, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
MFPReadBlock(&_session, false, false, true, sl3Count * 4, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
chunkBlank:
PrintAndLogEx(ERR, "\nChunk read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
memcpy(carddata + (sl3Count * 4 * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
memcpy(carddata + ((3+4*sl3Count) * MFBLOCK_SIZE), nullBlock, 1 * MFBLOCK_SIZE);
memcpy(carddata + ((3 + 4 * sl3Count) * MFBLOCK_SIZE), nullBlock, 1 * MFBLOCK_SIZE);
PrintAndLogEx(WARNING, "Quick-reading sector %3d / %3d ( " _RED_("fail") " )", sl3Count, numSectors - 1);
// Restart auth since a read failure resets it
nonfirst = false;
@@ -2285,7 +2285,7 @@ chunkBlank:
sectorsRead++;
sl3Count++;
} else {
MFPReadBlock(&_session, true, false, true, sl3Count*4, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
MFPReadBlock(&_session, true, false, true, sl3Count * 4, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
PrintAndLogEx(ERR, "Chunk read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
memcpy(carddata + (sl3Count * 4 * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
@@ -2308,12 +2308,12 @@ chunkCycleClean:
if (numSectors>32){
if (numSectors > 32) {
chunkCycle2:
ki_pA[1] = sl3Count*2;
ki_pA[1] = sl3Count * 2;
MifareAuth4(&_session, ki_pA, &aesFoundKeys[MF_KEY_A][sl3Count][1], nonfirst, !nonfirst, true, true, verbose, false);
nonfirst = true;
MFPReadBlock(&_session, false, false, true, 128+(sl3Count-31)*16-1, 1, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
MFPReadBlock(&_session, false, false, true, 128 + (sl3Count - 31) * 16 - 1, 1, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
PrintAndLogEx(ERR, "Trailer read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
goto chunkBlank2;
@@ -2324,22 +2324,23 @@ chunkCycle2:
}
mfp_data_crypt(&_session, &STBuffer[1], &STBuffer[1], true, 1);
// Multiblock reads do not allow reading out STs, as such this is the time to save them into the final dump
memcpy(carddata + ((128+(sl3Count-31)*16-1) * MFBLOCK_SIZE), &STBuffer[1], 1 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + (sl3Count - 31) * 16 - 1) * MFBLOCK_SIZE), &STBuffer[1], 1 * MFBLOCK_SIZE);
int c = 0;
// Check if any block is encrypted only
ki_pB[1] = 0x01+sl3Count*2;
ki_pB[1] = 0x01+sl3Count * 2;
MifareAuth4(&_session, ki_pB, &aesFoundKeys[MF_KEY_B][sl3Count][1], true, false, true, true, verbose, false);
if (STBuffer[6] & 0xF0) { // At least one bit is set to force enc. only
chunkBlank2: // Jumping here will start the cycle which will blank out the remaining 5 chunks anyway
for (c=0; c<5; ++c) {
MFPReadBlock(&_session, false, false, true, 128+(sl3Count-32)*16+c*3, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
for (c = 0; c < 5; ++c) {
MFPReadBlock(&_session, false, false, true, 128 + (sl3Count - 32) * 16 + c * 3, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
PrintAndLogEx(ERR, "Chunk read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
PrintAndLogEx(WARNING, "Quick-reading sector %3d / %3d chunk %d ( " _RED_("fail") " )", sl3Count, numSectors - 1, c);
memcpy(carddata + ((128+(sl3Count-31)*16-1) * MFBLOCK_SIZE), nullBlock, 1 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + 16*(sl3Count-32)+c*3) * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + (sl3Count - 31) * 16 - 1) * MFBLOCK_SIZE), nullBlock, 1 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + 16 * (sl3Count - 32) + c * 3) * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
nonfirst = false;
if (c<5) {continue;} else {sl3Count++; goto chunkCycleClean2;};
if (c < 5) {continue;}
else {sl3Count++; goto chunkCycleClean2;};
}
if (STRead != 1 + 48 + 2) {
PrintAndLogEx(ERR, "Error return length: %d", STRead);
@@ -2348,16 +2349,16 @@ chunkBlank2: // Jumping here will start the cycle which will blank out the remai
}
mfp_data_crypt(&_session, &STBuffer[1], &STBuffer[1], true, 3);
PrintAndLogEx(INPLACE, "Quick-reading sector %3d / %3d ( " _GREEN_("ok") " )", sl3Count, numSectors - 1);
memcpy(carddata + ((128 + 16*(sl3Count-32)+c*3) * MFBLOCK_SIZE), &STBuffer[1], 3 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + 16 * (sl3Count - 32) + c * 3) * MFBLOCK_SIZE), &STBuffer[1], 3 * MFBLOCK_SIZE);
}
sectorsRead++;
sl3Count++;
} else {
for (c=0; c<5; ++c) {
MFPReadBlock(&_session, true, false, true, 128+(sl3Count-32)*16+c*3, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
for (c = 0; c < 5; ++c) {
MFPReadBlock(&_session, true, false, true, 128 + (sl3Count - 32) * 16 + c * 3, 3, false, true, STBuffer, sizeof(STBuffer), &STRead, mac);
if (STRead && STBuffer[0] != 0x90) {
PrintAndLogEx(ERR, "Chunk read error: %02x %s", STBuffer[0], mfpGetErrorDescription(STBuffer[0]));
memcpy(carddata + ((128 + 16*(sl3Count-32)+c*3) * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + 16 * (sl3Count - 32) + c * 3) * MFBLOCK_SIZE), nullChunk, 3 * MFBLOCK_SIZE);
PrintAndLogEx(WARNING, "Quick-reading sector %3d / %3d ( " _RED_("fail") " )", sl3Count, numSectors - 1);
continue;
}
@@ -2367,8 +2368,8 @@ chunkBlank2: // Jumping here will start the cycle which will blank out the remai
return PM3_ESOFT;
}
PrintAndLogEx(INPLACE, "Quick-reading sector %3d / %3d ( " _GREEN_("ok") " )", sl3Count, numSectors - 1);
memcpy(carddata + ((128 + 16*(sl3Count-32)+c*3) * MFBLOCK_SIZE), &STBuffer[1], 3 * MFBLOCK_SIZE);
memcpy(carddata + ((128 + 16 * (sl3Count - 32) + c * 3) * MFBLOCK_SIZE), &STBuffer[1], 3 * MFBLOCK_SIZE);
}
sectorsRead++;
sl3Count++;
@@ -2445,7 +2446,7 @@ chunkCycleClean2:
DropField();
t1 = msclock() - t1;
// ========================================
// Print sector summary
// ========================================
@@ -2546,7 +2547,7 @@ chunkCycleClean2:
PrintAndLogEx(HINT, "Partial dump: %d of %d sectors read", sectorsRead, numSectors);
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`hf mfp chk --dump`") " and/or " _YELLOW_("`hf mf chk`") " to find more keys");
}
PrintAndLogEx(INFO, "\ntime in dump " _YELLOW_("%.0f") " seconds\n", (float)t1 / 1000.0);
free(carddata);
return PM3_SUCCESS;
+6 -4
View File
@@ -224,7 +224,8 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
}
uint8_t cmd1[4];
if (nonfirst) { cmd1[0] = 0x76; cmd1[1] = keyn[1]; cmd1[2] = keyn[0]; } else { cmd1[0] = 0x70; cmd1[1] = keyn[1]; cmd1[2] = keyn[0]; cmd1[3] = 0x00; }
if (nonfirst) { cmd1[0] = 0x76; cmd1[1] = keyn[1]; cmd1[2] = keyn[0]; }
else { cmd1[0] = 0x70; cmd1[1] = keyn[1]; cmd1[2] = keyn[0]; cmd1[3] = 0x00; }
int res = ExchangeRAW14a(cmd1, nonfirst ? 3 : 4, activateField, true, data, sizeof(data), &datalen, silentMode);
if (res != PM3_SUCCESS) {
@@ -307,7 +308,7 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
memcpy(&IVW[12], &mf4session->R_Ctr, 2);
memcpy(&IVW[14], &mf4session->W_Ctr, 2);
memcpy(IVW, mf4session->TI, 4);
aes_decode(IVR, key, &data[1], RndB, 16);
RndB[16] = RndB[0];
if (verbose) {
@@ -353,7 +354,7 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
PrintAndLogEx(INFO, "< phase2: %s", sprint_hex(data, datalen));
}
if (data[0]!=0x90) {
if (data[0] != 0x90) {
if (silentMode == false) {
PrintAndLogEx(ERR, "\nAuthentication FAILED. Card did not ACK response");
}
@@ -364,7 +365,8 @@ int MifareAuth4(mf4Session_t *mf4session, const uint8_t *keyn, uint8_t *key, boo
return PM3_EWRONGANSWER;
}
if (nonfirst) { aes_decode(IVR, key, &data[1], raw, 16); } else { aes_decode(NULL, key, &data[1], raw, 32); }
if (nonfirst) { aes_decode(IVR, key, &data[1], raw, 16); }
else { aes_decode(NULL, key, &data[1], raw, 32); }
if (verbose) {
if (nonfirst) {
+35
View File
@@ -276,6 +276,40 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf fido auth" },
{ 0, "hf fido make" },
{ 0, "hf fido assert" },
{ 1, "hf fmcos help" },
{ 0, "hf fmcos info" },
{ 0, "hf fmcos select" },
{ 0, "hf fmcos erase" },
{ 0, "hf fmcos createdir" },
{ 0, "hf fmcos createfile" },
{ 0, "hf fmcos createkeyfile" },
{ 0, "hf fmcos readbinary" },
{ 0, "hf fmcos readrecord" },
{ 0, "hf fmcos writebinary" },
{ 0, "hf fmcos writerecord" },
{ 0, "hf fmcos append" },
{ 0, "hf fmcos authexternal" },
{ 0, "hf fmcos authinternal" },
{ 0, "hf fmcos key" },
{ 0, "hf fmcos pinverify" },
{ 0, "hf fmcos pinchange" },
{ 0, "hf fmcos pinreset" },
{ 0, "hf fmcos pinunblock" },
{ 0, "hf fmcos balance" },
{ 0, "hf fmcos credit" },
{ 0, "hf fmcos purchase" },
{ 0, "hf fmcos overdraft" },
{ 0, "hf fmcos history" },
{ 0, "hf fmcos block" },
{ 0, "hf fmcos unblock" },
{ 0, "hf fmcos tidsetcard" },
{ 0, "hf fmcos tidsetuid" },
{ 0, "hf fmcos tidsetauth" },
{ 0, "hf fmcos tiderase" },
{ 0, "hf fmcos tidprovision" },
{ 0, "hf fmcos tidcreatedf" },
{ 0, "hf fmcos tidcreatebin" },
{ 0, "hf fmcos tidcreaterec" },
{ 1, "hf fudan help" },
{ 0, "hf fudan reader" },
{ 0, "hf fudan dump" },
@@ -357,6 +391,7 @@ const static vocabulary_t vocabulary[] = {
{ 0, "hf legic reader" },
{ 0, "hf legic restore" },
{ 0, "hf legic clone" },
{ 0, "hf legic migrate" },
{ 0, "hf legic wipe" },
{ 0, "hf legic wrbl" },
{ 0, "hf legic sim" },