44
44
#include "gen4.h"
45
45
#include "parity.h"
46
46
47
- int mfDarkside (uint8_t blockno , uint8_t key_type , uint64_t * key ) {
47
+ int mf_dark_side (uint8_t blockno , uint8_t key_type , uint64_t * key ) {
48
48
uint32_t uid = 0 ;
49
49
uint32_t nt = 0 , nr = 0 , ar = 0 ;
50
50
uint64_t par_list = 0 , ks_list = 0 ;
@@ -189,7 +189,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
189
189
}
190
190
}
191
191
192
- if (mfCheckKeys (blockno , key_type - 0x60 , false, size , keyBlock , key ) == PM3_SUCCESS ) {
192
+ if (mf_check_keys (blockno , key_type - 0x60 , false, size , keyBlock , key ) == PM3_SUCCESS ) {
193
193
break ;
194
194
}
195
195
}
@@ -208,7 +208,7 @@ int mfDarkside(uint8_t blockno, uint8_t key_type, uint64_t *key) {
208
208
return PM3_SUCCESS ;
209
209
}
210
210
211
- int mfCheckKeys (uint8_t blockNo , uint8_t keyType , bool clear_trace , uint8_t keycnt , uint8_t * keyBlock , uint64_t * key ) {
211
+ int mf_check_keys (uint8_t blockNo , uint8_t keyType , bool clear_trace , uint8_t keycnt , uint8_t * keyBlock , uint64_t * key ) {
212
212
if (key ) {
213
213
* key = -1 ;
214
214
}
@@ -249,9 +249,9 @@ int mfCheckKeys(uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t keyc
249
249
// 0 == ok all keys found
250
250
// 1 ==
251
251
// 2 == Time-out, aborting
252
- int mfCheckKeys_fast_ex (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
253
- uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory ,
254
- bool verbose , bool quiet , uint16_t singleSectorParams ) {
252
+ int mf_check_keys_fast_ex (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
253
+ uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory ,
254
+ bool verbose , bool quiet , uint16_t singleSectorParams ) {
255
255
256
256
uint64_t t2 = msclock ();
257
257
@@ -357,15 +357,15 @@ int mfCheckKeys_fast_ex(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastChun
357
357
return PM3_ESOFT ;
358
358
}
359
359
360
- int mfCheckKeys_fast (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
361
- uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory , bool verbose ) {
362
- return mfCheckKeys_fast_ex (sectorsCnt , firstChunk , lastChunk , strategy , size , keyBlock , e_sector , use_flashmemory , verbose , false, 0 );
360
+ int mf_check_keys_fast (uint8_t sectorsCnt , uint8_t firstChunk , uint8_t lastChunk , uint8_t strategy ,
361
+ uint32_t size , uint8_t * keyBlock , sector_t * e_sector , bool use_flashmemory , bool verbose ) {
362
+ return mf_check_keys_fast_ex (sectorsCnt , firstChunk , lastChunk , strategy , size , keyBlock , e_sector , use_flashmemory , verbose , false, 0 );
363
363
}
364
364
365
365
// Trigger device to use a binary file on flash mem as keylist for mfCheckKeys.
366
366
// As of now, 255 keys possible in the file
367
367
// 6 * 255 = 1500 bytes
368
- int mfCheckKeys_file (uint8_t * destfn , uint64_t * key ) {
368
+ int mf_check_keys_file (uint8_t * destfn , uint64_t * key ) {
369
369
* key = -1 ;
370
370
clearCommandBuffer ();
371
371
@@ -412,7 +412,7 @@ int mfCheckKeys_file(uint8_t *destfn, uint64_t *key) {
412
412
413
413
// PM3 imp of J-Run mf_key_brute (part 2)
414
414
// ref: https://github.com/J-Run/mf_key_brute
415
- int mfKeyBrute (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint64_t * resultkey ) {
415
+ int mf_key_brute (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint64_t * resultkey ) {
416
416
417
417
uint64_t key64 ;
418
418
uint8_t found = false;
@@ -441,7 +441,7 @@ int mfKeyBrute(uint8_t blockNo, uint8_t keyType, const uint8_t *key, uint64_t *r
441
441
memcpy (keyBlock , candidates + i , KEYBLOCK_SIZE );
442
442
443
443
// check a block of generated key candidates.
444
- if (mfCheckKeys (blockNo , keyType , true, KEYS_IN_BLOCK , keyBlock , & key64 ) == PM3_SUCCESS ) {
444
+ if (mf_check_keys (blockNo , keyType , true, KEYS_IN_BLOCK , keyBlock , & key64 ) == PM3_SUCCESS ) {
445
445
* resultkey = key64 ;
446
446
found = true;
447
447
break ;
@@ -483,7 +483,7 @@ __attribute__((force_align_arg_pointer))
483
483
return statelist -> head .slhead ;
484
484
}
485
485
486
- int mfnested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey , bool calibrate ) {
486
+ int mf_nested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey , bool calibrate ) {
487
487
488
488
uint32_t uid ;
489
489
StateList_t statelists [2 ];
@@ -625,7 +625,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
625
625
num_to_bytes (key64 , 6 , keyBlock + j * MIFARE_KEY_SIZE );
626
626
}
627
627
628
- if (mfCheckKeys (statelists [0 ].blockNo , statelists [0 ].keyType , false, size , keyBlock , & key64 ) == PM3_SUCCESS ) {
628
+ if (mf_check_keys (statelists [0 ].blockNo , statelists [0 ].keyType , false, size , keyBlock , & key64 ) == PM3_SUCCESS ) {
629
629
free (statelists [0 ].head .slhead );
630
630
free (statelists [1 ].head .slhead );
631
631
num_to_bytes (key64 , 6 , resultKey );
@@ -669,7 +669,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo,
669
669
return PM3_ESOFT ;
670
670
}
671
671
672
- int mfStaticNested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey ) {
672
+ int mf_static_nested (uint8_t blockNo , uint8_t keyType , uint8_t * key , uint8_t trgBlockNo , uint8_t trgKeyType , uint8_t * resultKey ) {
673
673
674
674
uint32_t uid ;
675
675
StateList_t statelists [2 ];
@@ -902,9 +902,9 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBl
902
902
free (mem );
903
903
return res ;
904
904
}
905
- res = mfCheckKeys_file (fn , & key64 );
905
+ res = mf_check_keys_file (fn , & key64 );
906
906
} else {
907
- res = mfCheckKeys (statelists [0 ].blockNo , statelists [0 ].keyType , true, chunk , mem , & key64 );
907
+ res = mf_check_keys (statelists [0 ].blockNo , statelists [0 ].keyType , true, chunk , mem , & key64 );
908
908
}
909
909
910
910
if (res == PM3_SUCCESS ) {
@@ -949,7 +949,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBl
949
949
}
950
950
951
951
// MIFARE
952
- int mfReadSector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
952
+ int mf_read_sector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
953
953
954
954
clearCommandBuffer ();
955
955
SendCommandMIX (CMD_HF_MIFARE_READSC , sectorNo , keyType , 0 , (uint8_t * )key , MIFARE_KEY_SIZE );
@@ -970,7 +970,7 @@ int mfReadSector(uint8_t sectorNo, uint8_t keyType, const uint8_t *key, uint8_t
970
970
return PM3_SUCCESS ;
971
971
}
972
972
973
- int mfReadBlock (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
973
+ int mf_read_block (uint8_t blockNo , uint8_t keyType , const uint8_t * key , uint8_t * data ) {
974
974
mf_readblock_t payload = {
975
975
.blockno = blockNo ,
976
976
.keytype = keyType
@@ -994,7 +994,7 @@ int mfReadBlock(uint8_t blockNo, uint8_t keyType, const uint8_t *key, uint8_t *d
994
994
return PM3_SUCCESS ;
995
995
}
996
996
997
- int mfWriteBlock (uint8_t blockno , uint8_t keyType , const uint8_t * key , uint8_t * block ) {
997
+ int mf_write_block (uint8_t blockno , uint8_t keyType , const uint8_t * key , uint8_t * block ) {
998
998
999
999
uint8_t data [26 ];
1000
1000
memcpy (data , key , MIFARE_KEY_SIZE );
@@ -1014,10 +1014,10 @@ int mfWriteBlock(uint8_t blockno, uint8_t keyType, const uint8_t *key, uint8_t *
1014
1014
return res ;
1015
1015
}
1016
1016
1017
- int mfWriteSector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * sector ){
1018
-
1019
- for (int i = 0 ; i < 4 ; i ++ ) {
1020
- int res = mfWriteBlock (( sectorNo * 4 ) + i , keyType , key , sector + ( i * MFBLOCK_SIZE ));
1017
+ int mf_write_sector (uint8_t sectorNo , uint8_t keyType , const uint8_t * key , uint8_t * sector ) {
1018
+ int res ;
1019
+ for (int i = 0 ; i < mfNumBlocksPerSector ( sectorNo ) ; i ++ ) {
1020
+ res = mf_write_block (( mfFirstBlockOfSector ( sectorNo )) + i , keyType , key , sector + (i * MFBLOCK_SIZE ));
1021
1021
if (res != PM3_SUCCESS ) {
1022
1022
return (i == 0 ) ? PM3_EFAILED : PM3_EPARTIAL ;
1023
1023
}
@@ -1026,7 +1026,7 @@ int mfWriteSector(uint8_t sectorNo, uint8_t keyType, const uint8_t *key, uint8_t
1026
1026
}
1027
1027
1028
1028
// EMULATOR
1029
- int mfEmlGetMem (uint8_t * data , int blockNum , int blocksCount ) {
1029
+ int mf_eml_get_mem (uint8_t * data , int blockNum , int blocksCount ) {
1030
1030
1031
1031
size_t size = blocksCount * MFBLOCK_SIZE ;
1032
1032
if (size > PM3_CMD_DATA_SIZE ) {
@@ -1056,11 +1056,11 @@ int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
1056
1056
return resp .status ;
1057
1057
}
1058
1058
1059
- int mfEmlSetMem (uint8_t * data , int blockNum , int blocksCount ) {
1060
- return mfEmlSetMem_xt (data , blockNum , blocksCount , MFBLOCK_SIZE );
1059
+ int mf_elm_set_mem (uint8_t * data , int blockNum , int blocksCount ) {
1060
+ return mf_eml_set_mem_xt (data , blockNum , blocksCount , MFBLOCK_SIZE );
1061
1061
}
1062
1062
1063
- int mfEmlSetMem_xt (uint8_t * data , int blockNum , int blocksCount , int blockBtWidth ) {
1063
+ int mf_eml_set_mem_xt (uint8_t * data , int blockNum , int blocksCount , int blockBtWidth ) {
1064
1064
1065
1065
struct p {
1066
1066
uint8_t blockno ;
@@ -1089,13 +1089,13 @@ int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidt
1089
1089
}
1090
1090
1091
1091
// "MAGIC" CARD
1092
- int mfCSetUID (uint8_t * uid , uint8_t uidlen , const uint8_t * atqa , const uint8_t * sak , uint8_t * old_uid , uint8_t * verifed_uid , uint8_t wipecard , uint8_t gdm ) {
1092
+ int mf_chinese_set_uid (uint8_t * uid , uint8_t uidlen , const uint8_t * atqa , const uint8_t * sak , uint8_t * old_uid , uint8_t * verifed_uid , uint8_t wipecard , uint8_t gdm ) {
1093
1093
1094
1094
uint8_t params = MAGIC_SINGLE | (gdm ? MAGIC_GDM_ALT_WUPC : MAGIC_WUPC );
1095
1095
uint8_t block0 [MFBLOCK_SIZE ];
1096
1096
memset (block0 , 0x00 , sizeof (block0 ));
1097
1097
1098
- int res = mfCGetBlock (0 , block0 , params );
1098
+ int res = mf_chinese_get_block (0 , block0 , params );
1099
1099
if (res == 0 ) {
1100
1100
PrintAndLogEx (SUCCESS , "old block 0... %s" , sprint_hex_inrow (block0 , sizeof (block0 )));
1101
1101
if (old_uid ) {
@@ -1140,11 +1140,11 @@ int mfCSetUID(uint8_t *uid, uint8_t uidlen, const uint8_t *atqa, const uint8_t *
1140
1140
params |= MAGIC_WIPE ;
1141
1141
}
1142
1142
1143
- res = mfCSetBlock (0 , block0 , NULL , params );
1143
+ res = mf_chinese_set_block (0 , block0 , NULL , params );
1144
1144
if (res == PM3_SUCCESS ) {
1145
1145
params = MAGIC_SINGLE | MAGIC_WUPC ;
1146
1146
memset (block0 , 0 , sizeof (block0 ));
1147
- res = mfCGetBlock (0 , block0 , params );
1147
+ res = mf_chinese_get_block (0 , block0 , params );
1148
1148
if (res == 0 ) {
1149
1149
if (verifed_uid ) {
1150
1150
memcpy (verifed_uid , block0 , uidlen );
@@ -1154,7 +1154,7 @@ int mfCSetUID(uint8_t *uid, uint8_t uidlen, const uint8_t *atqa, const uint8_t *
1154
1154
return res ;
1155
1155
}
1156
1156
1157
- int mfCWipe (uint8_t * uid , const uint8_t * atqa , const uint8_t * sak , uint8_t gdm ) {
1157
+ int mf_chinese_wipe (uint8_t * uid , const uint8_t * atqa , const uint8_t * sak , uint8_t gdm ) {
1158
1158
uint8_t block0 [MFBLOCK_SIZE ] = {0x00 , 0x56 , 0x78 , 0xBB , 0x95 , 0x08 , 0x04 , 0x00 , 0x02 , 0xB2 , 0x1E , 0x24 , 0x23 , 0x27 , 0x1E , 0x1D };
1159
1159
// uint8_t block0[MFBLOCK_SIZE] = {0x04, 0x03, 0x02, 0x01, 0x04, 0x08, 0x04, 0x00, 0x64, 0xB9, 0x95, 0x11, 0x4D, 0x20, 0x42, 0x09};
1160
1160
uint8_t blockD [MFBLOCK_SIZE ] = {0x00 };
@@ -1180,12 +1180,12 @@ int mfCWipe(uint8_t *uid, const uint8_t *atqa, const uint8_t *sak, uint8_t gdm)
1180
1180
PrintAndLogEx (INPLACE , "wipe block %d" , blockNo );
1181
1181
1182
1182
if (blockNo == 0 ) {
1183
- res = mfCSetBlock (blockNo , block0 , NULL , params );
1183
+ res = mf_chinese_set_block (blockNo , block0 , NULL , params );
1184
1184
} else {
1185
1185
if (mfIsSectorTrailer (blockNo ))
1186
- res = mfCSetBlock (blockNo , blockK , NULL , params );
1186
+ res = mf_chinese_set_block (blockNo , blockK , NULL , params );
1187
1187
else
1188
- res = mfCSetBlock (blockNo , blockD , NULL , params );
1188
+ res = mf_chinese_set_block (blockNo , blockD , NULL , params );
1189
1189
}
1190
1190
1191
1191
if (res == PM3_SUCCESS )
@@ -1204,7 +1204,7 @@ int mfCWipe(uint8_t *uid, const uint8_t *atqa, const uint8_t *sak, uint8_t gdm)
1204
1204
return PM3_SUCCESS ;
1205
1205
}
1206
1206
1207
- int mfCSetBlock (uint8_t blockNo , uint8_t * data , uint8_t * uid , uint8_t params ) {
1207
+ int mf_chinese_set_block (uint8_t blockNo , uint8_t * data , uint8_t * uid , uint8_t params ) {
1208
1208
clearCommandBuffer ();
1209
1209
SendCommandMIX (CMD_HF_MIFARE_CSETBL , params , blockNo , 0 , data , MFBLOCK_SIZE );
1210
1210
PacketResponseNG resp ;
@@ -1224,7 +1224,7 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params) {
1224
1224
return PM3_SUCCESS ;
1225
1225
}
1226
1226
1227
- int mfCGetBlock (uint8_t blockNo , uint8_t * data , uint8_t params ) {
1227
+ int mf_chinese_get_block (uint8_t blockNo , uint8_t * data , uint8_t params ) {
1228
1228
clearCommandBuffer ();
1229
1229
SendCommandMIX (CMD_HF_MIFARE_CGETBL , params , blockNo , 0 , NULL , 0 );
1230
1230
PacketResponseNG resp ;
@@ -1241,7 +1241,7 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
1241
1241
return PM3_SUCCESS ;
1242
1242
}
1243
1243
1244
- int mfGen3UID (uint8_t * uid , uint8_t uidlen , uint8_t * oldUid ) {
1244
+ int mf_chinese_gen_3_uid (uint8_t * uid , uint8_t uidlen , uint8_t * oldUid ) {
1245
1245
clearCommandBuffer ();
1246
1246
SendCommandMIX (CMD_HF_MIFARE_GEN3UID , uidlen , 0 , 0 , uid , uidlen );
1247
1247
PacketResponseNG resp ;
@@ -1256,7 +1256,7 @@ int mfGen3UID(uint8_t *uid, uint8_t uidlen, uint8_t *oldUid) {
1256
1256
}
1257
1257
}
1258
1258
1259
- int mfGen3Block (uint8_t * block , int blockLen , uint8_t * newBlock ) {
1259
+ int mf_chinese_gen_3_block (uint8_t * block , int blockLen , uint8_t * newBlock ) {
1260
1260
clearCommandBuffer ();
1261
1261
SendCommandMIX (CMD_HF_MIFARE_GEN3BLK , blockLen , 0 , 0 , block , MFBLOCK_SIZE );
1262
1262
PacketResponseNG resp ;
@@ -1271,7 +1271,7 @@ int mfGen3Block(uint8_t *block, int blockLen, uint8_t *newBlock) {
1271
1271
}
1272
1272
}
1273
1273
1274
- int mfGen3Freeze (void ) {
1274
+ int mf_chinese_gen_3_freeze (void ) {
1275
1275
clearCommandBuffer ();
1276
1276
SendCommandNG (CMD_HF_MIFARE_GEN3FREEZ , NULL , 0 );
1277
1277
PacketResponseNG resp ;
@@ -1301,7 +1301,7 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i
1301
1301
}
1302
1302
}
1303
1303
1304
- int tryDecryptWord (uint32_t nt , uint32_t ar_enc , uint32_t at_enc , uint8_t * data , int len ) {
1304
+ int try_decrypt_word (uint32_t nt , uint32_t ar_enc , uint32_t at_enc , uint8_t * data , int len ) {
1305
1305
1306
1306
PrintAndLogEx (SUCCESS , "encrypted data... %s" , sprint_hex (data , len ));
1307
1307
uint32_t ks2 = ar_enc ^ prng_successor (nt , 64 );
@@ -1636,7 +1636,7 @@ uint16_t detect_mf_magic(bool is_mfc, uint8_t key_type, uint64_t key) {
1636
1636
1637
1637
bool detect_mfc_ev1_signature (void ) {
1638
1638
uint64_t key = 0 ;
1639
- int res = mfCheckKeys (69 , MF_KEY_B , false, 1 , (uint8_t * )g_mifare_signature_key_b , & key );
1639
+ int res = mf_check_keys (69 , MF_KEY_B , false, 1 , (uint8_t * )g_mifare_signature_key_b , & key );
1640
1640
return (res == PM3_SUCCESS );
1641
1641
}
1642
1642
@@ -1645,17 +1645,17 @@ int read_mfc_ev1_signature(uint8_t *signature) {
1645
1645
return PM3_EINVARG ;
1646
1646
}
1647
1647
uint8_t sign [32 ] = {0 };
1648
- int res = mfReadBlock (69 , MF_KEY_B , g_mifare_signature_key_b , sign );
1648
+ int res = mf_read_block (69 , MF_KEY_B , g_mifare_signature_key_b , sign );
1649
1649
if (res == PM3_SUCCESS ) {
1650
- res = mfReadBlock (70 , MF_KEY_B , g_mifare_signature_key_b , sign + 16 );
1650
+ res = mf_read_block (70 , MF_KEY_B , g_mifare_signature_key_b , sign + 16 );
1651
1651
if (res == PM3_SUCCESS ) {
1652
1652
memcpy (signature , sign , sizeof (sign ));
1653
1653
}
1654
1654
} else {
1655
1655
// try QL88
1656
- res = mfReadBlock (69 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign );
1656
+ res = mf_read_block (69 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign );
1657
1657
if (res == PM3_SUCCESS ) {
1658
- res = mfReadBlock (70 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign + 16 );
1658
+ res = mf_read_block (70 , MF_KEY_B , g_mifare_ql88_signature_key_b , sign + 16 );
1659
1659
if (res == PM3_SUCCESS ) {
1660
1660
memcpy (signature , sign , sizeof (sign ));
1661
1661
}
0 commit comments