From 2cac27ed5372d5a536a62dd3407537492e670c3a Mon Sep 17 00:00:00 2001 From: danshuk Date: Mon, 6 Jan 2020 19:38:44 +0000 Subject: [PATCH 1/2] chg: lf pac sim *wip* --- armsrc/appmain.c | 2 +- client/cmdlfpac.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 20c26eb4d..4ed7f7dc3 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -780,7 +780,7 @@ static void PacketReceived(PacketCommandNG *packet) { } case CMD_LF_NRZ_SIMULATE: { lf_nrzsim_t *payload = (lf_nrzsim_t *)packet->data.asBytes; - CmdNRZsimTAG(payload->invert, payload->separator, payload->clock, packet->length - sizeof(lf_asksim_t), payload->data, true); + CmdNRZsimTAG(payload->invert, payload->separator, payload->clock, packet->length - sizeof(lf_nrzsim_t), payload->data, true); break; } case CMD_LF_HID_CLONE: { diff --git a/client/cmdlfpac.c b/client/cmdlfpac.c index 92a7f18ea..040c8af0a 100644 --- a/client/cmdlfpac.c +++ b/client/cmdlfpac.c @@ -51,7 +51,7 @@ static int usage_lf_pac_sim(void) { PrintAndLogEx(NORMAL, " : 8 byte PAC/Stanley card id"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, " lf pac sim 1A337"); + PrintAndLogEx(NORMAL, " lf pac sim 12345678"); return PM3_SUCCESS; } // by danshuk @@ -245,20 +245,23 @@ static int CmdPacClone(const char *Cmd) { static int CmdPacSim(const char *Cmd) { // NRZ sim. - uint32_t id = 0; - uint64_t rawID = 0; + char cardid[9] = { 0 }; + uint8_t rawBytes[16] = { 0 }; + uint32_t rawBlocks[4]; char cmdp = tolower(param_getchar(Cmd, 0)); if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_pac_sim(); - id = param_get32ex(Cmd, 0, 0, 16); - if (id == 0) return usage_lf_pac_sim(); - - //rawID = pacCardIdToRaw(id); - - PrintAndLogEx(SUCCESS, "Simulating PAC/Stanley - ID " _YELLOW_("%08X")" raw "_YELLOW_("%08X%08X"), id, (uint32_t)(rawID >> 32), (uint32_t)(rawID & 0xFFFFFFFF)); + int res = param_getstr(Cmd, 0, cardid, sizeof(cardid)); + if (res < 8) return usage_lf_pac_sim(); uint8_t bs[128]; - num_to_bytebits(rawID, sizeof(bs), bs); + pacCardIdToRaw(rawBytes, cardid); + for (size_t i = 0; i < ARRAYLEN(rawBlocks); i++) { + rawBlocks[i] = bytes_to_num(rawBytes + (i * sizeof(uint32_t)), sizeof(uint32_t)); + num_to_bytebits(rawBlocks[i], sizeof(uint32_t) * 8, bs + (i * sizeof(uint32_t) * 8)); + } + + PrintAndLogEx(SUCCESS, "Simulating PAC/Stanley - ID " _YELLOW_("%s")" raw "_YELLOW_("%08X%08X%08X%08X"), cardid, rawBlocks[0], rawBlocks[1], rawBlocks[2], rawBlocks[3]); lf_nrzsim_t *payload = calloc(1, sizeof(lf_nrzsim_t) + sizeof(bs)); payload->invert = 0; From e9960ed0a039efd1ba002b2ad44b9889daccf21f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 7 Jan 2020 09:19:59 +0100 Subject: [PATCH 2/2] Fix: lf io sim/clone - now takes same input format (decimal/hex) as outputted --- client/cmdlfio.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/client/cmdlfio.c b/client/cmdlfio.c index 57a8a64d1..b640bed41 100644 --- a/client/cmdlfio.c +++ b/client/cmdlfio.c @@ -47,9 +47,9 @@ static int usage_lf_io_sim(void) { PrintAndLogEx(NORMAL, "Usage: lf io sim [h] "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : 8bit version"); - PrintAndLogEx(NORMAL, " : 8bit value facility code"); - PrintAndLogEx(NORMAL, " : 16bit value card number"); + PrintAndLogEx(NORMAL, " : 8bit version (decimal)"); + PrintAndLogEx(NORMAL, " : 8bit value facility code (hex)"); + PrintAndLogEx(NORMAL, " : 16bit value card number (decimal)"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); PrintAndLogEx(NORMAL, " lf io sim 26 101 1337"); @@ -63,9 +63,9 @@ static int usage_lf_io_clone(void) { PrintAndLogEx(NORMAL, "Usage: lf io clone [h] [Q5]"); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); - PrintAndLogEx(NORMAL, " : 8bit version"); - PrintAndLogEx(NORMAL, " : 8bit value facility code"); - PrintAndLogEx(NORMAL, " : 16bit value card number"); + PrintAndLogEx(NORMAL, " : 8bit version (decimal)"); + PrintAndLogEx(NORMAL, " : 8bit value facility code (hex)"); + PrintAndLogEx(NORMAL, " : 16bit value card number (decimal)"); PrintAndLogEx(NORMAL, " Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip"); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "Examples:"); @@ -197,7 +197,7 @@ static int CmdIOProxSim(const char *Cmd) { if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_io_sim(); version = param_get8(Cmd, 0); - fc = param_get8(Cmd, 1); + fc = param_get8ex(Cmd, 1, 0, 16); cn = param_get32ex(Cmd, 2, 0, 10); if (!version || !fc || !cn) return usage_lf_io_sim(); @@ -249,7 +249,7 @@ static int CmdIOProxClone(const char *Cmd) { if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_io_clone(); version = param_get8(Cmd, 0); - fc = param_get8(Cmd, 1); + fc = param_get8ex(Cmd, 1, 0, 16); cn = param_get32ex(Cmd, 2, 0, 10); if (!version || !fc || !cn) return usage_lf_io_clone();