Merge branch 'master' into fix-thinfilm-sim-restart

Signed-off-by: Iceman <iceman@iuse.se>
This commit is contained in:
Iceman authored and GitHub committed 2026-11-07 16:52:28 +08:00
commit 22e9e59b27
12 files changed
+441 -67

No files matched your search

+195 -7
View File
@@ -8105,6 +8105,177 @@ static int mfc_supercard_gen2_recovery(uint8_t items, uint8_t tracedata[FURUI_MA
return PM3_SUCCESS;
}
// super card generation 2, UID write
#define SUPER_GEN2_UID_LEN 7 // UID bytes sent, zero padded
#define SUPER_GEN2_ACK 0x11 // command accepted
#define SUPER_GEN2_COMMITTED 0x22 // halt answer
// select a super card. Clears the trace when the field is kept, so a later `hf 14a list` holds only the write
static int mfc_supercard_select(bool keep_field_on, iso14a_card_select_t *card) {
uint32_t flags = ISO14A_CONNECT | ISO14A_NO_RATS;
if (keep_field_on) {
flags |= ISO14A_NO_DISCONNECT | ISO14A_CLEARTRACE;
}
clearCommandBuffer();
SendIso14aReader(flags, NULL, 0);
PacketResponseNG resp;
uint16_t len = 0;
uint8_t sel = 0;
if (WaitForIso14aReply(&resp, 1500, &len, &sel) == false) {
return PM3_ETIMEOUT;
}
if (sel == 0) {
return PM3_ECARDEXCHANGE;
}
if (len < sizeof(iso14a_card_select_t)) {
PrintAndLogEx(FAILED, "Short select answer, %u bytes. Client and firmware out of sync?", len);
return PM3_ELENGTH;
}
memcpy(card, resp.data.asBytes, sizeof(iso14a_card_select_t));
if (card->uidlen == 0) {
return PM3_ECARDEXCHANGE;
}
return PM3_SUCCESS;
}
// one frame of the gen2 UID write. PM3_ECARDEXCHANGE when the card stayed silent,
// PM3_EWRONGANSWER when it answered and refused
static int mfc_supercard_gen2_frame(uint8_t cmd, uint8_t arg, uint8_t status) {
uint8_t data[2] = {cmd, arg};
uint32_t flags = ISO14A_RAW | ISO14A_APPEND_CRC | ISO14A_NO_DISCONNECT;
clearCommandBuffer();
SendIso14aReader(flags, data, sizeof(data));
PacketResponseNG resp;
uint16_t len = 0;
if (WaitForIso14aReply(&resp, 1500, &len, NULL) == false) {
return PM3_ETIMEOUT;
}
PrintAndLogEx(DEBUG, "%02X %02X >>> %s", cmd, arg, sprint_hex_inrow(resp.data.asBytes, len));
// the device reports a silent card as a zero length answer, not as a timeout
if (len == 0) {
return PM3_ECARDEXCHANGE;
}
// 18 byte answer on the wire, 16 byte payload plus CRC. Only the payload is required
if (len < 16) {
PrintAndLogEx(FAILED, "Short answer... %s", sprint_hex_inrow(resp.data.asBytes, len));
return PM3_ELENGTH;
}
if (resp.data.asBytes[0] != status || resp.data.asBytes[1] != arg) {
PrintAndLogEx(FAILED, "Card answered... %s, expected status %02X arg %02X",
sprint_hex_inrow(resp.data.asBytes, len), status, arg);
return PM3_EWRONGANSWER;
}
return PM3_SUCCESS;
}
// change UID on a super card generation 2. Knock, UID one byte per command,
// then HLTA, which commits - without it the card discards the write on field drop
static int mfc_supercard_gen2_set_uid(const uint8_t *uid, uint8_t uidlen) {
static const uint8_t knock[] = {0xF3, 0x2A, 0xBD, 0xEF, 0x01};
iso14a_card_select_t old_card = {0};
int res = mfc_supercard_select(true, &old_card);
if (res != PM3_SUCCESS) {
if (res == PM3_ETIMEOUT) {
PrintAndLogEx(FAILED, "Device did not answer the select command");
} else {
PrintAndLogEx(FAILED, "Failed to select card, is it on the antenna?");
}
DropField();
return res;
}
// these parts are physically 4 or 7 byte, the length is not changeable
if (old_card.uidlen != uidlen) {
PrintAndLogEx(FAILED, "Card UID is " _YELLOW_("%u") " bytes, new UID is " _YELLOW_("%u") " bytes", old_card.uidlen, uidlen);
DropField();
return PM3_EINVARG;
}
for (uint8_t i = 0; i < ARRAYLEN(knock); i++) {
res = mfc_supercard_gen2_frame(0x30, knock[i], SUPER_GEN2_ACK);
if (res != PM3_SUCCESS) {
if (res == PM3_ECARDEXCHANGE) {
PrintAndLogEx(FAILED, "Card stopped answering at knock command " _YELLOW_("%u") " of %zu", i + 1, ARRAYLEN(knock));
} else {
PrintAndLogEx(FAILED, "Card rejected knock command " _YELLOW_("%u") " of %zu", i + 1, ARRAYLEN(knock));
PrintAndLogEx(HINT, "Hint: Are you sure your card is a super card generation 2?");
}
DropField();
return res;
}
}
uint8_t new_uid[SUPER_GEN2_UID_LEN] = {0};
memcpy(new_uid, uid, uidlen);
for (uint8_t i = 0; i < SUPER_GEN2_UID_LEN; i++) {
res = mfc_supercard_gen2_frame(0x30, new_uid[i], SUPER_GEN2_ACK);
if (res != PM3_SUCCESS) {
if (res == PM3_ECARDEXCHANGE) {
PrintAndLogEx(FAILED, "Card stopped answering at UID byte " _YELLOW_("%u") " of %u, the write is incomplete", i + 1, SUPER_GEN2_UID_LEN);
PrintAndLogEx(HINT, "Hint: hold the card still on the antenna and run the command again");
} else {
PrintAndLogEx(FAILED, "Card rejected UID byte " _YELLOW_("%u") " of %u", i + 1, SUPER_GEN2_UID_LEN);
}
DropField();
return res;
}
}
// not fatal, the UID read back below decides the outcome
int res_halt = mfc_supercard_gen2_frame(0x50, 0x00, SUPER_GEN2_COMMITTED);
if (res_halt != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "Card did not acknowledge the commit (%d), verifying anyway", res_halt);
}
DropField();
iso14a_card_select_t new_card = {0};
res = PM3_ETIMEOUT;
// card is writing, it ignores the first activation attempts
for (uint8_t i = 0; i < 4 && res != PM3_SUCCESS; i++) {
msleep(150);
res = mfc_supercard_select(false, &new_card);
PrintAndLogEx(DEBUG, "verify activation %u... %d", i + 1, res);
}
if (res != PM3_SUCCESS) {
PrintAndLogEx(FAILED, "Card did not answer after the commit, can't verify the new UID");
PrintAndLogEx(WARNING, "The write may still have succeeded, the card ignores activation while writing");
PrintAndLogEx(HINT, "Hint: keep the card on the antenna and run `hf 14a info`");
return PM3_EPARTIAL;
}
if (new_card.uidlen != uidlen || memcmp(new_card.uid, uid, uidlen) != 0) {
PrintAndLogEx(FAILED, "Super card UID change [ " _RED_("fail") " ]");
PrintAndLogEx(INFO, "Card UID... %s", sprint_hex(new_card.uid, new_card.uidlen));
return PM3_ESOFT;
}
PrintAndLogEx(SUCCESS, "Old UID... %s", sprint_hex(old_card.uid, old_card.uidlen));
PrintAndLogEx(SUCCESS, "New UID... %s", sprint_hex(new_card.uid, new_card.uidlen));
PrintAndLogEx(SUCCESS, "Super card UID change ( " _GREEN_("ok") " )");
return PM3_SUCCESS;
}
static int CmdHf14AMfSuperCard(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mf supercard",
@@ -8116,13 +8287,13 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_lit0("r", "reset", "Reset card"),
arg_str0("u", "uid", "<hex>", "New UID (4 hex bytes)"),
arg_str0("u", "uid", "<hex>", "New UID (4 hex bytes, or 7 on generation 2)"),
arg_lit0(NULL, "furui", "Furui detection card"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
bool reset_card = arg_get_lit(ctx, 1);
uint8_t uid[4];
uint8_t uid[7] = {0};
int uidlen = 0;
int res = CLIParamHexToBuf(arg_get_str(ctx, 2), uid, sizeof(uid), &uidlen);
bool is_furui = arg_get_lit(ctx, 3);
@@ -8130,8 +8301,13 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
CLIParserFree(ctx);
// sanity checks
if (res || (!res && uidlen && uidlen != sizeof(uid))) {
PrintAndLogEx(ERR, "UID must include 4 hex bytes");
if (res) {
PrintAndLogEx(ERR, "UID must be 4 or 7 hex bytes");
return PM3_EINVARG;
}
if (uidlen && uidlen != 4 && uidlen != 7) {
PrintAndLogEx(ERR, "UID must be 4 or 7 hex bytes. Got %d", uidlen);
return PM3_EINVARG;
}
@@ -8143,7 +8319,7 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
// no reset on super card FURUI
if (uidlen || reset_card) {
PrintAndLogEx(FAILED, "Not supported on this card");
return PM3_SUCCESS;
return PM3_ENOTIMPL;
}
// read 8 traces
@@ -8211,9 +8387,14 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
if (i == SUPER_MAX_TRACES) {
// no reset on super card generation 2.
if (uidlen || reset_card) {
if (reset_card) {
PrintAndLogEx(FAILED, "Not supported on this card");
return PM3_SUCCESS;
return PM3_ENOTIMPL;
}
// change UID on a super card generation 2
if (uidlen) {
return mfc_supercard_gen2_set_uid(uid, uidlen);
}
// recover key from collected traces
@@ -8231,6 +8412,13 @@ static int CmdHf14AMfSuperCard(const char *Cmd) {
// change UID on a super card generation 1
if (uidlen) {
// generation 1 is 4 byte UID only
if (uidlen != 4) {
PrintAndLogEx(FAILED, "Super card generation 1 UID must be 4 hex bytes");
return PM3_EINVARG;
}
keep_field_on = false;
uint8_t response[6];
int resplen = 0;
+65
View File
@@ -2028,6 +2028,69 @@ int mfu_get_version_uid(uint8_t *version, uint8_t *uid) {
return PM3_SUCCESS;
}
// Weak-PRNG backstop: RndB collision => counterfeit LFSR
#define MFULC_PRNG_SAMPLES 40
#define MFULC_PRNG_CLEAR 39
static int mfulc_prng_test(uint32_t samples) {
if (samples < 2) {
samples = 2;
}
if (samples > 64) {
samples = 64;
}
uint8_t rndb[64][8];
uint32_t got = 0;
for (uint32_t i = 0; i < samples; i++) {
iso14a_card_select_t card;
if (ul_select(&card) == false) {
continue;
}
uint8_t nonce[11] = {0x00};
int rl = ulc_requestAuthentication(nonce, sizeof(nonce));
DropField();
// response is AF || ek(RndB)[8] || CRC[2]; compare the 8-byte ek(RndB)
if (rl < 9 || nonce[0] != 0xAF) {
continue;
}
memcpy(rndb[got], &nonce[1], 8);
got++;
}
if (got < 2) {
PrintAndLogEx(INFO, "PRNG......... could not collect nonces (got %u)", got);
return PM3_ESOFT;
}
uint32_t first_dup = 0;
uint32_t dups = 0;
for (uint32_t i = 0; i < got; i++) {
for (uint32_t j = 0; j < i; j++) {
if (memcmp(rndb[i], rndb[j], 8) == 0) {
if (first_dup == 0) {
first_dup = i + 1; // 1-based draw index
}
dups++;
break;
}
}
}
if (dups > 0) {
PrintAndLogEx(SUCCESS, "PRNG......... " _RED_("Weak") " (RndB collision at %u)", first_dup);
return PM3_SUCCESS;
}
if (got >= MFULC_PRNG_CLEAR) {
PrintAndLogEx(SUCCESS, "PRNG......... " _GREEN_("Genuine"));
} else {
PrintAndLogEx(INFO, "PRNG......... inconclusive (%u/%u nonces)", got, (uint32_t)MFULC_PRNG_CLEAR);
}
return PM3_SUCCESS;
}
static int mfulc_fingerprint(void) {
iso14a_card_select_t card;
PacketResponseNG resp;
@@ -2139,6 +2202,8 @@ static int mfulc_fingerprint(void) {
}
}
}
// weak-PRNG backstop
mfulc_prng_test(MFULC_PRNG_SAMPLES);
PrintAndLogEx(INFO, "likely MF0ICU2");
DropField();
return PM3_SUCCESS;
+7 -1
View File
@@ -475,6 +475,11 @@ static int CmdHFHIDConfigSim(const char *Cmd) {
char uid_str[2 * sizeof(uid) + 1];
strncpy(uid_str, sprint_hex_inrow(uid, uidlen), sizeof(uid_str) - 1);
uid_str[sizeof(uid_str) - 1] = '\0';
// an all-zero UID makes the device take a 4-byte UID from emulator memory
bool uid_from_emul = (memcmp(uid, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", sizeof(uid)) == 0);
if (uid_from_emul) {
snprintf(uid_str, sizeof(uid_str), "from emulator memory");
}
PrintAndLogEx(INFO, "HID Config Card sim:"
" UID " _YELLOW_("%s")
" AID " _YELLOW_("%s")
@@ -490,7 +495,8 @@ static int CmdHFHIDConfigSim(const char *Cmd) {
payload.tagtype = 4; // ISO14443-4 base type; ATQA/SAK/ATS overridden by ARM
payload.flags = flags;
payload.exitAfter = exitAfterNReads;
payload.atqa[0] = 0x02; // HID Config Card ATQA high byte
// HID Config Card ATQA high byte, b8 b7 code the UID size (ISO/IEC 14443-3)
payload.atqa[0] = 0x02 | ((uid_from_emul || uidlen == 4) ? 0x00 : ((uidlen == 7) ? 0x40 : 0x80));
payload.atqa[1] = 0x00; // HID Config Card ATQA low byte
payload.sak = 0x38; // HID Config Card SAK
payload.ats_len = (uint8_t)ats_len;
+26 -6
View File
@@ -248,8 +248,8 @@ static int CmdKeriClone(const char *Cmd) {
int typeLen = sizeof(keritype) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
CLIGetStrWithReturn(ctx, 1, keritype, &typeLen);
uint32_t fc = arg_get_int_def(ctx, 2, 0);
uint32_t cid = arg_get_int_def(ctx, 3, 0);
int fc_arg = arg_get_int_def(ctx, 2, 0);
int cn_arg = arg_get_int_def(ctx, 3, 0);
bool q5 = arg_get_lit(ctx, 4);
bool em = arg_get_lit(ctx, 5);
CLIParserFree(ctx);
@@ -259,6 +259,20 @@ static int CmdKeriClone(const char *Cmd) {
return PM3_EINVARG;
}
if (fc_arg < 0 || cn_arg < 0) {
PrintAndLogEx(FAILED, "FC and CN can't be negative");
return PM3_EINVARG;
}
// the MS scramble carries 5 bits of fc and 22 of cn
if (keritype[0] == 'm' && (fc_arg > 31 || cn_arg > 0x3FFFFF)) {
PrintAndLogEx(FAILED, "MS FC has a max value of 31 and CN has a max value of 4194303");
return PM3_EINVARG;
}
uint32_t fc = (uint32_t)fc_arg;
uint32_t cid = (uint32_t)cn_arg;
// Setup card data/build internal id
uint32_t internalid = 0;
switch (keritype[0]) {
@@ -310,7 +324,7 @@ static int CmdKeriClone(const char *Cmd) {
}
PrintAndLogEx(SUCCESS, "Done!");
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf keri read`") " to verify");
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf keri reader`") " to verify");
return res;
}
@@ -320,7 +334,7 @@ static int CmdKeriSim(const char *Cmd) {
CLIParserInit(&ctx, "lf keri sim",
"Enables simulation of KERI card with internal ID.\n"
"You supply a KERI card id and it will converted to a KERI internal ID.",
"lf keri sim --cn 112233"
"lf keri sim --id 112233"
);
void *argtable[] = {
@@ -332,6 +346,14 @@ static int CmdKeriSim(const char *Cmd) {
uint64_t internalid = arg_get_u64_def(ctx, 1, 0);
CLIParserFree(ctx);
// the frame carries 31 bits of internal id
if (internalid > 0x7FFFFFFF) {
PrintAndLogEx(FAILED, "Internal Id has a max value of 2147483647");
return PM3_EINVARG;
}
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64) ", Raw: E0000000%08" PRIX64, internalid, internalid | 0x80000000);
internalid |= 0x80000000;
internalid <<= 3;
internalid += 7;
@@ -343,8 +365,6 @@ static int CmdKeriSim(const char *Cmd) {
bs[j++] = ((internalid >> i) & 1);
}
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64), internalid);
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
if (payload == NULL) {
PrintAndLogEx(WARNING, "Failed to allocate memory");
+7 -5
View File
@@ -333,8 +333,9 @@ static int CmdParadoxClone(const char *Cmd) {
return PM3_EINVARG;
}
if (fc > 999 || cn > 99999) {
PrintAndLogEx(FAILED, "FC has a max value of 999 and CN has a max value of 99999");
// the frame carries 8 bits of fc and 16 of cn
if (fc > 0xFF || cn > 0xFFFF) {
PrintAndLogEx(FAILED, "FC has a max value of 255 and CN has a max value of 65535");
return PM3_EINVARG;
}
@@ -384,7 +385,7 @@ static int CmdParadoxClone(const char *Cmd) {
res = clone_t55xx_tag(blocks, ARRAYLEN(blocks));
}
PrintAndLogEx(SUCCESS, "Done!");
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf paradox read`") " to verify");
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf paradox reader`") " to verify");
return res;
}
@@ -421,8 +422,9 @@ static int CmdParadoxSim(const char *Cmd) {
return PM3_EINVARG;
}
if (fc > 999 || cn > 99999) {
PrintAndLogEx(FAILED, "FC has a max value of 999 and CN has a max value of 99999");
// the frame carries 8 bits of fc and 16 of cn
if (fc > 0xFF || cn > 0xFFFF) {
PrintAndLogEx(FAILED, "FC has a max value of 255 and CN has a max value of 65535");
return PM3_EINVARG;
}
if (raw_len != 0) {
+1 -1
View File
@@ -135,7 +135,7 @@ static int wiegand_encode_new_pacs_from_bin(const uint8_t *binarr, int blen, boo
int CmdWiegandList(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "wiegand info",
CLIParserInit(&ctx, "wiegand list",
"List available wiegand formats",
"wiegand list"
);
+29 -17
View File
@@ -1440,12 +1440,17 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
switch (ndef[indx]) {
case 0x00: {
indx++;
uint16_t len = ndefTLVGetLength(&ndef[indx], &indx);
PrintAndLogEx(SUCCESS, "--- " _CYAN_("NDEF NULL block") " ---");
if (len)
PrintAndLogEx(WARNING, "NDEF NULL block size must be 0, got %d bytes", len);
indx += len;
// a NULL TLV is the T byte alone, without length
size_t run = 0;
while ((indx < ndefLen) && (ndef[indx] == 0x00)) {
indx++;
run++;
}
if (run == 1) {
PrintAndLogEx(SUCCESS, "--- " _CYAN_("NDEF NULL block") " ---");
} else {
PrintAndLogEx(SUCCESS, "--- " _CYAN_("NDEF NULL block") " --- x %zu", run);
}
break;
}
case 0x01: {
@@ -1458,15 +1463,16 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
} else {
uint8_t pages_addr = (ndef[indx] >> 4) & 0x0f;
uint8_t byte_offset = ndef[indx] & 0x0f;
uint8_t Size = ndef[indx + 1];
uint8_t BytesLockedPerLockBit = (ndef[indx + 2] >> 4) & 0x0f;
uint8_t bytes_per_page = ndef[indx + 2] & 0x0f;
// Type 2 Tag spec: Size 0 is 256 lock bits, both nibbles are powers of two
uint16_t Size = (ndef[indx + 1]) ? ndef[indx + 1] : 256;
uint16_t BytesLockedPerLockBit = 1 << ((ndef[indx + 2] >> 4) & 0x0f);
uint16_t bytes_per_page = 1 << (ndef[indx + 2] & 0x0f);
PrintAndLogEx(SUCCESS, " Pages addr (number of pages).... %d", pages_addr);
PrintAndLogEx(SUCCESS, " Byte offset (number of bytes)... %d", byte_offset);
PrintAndLogEx(SUCCESS, " Lock Area size in bits.......... %d ( %d bytes )", Size, Size / 8);
PrintAndLogEx(SUCCESS, " Number of bytes / page... %d", bytes_per_page);
PrintAndLogEx(SUCCESS, " Lock Area size in bits.......... %u ( %u bytes )", Size, (Size + 7) / 8);
PrintAndLogEx(SUCCESS, " Number of bytes / page... %u", bytes_per_page);
PrintAndLogEx(SUCCESS, " Bytes Locked Per LockBit");
PrintAndLogEx(SUCCESS, " number of bytes that each dynamic lock bit locks... %d", BytesLockedPerLockBit);
PrintAndLogEx(SUCCESS, " number of bytes that each dynamic lock bit locks... %u", BytesLockedPerLockBit);
}
indx += len;
break;
@@ -1481,11 +1487,12 @@ int NDEFDecodeAndPrint(uint8_t *ndef, size_t ndefLen, bool verbose) {
} else {
uint8_t pages_addr = (ndef[indx] >> 4) & 0x0f;
uint8_t byte_offset = ndef[indx] & 0x0f;
uint8_t Size = ndef[indx + 1];
uint8_t bytes_per_page = ndef[indx + 2] & 0x0f;
// Type 2 Tag spec: Size is in bytes, 0 is 256, the page size is a power of two
uint16_t Size = (ndef[indx + 1]) ? ndef[indx + 1] : 256;
uint16_t bytes_per_page = 1 << (ndef[indx + 2] & 0x0f);
PrintAndLogEx(SUCCESS, "Pages addr (number of pages).... %u", pages_addr);
PrintAndLogEx(SUCCESS, "Byte offset (number of bytes)... %u", byte_offset);
PrintAndLogEx(SUCCESS, "Reserved area size in bits...... %u ( %u bytes )", Size, Size / 8);
PrintAndLogEx(SUCCESS, "Reserved area size in bytes..... %u", Size);
PrintAndLogEx(SUCCESS, " Number of bytes / page... %u", bytes_per_page);
}
indx += len;
@@ -1541,8 +1548,13 @@ int NDEFGetTotalLength(uint8_t *ndef, size_t ndeflen, size_t *outlen) {
size_t idx = 0;
while (idx < ndeflen) {
if (ndef[idx] == 0x00 ||
ndef[idx] == 0x01 ||
// a NULL TLV is the T byte alone, no length
if (ndef[idx] == 0x00) {
idx++;
continue;
}
if (ndef[idx] == 0x01 ||
ndef[idx] == 0x02 ||
ndef[idx] == 0x03 ||
ndef[idx] == 0xFD) {
+25 -26
View File
@@ -384,7 +384,7 @@ static bool Pack_hpp32(int format_idx, wiegand_card_t *card, wiegand_message_t *
packed->Length = 32; // Set number of bits
set_linear_field(packed, card->FacilityCode, 1, 12);
set_linear_field(packed, card->CardNumber, 13, 29);
set_linear_field(packed, card->CardNumber, 13, 18);
if (preamble)
return add_HID_header(packed);
@@ -398,7 +398,7 @@ static bool Unpack_hpp32(wiegand_message_t *packed, wiegand_card_t *card) {
memset(card, 0, sizeof(wiegand_card_t));
card->FacilityCode = get_linear_field(packed, 1, 12);
card->CardNumber = get_linear_field(packed, 13, 29);
card->CardNumber = get_linear_field(packed, 13, 18);
return true;
}
@@ -627,20 +627,20 @@ static bool Pack_H10320(int format_idx, wiegand_card_t *card, wiegand_message_t
// This card is BCD-encoded rather than binary. Set the 4-bit groups independently.
for (uint32_t idx = 0; idx < 8; idx++) {
set_linear_field(packed, (uint64_t)(card->CardNumber / pow(10, 7 - idx)) % 10, idx * 4, 4);
set_linear_field(packed, (uint64_t)(card->CardNumber / pow(10, 7 - idx)) % 10, 1 + idx * 4, 4);
}
set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {0, 4, 8, 12, 16, 20, 24, 28})
), 32);
set_bit_by_position(packed, oddparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {1, 5, 9, 13, 17, 21, 25, 29})
), 33);
set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 28, 30})
set_bit_by_position(packed, oddparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 26, 30})
), 34);
set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 29, 31})
get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 27, 31})
), 35);
set_bit_by_position(packed, evenparity32(
get_nonlinear_field(packed, 8, (uint8_t[]) {4, 8, 12, 16, 20, 24, 28, 32})
), 36);
if (preamble)
return add_HID_header(packed);
return true;
@@ -657,7 +657,7 @@ static bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) {
// This card is BCD-encoded rather than binary. Get the 4-bit groups independently.
for (uint32_t idx = 0; idx < 8; idx++) {
uint64_t val = get_linear_field(packed, idx * 4, 4);
uint64_t val = get_linear_field(packed, 1 + idx * 4, 4);
if (val > 9) {
// Violation of BCD; Zero and exit.
card->CardNumber = 0;
@@ -667,10 +667,10 @@ static bool Unpack_H10320(wiegand_message_t *packed, wiegand_card_t *card) {
}
}
card->ParityValid =
(get_bit_by_position(packed, 32) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {0, 4, 8, 12, 16, 20, 24, 28}))) &&
(get_bit_by_position(packed, 33) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {1, 5, 9, 13, 17, 21, 25, 29}))) &&
(get_bit_by_position(packed, 34) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 28, 30}))) &&
(get_bit_by_position(packed, 35) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 29, 31})));
(get_bit_by_position(packed, 33) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {1, 5, 9, 13, 17, 21, 25, 29}))) &&
(get_bit_by_position(packed, 34) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {2, 6, 10, 14, 18, 22, 26, 30}))) &&
(get_bit_by_position(packed, 35) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {3, 7, 11, 15, 19, 23, 27, 31}))) &&
(get_bit_by_position(packed, 36) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {4, 8, 12, 16, 20, 24, 28, 32})));
return true;
}
@@ -726,7 +726,6 @@ static bool Pack_S12906b(int format_idx, wiegand_card_t *card, wiegand_message_t
if (!validate_card_limit(format_idx, card)) return false;
if (card->FacilityCode != S12906b_FACILITY_CODE) return false;
if (card->IssueLevel != 0u) return false; // This card does not support issue levels
if (!card->ParityValid) return false; // Cannot intentionally guess which parity caller wants to invalidate
if (card->OEM != 0u) return false; // Card does not support OEM values
packed->Length = 36; // Set number of bits
@@ -950,7 +949,7 @@ static bool Unpack_HGeneric37(wiegand_message_t *packed, wiegand_card_t *card) {
card->CardNumber = get_linear_field(packed, 4, 32);
card->ParityValid =
(get_bit_by_position(packed, 0) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {4, 8, 12, 16, 20, 24, 28, 32}))) &&
(get_bit_by_position(packed, 2) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {6, 10, 14, 18, 22, 28, 30, 34}))) &&
(get_bit_by_position(packed, 2) == oddparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {6, 10, 14, 18, 22, 26, 30, 34}))) &&
(get_bit_by_position(packed, 3) == evenparity32(get_nonlinear_field(packed, 8, (uint8_t[]) {7, 11, 15, 19, 23, 27, 31, 35})))
;
return true;
@@ -1562,16 +1561,16 @@ static const cardformat_t FormatTable[] = {
{"ind29", Pack_ind29, Unpack_ind29, "Indala 29-bit", 29, {1, 1, 0, 0, 0, 0x00001FFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"ATSW30", Pack_ATSW30, Unpack_ATSW30, "ATS Wiegand 30-bit", 30, {1, 1, 0, 0, 1, 0x00000FFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"ADT31", Pack_ADT31, Unpack_ADT31, "HID ADT 31-bit", 31, {1, 1, 0, 0, 0, 0x0000000Fu, 0x00000000007FFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"HCP32", Pack_hcp32, Unpack_hcp32, "HID Check Point 32-bit", 32, {1, 0, 0, 0, 0, 0x00000000u, 0x0000000000003FFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"HPP32", Pack_hpp32, Unpack_hpp32, "HID Hewlett-Packard 32-bit", 32, {1, 1, 0, 0, 0, 0x00000FFFu, 0x000000001FFFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"HCP32", Pack_hcp32, Unpack_hcp32, "HID Check Point 32-bit", 32, {1, 0, 0, 0, 0, 0x00000000u, 0x0000000000FFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"HPP32", Pack_hpp32, Unpack_hpp32, "HID Hewlett-Packard 32-bit", 32, {1, 1, 0, 0, 0, 0x00000FFFu, 0x000000000003FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"Kastle", Pack_Kastle, Unpack_Kastle, "Kastle 32-bit", 32, {1, 1, 1, 0, 1, 0x000000FFu, 0x000000000000FFFFu, 0x0000001Fu, 0x00000000u}}, // from @xilni; PR #23 on RfidResearchGroup/proxmark3
{"Kantech", Pack_Kantech, Unpack_Kantech, "Indala/Kantech KFS 32-bit", 32, {1, 1, 0, 0, 0, 0x000000FFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"WIE32", Pack_wie32, Unpack_wie32, "Wiegand 32-bit", 32, {1, 1, 0, 0, 0, 0x00000FFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"D10202", Pack_D10202, Unpack_D10202, "HID D10202 33-bit", 33, {1, 1, 0, 0, 1, 0x0000007Fu, 0x0000000000FFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"H10306", Pack_H10306, Unpack_H10306, "HID H10306 34-bit", 34, {1, 1, 0, 0, 1, 0x0000FFFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // imported from old pack/unpack
{"N10002", Pack_N10002, Unpack_N10002, "Honeywell/Northern N10002 34-bit", 34, {1, 1, 0, 0, 1, 0x0000FFFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from proxclone.com
{"Optus34", Pack_Optus, Unpack_Optus, "Indala Optus 34-bit", 34, {1, 1, 0, 0, 0, 0x000003FFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"SMP34", Pack_Smartpass, Unpack_Smartpass, "Cardkey Smartpass 34-bit", 34, {1, 1, 1, 0, 0, 0x000003FFu, 0x000000000000FFFFu, 0x00000007u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"Optus34", Pack_Optus, Unpack_Optus, "Indala Optus 34-bit", 34, {1, 1, 0, 0, 0, 0x000007FFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"SMP34", Pack_Smartpass, Unpack_Smartpass, "Cardkey Smartpass 34-bit", 34, {1, 1, 1, 0, 0, 0x00001FFFu, 0x000000000000FFFFu, 0x00000007u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"BQT34", Pack_bqt34, Unpack_bqt34, "BQT 34-bit", 34, {1, 1, 0, 0, 1, 0x000000FFu, 0x0000000000FFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"C1k35s", Pack_C1k35s, Unpack_C1k35s, "HID Corporate 1000 35-bit std", 35, {1, 1, 0, 0, 1, 0x00000FFFu, 0x00000000000FFFFFu, 0x00000000u, 0x00000000u}}, // imported from old pack/unpack
{"C15001", Pack_C15001, Unpack_C15001, "HID KeyScan 36-bit", 36, {1, 1, 0, 1, 1, 0x000000FFu, 0x000000000000FFFFu, 0x00000000u, 0x000003FFu}}, // from Proxmark forums
@@ -1582,15 +1581,15 @@ static const cardformat_t FormatTable[] = {
{"H10302", Pack_H10302, Unpack_H10302, "HID H10302 37-bit huge ID", 37, {1, 0, 0, 0, 1, 0x00000000u, 0x00000007FFFFFFFFu, 0x00000000u, 0x00000000u}}, // from Proxmark forums
{"H10304", Pack_H10304, Unpack_H10304, "HID H10304 37-bit", 37, {1, 1, 0, 0, 1, 0x0000FFFFu, 0x000000000007FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"P10004", Pack_P10004, Unpack_P10004, "HID P10004 37-bit PCSC", 37, {1, 1, 0, 0, 0, 0x00001FFFu, 0x000000000003FFFFu, 0x00000000u, 0x00000000u}}, // from @bthedorff; PR #1559
{"HGen37", Pack_HGeneric37, Unpack_HGeneric37, "HID Generic 37-bit", 37, {1, 0, 0, 0, 1, 0x00000000u, 0x000000000007FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"HGen37", Pack_HGeneric37, Unpack_HGeneric37, "HID Generic 37-bit", 37, {1, 0, 0, 0, 1, 0x00000000u, 0x00000000FFFFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"MDI37", Pack_MDI37, Unpack_MDI37, "PointGuard MDI 37-bit", 37, {1, 1, 0, 0, 1, 0x0000000Fu, 0x000000001FFFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"BQT38", Pack_bqt38, Unpack_bqt38, "BQT 38-bit", 38, {1, 1, 1, 0, 1, 0x00000FFFu, 0x000000000003FFFFu, 0x00000007u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"ISCS", Pack_iscs38, Unpack_iscs38, "ISCS 38-bit", 38, {1, 1, 0, 1, 1, 0x000003FFu, 0x0000000000FFFFFFu, 0x00000000u, 0x00000007u}}, // from cardinfo.barkweb.com.au
{"PW39", Pack_pw39, Unpack_pw39, "Pyramid 39-bit wiegand format", 39, {1, 1, 0, 0, 1, 0x0000FFFFu, 0x00000000000FFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"BQT38", Pack_bqt38, Unpack_bqt38, "BQT 38-bit", 38, {1, 1, 1, 0, 1, 0x00001FFFu, 0x000000000007FFFFu, 0x0000000Fu, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"ISCS", Pack_iscs38, Unpack_iscs38, "ISCS 38-bit", 38, {1, 1, 0, 1, 1, 0x000003FFu, 0x00000000003FFFFFu, 0x00000000u, 0x0000000Fu}}, // from cardinfo.barkweb.com.au
{"PW39", Pack_pw39, Unpack_pw39, "Pyramid 39-bit wiegand format", 39, {1, 1, 0, 0, 1, 0x0001FFFFu, 0x00000000000FFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"P10001", Pack_P10001, Unpack_P10001, "HID P10001 Honeywell 40-bit", 40, {1, 1, 0, 0, 0, 0x00000FFFu, 0x000000000000FFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"Casi40", Pack_CasiRusco40, Unpack_CasiRusco40, "Casi-Rusco 40-bit", 40, {1, 0, 0, 0, 0, 0x00000000u, 0x000000FFFFFFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"Casi40", Pack_CasiRusco40, Unpack_CasiRusco40, "Casi-Rusco 40-bit", 40, {1, 0, 0, 0, 0, 0x00000000u, 0x0000003FFFFFFFFFu, 0x00000000u, 0x00000000u}}, // from cardinfo.barkweb.com.au
{"Verkada40", Pack_Verkada40, Unpack_Verkada40, "Verkada 40-bit", 40, {1, 1, 0, 0, 1, 0x000003FFu, 0x000000000FFFFFFFu, 0x00000000u, 0x00000000u}}, // Verkada 40-bit format
{"BC40", Pack_bc40, Unpack_bc40, "Bundy TimeClock 40-bit", 40, {1, 1, 0, 1, 1, 0x00000FFFu, 0x00000000000FFFFFu, 0x00000000u, 0x0000007Fu}}, // from
{"BC40", Pack_bc40, Unpack_bc40, "Bundy TimeClock 40-bit", 40, {1, 1, 0, 1, 1, 0x00000FFFu, 0x000000000007FFFFu, 0x00000000u, 0x0000007Fu}}, // from
{"Defcon32", Pack_Defcon32, Unpack_Defcon32, "Custom Defcon RFCTF 42-bit", 42, {1, 1, 1, 0, 1, 0x0000FFFFu, 0x00000000000FFFFFu, 0x0000000Fu, 0x00000000u}}, // Created by (@micsen) for the CTF
{"H800002", Pack_H800002, Unpack_H800002, "HID H800002 46-bit", 46, {1, 1, 0, 0, 1, 0x00003FFFu, 0x000000003FFFFFFFu, 0x00000000u, 0x00000000u}},
{"C1k48s", Pack_C1k48s, Unpack_C1k48s, "HID Corporate 1000 48-bit std", 48, {1, 1, 0, 0, 1, 0x003FFFFFu, 0x00000000007FFFFFu, 0x00000000u, 0x00000000u}}, // imported from old pack/unpack