Merge branch 'master' into feat/supercard-gen2-uid-write

Signed-off-by: Iceman <iceman@iuse.se>
This commit is contained in:
Iceman authored and GitHub committed 2026-11-07 09:46:11 +08:00
commit 4b5eadd32b
24 files changed
+406 -140

No files matched your search

@@ -146,6 +146,13 @@
"type": "payment",
"description": "nanaco e-money system"
},
{
"code": "0801",
"name": "DoCARD",
"region": "Japan",
"type": "transit",
"description": "Used by legacy DoCARD transit card (Dohoku Bus, Hokkaido)"
},
{
"code": "12FC",
"name": "NDEF Type 3 Tag",
@@ -181,6 +188,20 @@
"type": "transit",
"description": "Used by legacy Nagasaki Smart Card transit system (Nagasaki operators)"
},
{
"code": "8019",
"name": "Sony Finance",
"region": "Japan",
"type": "payment",
"description": "Sony Finance e-money system; used by K-Touch cards"
},
{
"code": "801D",
"name": "Sony Finance",
"region": "Japan",
"type": "payment",
"description": "Marker system found on Edy cards issued by Sony Finance"
},
{
"code": "801E",
"name": "AMPM",
@@ -209,6 +230,27 @@
"type": "transit",
"description": "Used by Hokkaido Kitami Bus transit card"
},
{
"code": "8054",
"name": "PRONTO",
"region": "Japan",
"type": "payment",
"description": "Marker system found on Edy cards issued by PRONTO"
},
{
"code": "8082",
"name": "ANA",
"region": "Japan",
"type": "loyalty",
"description": "Marker system found on ANA Mileage Club cards"
},
{
"code": "80BB",
"name": "CLUB DAM",
"region": "Japan",
"type": "loyalty",
"description": "Used by Edy Club DAM Members Cards"
},
{
"code": "80DE",
"name": "IruCa",
@@ -286,6 +328,13 @@
"type": "payment",
"description": "Used by ANA QuicPay + Nanaco fob"
},
{
"code": "8188",
"name": "PokePark",
"region": "Japan",
"type": "payment",
"description": "Marker system found on Edy cards issued by PokePark"
},
{
"code": "8194",
"name": "Kagoshima",
@@ -570,6 +619,13 @@
"type": "transit",
"description": "Used by Ryuto transit card (Niigata Kotsu)"
},
{
"code": "8B61",
"name": "Kuroneko Members",
"region": "Japan",
"type": "loyalty",
"description": "Used by Kuroneko Members nanaco card (Yamato Transport)"
},
{
"code": "8B98",
"name": "RANDEN",
@@ -591,6 +647,13 @@
"type": "payment",
"description": "Marker system found on Edy cards issued by San in Shinpan"
},
{
"code": "8C37",
"name": "ICOUSA",
"region": "Japan",
"type": "transit",
"description": "Used by ICOUSA transit card (Kochi-area operators)"
},
{
"code": "8CC1",
"name": "Speedpass",
@@ -752,6 +815,13 @@
"type": "general",
"description": "Used by FeliCa Secure ID credentials"
},
{
"code": "966F",
"name": "Oshiharai",
"region": "Japan",
"type": "payment",
"description": "Marker system found on some Edy keychains"
},
{
"code": "FE00",
"name": "FeliCa Networks Common Area",
@@ -779,6 +849,16 @@
}
]
},
{
"name": "ELIO",
"type": "payment",
"description": "ELIO e-money service found on K-Touch cards (Sony Finance)",
"nodes": [
{
"code": "00233F26"
}
]
},
{
"name": "FeliCa Kazasu Folder",
"type": "loyalty",
@@ -814,6 +894,9 @@
"type": "loyalty",
"description": "Karuwaza Club points and membership service",
"nodes": [
{
"code": "8026D726"
},
{
"code": "8026FF26"
}
+20
View File
@@ -116,6 +116,18 @@
"system": "802B",
"format": "packed"
},
{
"system": "80DE",
"prefix": "05D2",
"code": "KD",
"name": "IruCa",
"format": "packed",
"serial_group": 5
},
{
"system": "80DE",
"format": "packed"
},
{
"system": "80E0",
"prefix": "05D3",
@@ -241,6 +253,14 @@
"system": "8B5D",
"format": "epoch"
},
{
"system": "8C37",
"prefix": "0FDC",
"code": "FU",
"name": "ICOUSA",
"format": "epoch",
"serial_group": 4
},
{
"system": "FE00",
"format": "epoch",
+18 -12
View File
@@ -474,8 +474,8 @@ static int Cmdaskmandemod(const char *Cmd) {
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 2, 0);
bool invert = arg_get_lit(ctx, 3);
bool st = arg_get_lit(ctx, 4);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 5, 100) & 0xFF;
size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0) & 0xFF;
int max_err = arg_get_int_def(ctx, 5, 100);
size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0);
CLIParserFree(ctx);
return ASKDemod_ext(clk, invert, max_err, max_len, amplify, true, true, 1, &st);
@@ -718,7 +718,7 @@ static int Cmdaskbiphdemod(const char *Cmd) {
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0);
bool invert = arg_get_lit(ctx, 2);
int offset = arg_get_int_def(ctx, 3, 0);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 4, 50) & 0xFF;
int max_err = arg_get_int_def(ctx, 4, 50);
CLIParserFree(ctx);
return ASKbiphaseDemod(offset, clk, invert, max_err, true);
@@ -751,8 +751,8 @@ static int Cmdaskrawdemod(const char *Cmd) {
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 2, 0);
bool invert = arg_get_lit(ctx, 3);
bool st = arg_get_lit(ctx, 4);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 5, 100) & 0xFF;
size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0) & 0xFF;
int max_err = arg_get_int_def(ctx, 5, 100);
size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0);
CLIParserFree(ctx);
return ASKDemod_ext(clk, invert, max_err, max_len, amplify, true, false, 0, &st);
@@ -1348,12 +1348,18 @@ static int CmdFSKrawdemod(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint8_t clk = (uint8_t)arg_get_int_def(ctx, 1, 0) & 0xFF;
int clk = arg_get_int_def(ctx, 1, 0);
bool invert = arg_get_lit(ctx, 2);
uint8_t fchigh = (uint8_t)arg_get_int_def(ctx, 3, 0) & 0xFF;
uint8_t fclow = (uint8_t)arg_get_int_def(ctx, 4, 0) & 0xFF;
int fchigh = arg_get_int_def(ctx, 3, 0);
int fclow = arg_get_int_def(ctx, 4, 0);
CLIParserFree(ctx);
// the fsk demod holds them in a byte
if (clk < 0 || clk > 0xFF || fchigh < 0 || fchigh > 0xFF || fclow < 0 || fclow > 0xFF) {
PrintAndLogEx(FAILED, "Clock and field clocks must be 0 - 255");
return PM3_EINVARG;
}
return FSKrawDemod(clk, invert, fchigh, fclow, true);
}
@@ -1694,7 +1700,7 @@ static int CmdNRZrawDemod(const char *Cmd) {
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0);
bool invert = arg_get_lit(ctx, 2);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF;
int max_err = arg_get_int_def(ctx, 3, 100);
CLIParserFree(ctx);
return NRZrawDemod(clk, invert, max_err, true);
@@ -1724,7 +1730,7 @@ int CmdPSK1rawDemod(const char *Cmd) {
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0);
bool invert = arg_get_lit(ctx, 2);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF;
int max_err = arg_get_int_def(ctx, 3, 100);
CLIParserFree(ctx);
int ans = PSKDemod(clk, invert, max_err, true);
@@ -1760,9 +1766,9 @@ static int CmdPSK2rawDemod(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, true);
uint8_t clk = (uint8_t)arg_get_int_def(ctx, 1, 0) & 0xFF;
uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0);
bool invert = arg_get_lit(ctx, 2);
uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF;
int max_err = arg_get_int_def(ctx, 3, 100);
CLIParserFree(ctx);
int ans = PSKDemod(clk, invert, max_err, true);
+44 -12
View File
@@ -141,6 +141,11 @@ static bool felica_is_lite_ic_type(uint8_t ic_type) {
return (ic_type == 0xF0 || ic_type == 0xF1);
}
static bool felica_pmm_is_sd2_or_newer(const uint8_t *pmm) {
// SD2+ officially starts with 0x44, but 0x38/0x3B also express those features
return (pmm != NULL && (pmm[1] == 0x38 || pmm[1] == 0x3B || (pmm[1] >= 0x44 && pmm[1] <= 0x7F)));
}
static bool felica_pmm_is_lite(const uint8_t *pmm) {
return (pmm != NULL && pmm[0] == 0x00 && felica_is_lite_ic_type(pmm[1]));
}
@@ -2383,20 +2388,38 @@ static int discover_systems(uint8_t flags, const uint8_t *primary_idm,
primary_system_code, primary_idm_polled, primary_pmm_polled);
}
if (got_system_code_list == false) {
for (size_t i = 0; i < ARRAYLEN(FELICA_MANUAL_SYSTEM_PROBE_TARGETS); i++) {
uint8_t probed_idm[8] = {0};
uint8_t probed_pmm[8] = {0};
const uint16_t system_code = FELICA_MANUAL_SYSTEM_PROBE_TARGETS[i].system_code;
if (send_polling(flags, system_code, FELICA_POLLING_REQUEST_NO_DATA,
FELICA_POLLING_TIMEOUT_MS, polling_retries, false,
probed_idm, probed_pmm, NULL) != PM3_SUCCESS) {
continue;
// Probe systems manually, for the following reasons:
// * FeliCa Lite cards do not support RequestSystemCode
// * FeliCa Standard SD2 cards may host independent Lite/Secure ID environments
// not discoverable through RequestSystemCode
bool probe_selected = false;
const bool probe_allowed = got_system_code_list == false ||
felica_pmm_is_lite(primary_pmm_polled) ||
felica_pmm_is_sd2_or_newer(primary_pmm_polled);
for (size_t i = 0; probe_allowed && i < ARRAYLEN(FELICA_MANUAL_SYSTEM_PROBE_TARGETS); i++) {
const uint16_t system_code = FELICA_MANUAL_SYSTEM_PROBE_TARGETS[i].system_code;
bool known = false;
for (size_t j = 0; j < discovered_systems->count; j++) {
if (discovered_systems->systems[j].system_code == system_code) {
known = true;
break;
}
felica_add_unique_discovered_system(discovered_systems->systems, &discovered_systems->count,
system_code, probed_idm, probed_pmm);
}
if (known) {
continue;
}
uint8_t probed_idm[8] = {0};
uint8_t probed_pmm[8] = {0};
if (send_polling(flags, system_code, FELICA_POLLING_REQUEST_NO_DATA,
FELICA_POLLING_TIMEOUT_MS, polling_retries, false,
probed_idm, probed_pmm, NULL) != PM3_SUCCESS) {
continue;
}
felica_add_unique_discovered_system(discovered_systems->systems, &discovered_systems->count,
system_code, probed_idm, probed_pmm);
probe_selected = true;
}
if (discovered_systems->count == 0) {
@@ -2435,6 +2458,15 @@ static int discover_systems(uint8_t flags, const uint8_t *primary_idm,
}
discovered_systems->count = write_index;
// For SD2 cards, dedicated environments may have a more limited command set
// so we reselect the main Standard system
if (probe_selected && felica_pmm_is_sd2_or_newer(primary_pmm_polled)) {
uint8_t reselect_idm[8] = {0};
send_polling(flags, FELICA_SYSTEM_CODE_WILDCARD, FELICA_POLLING_REQUEST_NO_DATA,
FELICA_POLLING_TIMEOUT_MS, polling_retries, false,
reselect_idm, NULL, NULL);
}
if (discovered_systems->count == 0) {
return PM3_ERFTRANS;
}
+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"
);
+6 -4
View File
@@ -1027,7 +1027,9 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
void (*old_sigint)(int) = SIG_ERR;
void (*old_sigwinch)(int) = SIG_ERR;
if (blocks > 50) {
// escape sequences only where they work, not in a redirected stdout
bool animate = (blocks > 50) && g_session.stdoutOnTTY;
if (animate) {
old_sigint = signal(SIGINT, hadouken_on_sigint);
#ifndef _WIN32
@@ -1045,7 +1047,7 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
}
if (write_block(baddr, ctx->ver_info->magic, data, block_size, flash_dev) < 0) {
if (blocks > 50) {
if (animate) {
hadouken_stop();
restore_progress_signals(old_sigint, old_sigwinch);
}
@@ -1058,13 +1060,13 @@ int flash_write(flash_file_t *ctx, flash_dev_t *flash_dev) {
length -= block_size;
block++;
if (blocks > 50) {
if (animate) {
pct = (int)(block * 100) / blocks;
hadouken_set_progress(pct);
}
}
if (blocks > 50) {
if (animate) {
hadouken_stop();
restore_progress_signals(old_sigint, old_sigwinch);
}
+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) {
+12 -8
View File
@@ -978,7 +978,7 @@ finish:
} else if (ret == PM3_EOPABORTED) {
PrintAndLogEx(FAILED, "Aborted by user");
} else {
PrintAndLogEx(ERR, "Aborted on error %u", ret);
PrintAndLogEx(ERR, "Aborted on error %d", ret);
}
return ret;
}
@@ -1071,7 +1071,11 @@ finish:
PrintAndLogEx(WARNING, "The flashing procedure failed, follow the suggested steps!");
}
ret = flash_stop_flashing();
// the reset must not hide the error that ended the flashing
int stop_ret = flash_stop_flashing();
if (ret == PM3_SUCCESS) {
ret = stop_ret;
}
CloseProxmark(g_session.current_device);
finish2:
@@ -1500,18 +1504,18 @@ int main(int argc, char *argv[]) {
}
if (dumpmem_mode) {
dumpmem_pm3(port, dumpmem_filename, dumpmem_addr, dumpmem_len, dumpmem_raw);
exit(EXIT_SUCCESS);
int ret = dumpmem_pm3(port, dumpmem_filename, dumpmem_addr, dumpmem_len, dumpmem_raw);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (flash_mode) {
flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl, flash_force);
exit(EXIT_SUCCESS);
int ret = flash_pm3(port, flash_num_files, flash_filenames, flash_can_write_bl, flash_force);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (reboot_bootloader_mode) {
reboot_bootloader_pm3(port);
exit(EXIT_SUCCESS);
int ret = reboot_bootloader_pm3(port);
exit((ret == PM3_SUCCESS) ? EXIT_SUCCESS : EXIT_FAILURE);
}
if (script_cmd) {
+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