OLD/MIX convert to NG: Phase C3

This commit is contained in:
iceman1001 committed 2026-08-29 14:19:26 +02:00
1 parent ad629c77e8
commit f42564283e
5 files changed
+47 -20

No files matched your search

+12 -2
View File
@@ -2427,11 +2427,21 @@ static void PacketReceived(PacketCommandNG *packet) {
}
// Gen1a / 1b - "magic Chinese" card
case CMD_HF_MIFARE_CSETBL: {
MifareCSetBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
if (packet->length < sizeof(mf_chinese_blk_t) + MIFARE_BLOCK_SIZE) {
reply_ng(CMD_HF_MIFARE_CSETBL, PM3_EINVARG, NULL, 0);
break;
}
mf_chinese_blk_t *payload = (mf_chinese_blk_t *)packet->data.asBytes;
MifareCSetBlock(payload->params, payload->blockno, payload->data);
break;
}
case CMD_HF_MIFARE_CGETBL: {
MifareCGetBlock(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
if (packet->length < sizeof(mf_chinese_blk_t)) {
reply_ng(CMD_HF_MIFARE_CGETBL, PM3_EINVARG, NULL, 0);
break;
}
mf_chinese_blk_t *payload = (mf_chinese_blk_t *)packet->data.asBytes;
MifareCGetBlock(payload->params, payload->blockno, payload->data);
break;
}
case CMD_HF_MIFARE_CIDENT: {
+7 -7
View File
@@ -3051,9 +3051,9 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
} // end while
if (isOK)
reply_mix(CMD_ACK, 1, 0, 0, uid, sizeof(uid));
reply_ng(CMD_HF_MIFARE_CSETBL, PM3_SUCCESS, uid, sizeof(uid));
else
OnErrorMagic(errormsg);
OnErrorMagic(CMD_HF_MIFARE_CSETBL, errormsg);
if (workFlags & MAGIC_OFF)
OnSuccessMagic();
@@ -3153,9 +3153,9 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
} else {
if (isOK) {
reply_old(CMD_ACK, 1, 0, 0, data, sizeof(data));
reply_ng(CMD_HF_MIFARE_CGETBL, PM3_SUCCESS, data, sizeof(data));
} else {
OnErrorMagic(errormsg);
OnErrorMagic(CMD_HF_MIFARE_CGETBL, errormsg);
}
}
@@ -3667,9 +3667,9 @@ void OnSuccessMagic(void) {
set_tracing(false);
}
void OnErrorMagic(uint8_t reason) {
// ACK, ISOK, reason,0,0,0
reply_mix(CMD_ACK, 0, reason, 0, 0, 0);
void OnErrorMagic(uint16_t cmd, uint8_t reason) {
// the failure reason rides in the NG reason field
reply_reason(cmd, PM3_EUNDEF, reason, NULL, 0);
OnSuccessMagic();
}
+1 -1
View File
@@ -69,7 +69,7 @@ void MifarePersonalizeUID(uint8_t keyType, uint8_t perso_option, uint64_t key);
void MifareUSetKey(mful_setkey_t *packet);
void OnSuccessMagic(void);
void OnErrorMagic(uint8_t reason);
void OnErrorMagic(uint16_t cmd, uint8_t reason);
int32_t dist_nt(uint32_t nt1, uint32_t nt2);
//void RAMFUNC SniffMifare(uint8_t param);
+19 -10
View File
@@ -1269,23 +1269,28 @@ int mf_chinese_wipe(uint8_t *uid, const uint8_t *atqa, const uint8_t *sak, uint8
int mf_chinese_set_block(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t params) {
uint8_t buf[PM3_CMD_DATA_SIZE] = {0};
mf_chinese_blk_t *payload = (mf_chinese_blk_t *)buf;
payload->params = params;
payload->blockno = blockNo;
memcpy(payload->data, data, MFBLOCK_SIZE);
clearCommandBuffer();
SendCommandMIX(CMD_HF_MIFARE_CSETBL, params, blockNo, 0, data, MFBLOCK_SIZE);
SendCommandNG(CMD_HF_MIFARE_CSETBL, buf, sizeof(mf_chinese_blk_t) + MFBLOCK_SIZE);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 3500) == false) {
if (WaitForResponseTimeout(CMD_HF_MIFARE_CSETBL, &resp, 3500) == false) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, "Command execution time out");
return PM3_ETIMEOUT;
}
uint8_t isOK = resp.oldarg[0] & 0xFF;
if (uid != NULL) {
if ((uid != NULL) && (resp.status == PM3_SUCCESS) && (resp.length >= 4)) {
memcpy(uid, resp.data.asBytes, 4);
}
if (isOK == 0) {
if (resp.status != PM3_SUCCESS) {
uint8_t reason = (resp.oldarg[1] & 0xFF);
uint8_t reason = (uint8_t)resp.reason;
if (reason == 4) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, "GDM magic write signature block failed");
@@ -1301,12 +1306,16 @@ int mf_chinese_set_block(uint8_t blockNo, uint8_t *data, uint8_t *uid, uint8_t p
}
int mf_chinese_get_block(uint8_t blockNo, uint8_t *data, uint8_t params) {
mf_chinese_blk_t payload = {
.params = params,
.blockno = blockNo,
};
clearCommandBuffer();
SendCommandMIX(CMD_HF_MIFARE_CGETBL, params, blockNo, 0, NULL, 0);
SendCommandNG(CMD_HF_MIFARE_CGETBL, (uint8_t *)&payload, sizeof(payload));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
uint8_t isOK = resp.oldarg[0] & 0xff;
if (isOK == 0) {
if (WaitForResponseTimeout(CMD_HF_MIFARE_CGETBL, &resp, 1500)) {
if (resp.status != PM3_SUCCESS || resp.length < MFBLOCK_SIZE) {
return PM3_EUNDEF;
}
memcpy(data, resp.data.asBytes, MFBLOCK_SIZE);
+8
View File
@@ -399,6 +399,14 @@ typedef struct {
uint8_t key[6];
} PACKED mf_readsector_t;
// CMD_HF_MIFARE_CSETBL / CMD_HF_MIFARE_CGETBL payload.
// data[] carries the block to write for CSETBL, and is empty for CGETBL.
typedef struct {
uint8_t params; // MAGIC_* work flags
uint8_t blockno;
uint8_t data[];
} PACKED mf_chinese_blk_t;
// CMD_HF_MIFARE_GEN3UID payload
typedef struct {
uint8_t uidlen;