From 7d1897cd527b97cea57e6a5224a899a247f3850f Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 4 Feb 2021 22:36:08 +0100 Subject: [PATCH] lf em 410x brute - now works without pressing enter every time to continue one step --- client/src/cmdlf.c | 75 ++++++++++++++++++++++------------------ client/src/cmdlf.h | 2 +- client/src/cmdlfem410x.c | 26 ++++++++++++-- 3 files changed, 65 insertions(+), 38 deletions(-) diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 2f5384e36..86de80dbd 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -730,40 +730,8 @@ static void ChkBitstream(void) { } } -//Attempt to simulate any wave in buffer (one bit per output sample) -// converts GraphBuffer to bitstream (based on zero crossings) if needed. -int CmdLFSim(const char *Cmd) { - CLIParserContext *ctx; - CLIParserInit(&ctx, "lf sim", - "Simulate low frequency tag from graphbuffer\n" - "Use " _YELLOW_("`lf config`") _CYAN_(" to set parameters"), - "lf sim\n" - "lf sim --gap 240 --> start simulating with 240ms gap" - ); - - void *argtable[] = { - arg_param_begin, - arg_u64_0("g", "gap", "", "start gap in microseconds"), - arg_param_end - }; - CLIExecWithReturn(ctx, Cmd, argtable, true); - uint16_t gap = arg_get_u32_def(ctx, 1, 0); - CLIParserFree(ctx); - - if (session.pm3_present == false) { - PrintAndLogEx(DEBUG, "DEBUG: no proxmark present"); - return PM3_ENOTTY; - } - - // sanity check - if (GraphTraceLen < 20) { - PrintAndLogEx(ERR, "No data in Graphbuffer"); - return PM3_ENODATA; - } - - // convert to bitstream if necessary - ChkBitstream(); - +// Uploads GraphBuffer to device, in order to be used for LF SIM. +int lfsim_upload_gb(void) { PrintAndLogEx(DEBUG, "DEBUG: Uploading %zu bytes", GraphTraceLen); struct pupload { @@ -802,9 +770,48 @@ int CmdLFSim(const char *Cmd) { PrintAndLogEx(NORMAL, "." NOLF); payload_up.flag = 0; } + PrintAndLogEx(NORMAL, ""); // Disable fast mode before last command conn.block_after_ACK = false; + return PM3_SUCCESS; +} + +//Attempt to simulate any wave in buffer (one bit per output sample) +// converts GraphBuffer to bitstream (based on zero crossings) if needed. +int CmdLFSim(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "lf sim", + "Simulate low frequency tag from graphbuffer\n" + "Use " _YELLOW_("`lf config`") _CYAN_(" to set parameters"), + "lf sim\n" + "lf sim --gap 240 --> start simulating with 240ms gap" + ); + + void *argtable[] = { + arg_param_begin, + arg_u64_0("g", "gap", "", "start gap in microseconds"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + uint16_t gap = arg_get_u32_def(ctx, 1, 0); + CLIParserFree(ctx); + + if (session.pm3_present == false) { + PrintAndLogEx(DEBUG, "DEBUG: no proxmark present"); + return PM3_ENOTTY; + } + + // sanity check + if (GraphTraceLen < 20) { + PrintAndLogEx(ERR, "No data in Graphbuffer"); + return PM3_ENODATA; + } + + // convert to bitstream if necessary + ChkBitstream(); + + lfsim_upload_gb(); struct p { uint16_t len; diff --git a/client/src/cmdlf.h b/client/src/cmdlf.h index 645d00627..c68289c45 100644 --- a/client/src/cmdlf.h +++ b/client/src/cmdlf.h @@ -36,6 +36,6 @@ int lf_read(bool verbose, uint32_t samples); int lf_sniff(bool verbose, uint32_t samples); int lf_config(sample_config *config); int lf_getconfig(sample_config *config); - +int lfsim_upload_gb(void); int lfsim_wait_check(uint32_t cmd); #endif diff --git a/client/src/cmdlfem410x.c b/client/src/cmdlfem410x.c index 04f0254aa..0cb6518fa 100644 --- a/client/src/cmdlfem410x.c +++ b/client/src/cmdlfem410x.c @@ -536,7 +536,7 @@ static int CmdEM410xBrute(const char *Cmd) { for (uint32_t c = 0; c < uidcnt; ++c) { if (kbd_enter_pressed()) { SendCommandNG(CMD_BREAK_LOOP, NULL, 0); - PrintAndLogEx(INFO, "\nAborted via keyboard!\n"); + PrintAndLogEx(INFO, "Aborted via keyboard!\n"); free(uidblock); return PM3_EOPABORTED; } @@ -549,8 +549,28 @@ static int CmdEM410xBrute(const char *Cmd) { ); em410x_construct_emul_graph(testuid, clk); - CmdLFSim(""); - msleep(delay); + + lfsim_upload_gb(); + + struct p { + uint16_t len; + uint16_t gap; + } PACKED payload; + payload.len = GraphTraceLen; + payload.gap = 0; + + clearCommandBuffer(); + SendCommandNG(CMD_LF_SIMULATE, (uint8_t *)&payload, sizeof(payload)); + + PacketResponseNG resp; + if (WaitForResponseTimeout(CMD_LF_SIMULATE, &resp, delay)) { + if (resp.status == PM3_EOPABORTED) { + PrintAndLogEx(INFO, "Button pressed, user aborted"); + break; + } + } + +// msleep(delay); } free(uidblock); return PM3_SUCCESS;