From cad676a23c31e25d6d14535a5dd8ecce20304e55 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Wed, 1 May 2019 21:46:29 +0200 Subject: [PATCH] Replace WITH_FLASH by dynamic detection in client --- client/cmdflashmem.c | 16 ++++++--------- client/cmdflashmem.h | 4 ---- client/cmdhfmf.c | 9 +++------ client/cmdhw.c | 23 +++++----------------- client/cmdmain.c | 8 ++------ client/scripting.c | 46 ++++++++++++++++++++++---------------------- 6 files changed, 39 insertions(+), 67 deletions(-) diff --git a/client/cmdflashmem.c b/client/cmdflashmem.c index 127bd3419..4627dfebb 100644 --- a/client/cmdflashmem.c +++ b/client/cmdflashmem.c @@ -7,8 +7,6 @@ //----------------------------------------------------------------------------- // Proxmark3 RDV40 Flash memory commands //----------------------------------------------------------------------------- -#ifdef WITH_FLASH - #include "cmdflashmem.h" #include "mbedtls/rsa.h" @@ -618,12 +616,12 @@ static int CmdFlashMemInfo(const char *Cmd) { static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, - {"spibaud", CmdFlashmemSpiBaudrate, AlwaysAvailable, "Set Flash memory Spi baudrate [rdv40]"}, - {"read", CmdFlashMemRead, AlwaysAvailable, "Read Flash memory [rdv40]"}, - {"info", CmdFlashMemInfo, AlwaysAvailable, "Flash memory information [rdv40]"}, - {"load", CmdFlashMemLoad, AlwaysAvailable, "Load data into flash memory [rdv40]"}, - {"save", CmdFlashMemSave, AlwaysAvailable, "Save data from flash memory [rdv40]"}, - {"wipe", CmdFlashMemWipe, AlwaysAvailable, "Wipe data from flash memory [rdv40]"}, + {"spibaud", CmdFlashmemSpiBaudrate, IfPm3Flash, "Set Flash memory Spi baudrate [rdv40]"}, + {"read", CmdFlashMemRead, IfPm3Flash, "Read Flash memory [rdv40]"}, + {"info", CmdFlashMemInfo, IfPm3Flash, "Flash memory information [rdv40]"}, + {"load", CmdFlashMemLoad, IfPm3Flash, "Load data into flash memory [rdv40]"}, + {"save", CmdFlashMemSave, IfPm3Flash, "Save data from flash memory [rdv40]"}, + {"wipe", CmdFlashMemWipe, IfPm3Flash, "Wipe data from flash memory [rdv40]"}, {NULL, NULL, NULL, NULL} }; @@ -637,5 +635,3 @@ int CmdFlashMem(const char *Cmd) { clearCommandBuffer(); return CmdsParse(CommandTable, Cmd); } - -#endif diff --git a/client/cmdflashmem.h b/client/cmdflashmem.h index c58de661d..3c37239b7 100644 --- a/client/cmdflashmem.h +++ b/client/cmdflashmem.h @@ -8,8 +8,6 @@ // Proxmark3 RDV40 Flash memory commands //----------------------------------------------------------------------------- -#ifdef WITH_FLASH - #ifndef CMDFLASHMEM_H__ #define CMDFLASHMEM_H__ @@ -36,5 +34,3 @@ typedef enum { int CmdFlashMem(const char *Cmd); #endif - -#endif diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index dac5c3b11..1b10440df 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -202,9 +202,8 @@ static int usage_hf14_chk_fast(void) { PrintAndLogEx(NORMAL, " hf mf fchk 1 1234567890ab keys.dic -- target 1K using key 1234567890ab, using dictionary file"); PrintAndLogEx(NORMAL, " hf mf fchk 1 t -- target 1K, write to emulator memory"); PrintAndLogEx(NORMAL, " hf mf fchk 1 d -- target 1K, write to file"); -#ifdef WITH_FLASH - PrintAndLogEx(NORMAL, " hf mf fchk 1 m -- target 1K, use dictionary from flashmemory"); -#endif + if (IfPm3Flash()) + PrintAndLogEx(NORMAL, " hf mf fchk 1 m -- target 1K, use dictionary from flashmemory"); return 0; } static int usage_hf14_keybrute(void) { @@ -1593,9 +1592,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { } else if (clen == 1) { if (ctmp == 't') { transferToEml = 1; continue; } if (ctmp == 'd') { createDumpFile = 1; continue; } -#ifdef WITH_FLASH - if (ctmp == 'm') { use_flashmemory = true; continue; } -#endif + if ((ctmp == 'm') && (IfPm3Flash())){ use_flashmemory = true; continue; } } else { // May be a dic file if (param_getstr(Cmd, i, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { diff --git a/client/cmdhw.c b/client/cmdhw.c index 0dece387b..22de1e9e5 100644 --- a/client/cmdhw.c +++ b/client/cmdhw.c @@ -500,25 +500,12 @@ void pm3_version(bool verbose) { SendCommandOLD(CMD_VERSION, 0, 0, 0, NULL, 0); if (WaitForResponseTimeout(CMD_ACK, &resp, 1000)) { PrintAndLogEx(NORMAL, "\n" _BLUE_(" [ Proxmark3 RFID instrument ]") "\n"); - char s[60] = {0}; -#if defined(WITH_FLASH) || defined(WITH_SMARTCARD) || defined(WITH_FPC) - strncat(s, "build for RDV40 with ", sizeof(s) - strlen(s) - 1); -#endif -#ifdef WITH_FLASH - strncat(s, "flashmem; ", sizeof(s) - strlen(s) - 1); -#endif -#ifdef WITH_SMARTCARD - strncat(s, "smartcard; ", sizeof(s) - strlen(s) - 1); -#endif -#ifdef WITH_FPC -#ifdef WITH_FPC_HOST - strncat(s, "fpc-host; ", sizeof(s) - strlen(s) - 1); -#else - strncat(s, "fpc; ", sizeof(s) - strlen(s) - 1); -#endif -#endif PrintAndLogEx(NORMAL, "\n [ CLIENT ]"); - PrintAndLogEx(NORMAL, " client: iceman %s \n", s); + PrintAndLogEx(NORMAL, " client: RRG/Iceman"); // TODO version info? + PrintAndLogEx(NORMAL, "\n [ PROXMARK ]"); + PrintAndLogEx(NORMAL, " external flash: %s", IfPm3Flash() ? _GREEN_("present") : _YELLOW_("absent")); + PrintAndLogEx(NORMAL, " smartcard reader: %s", IfPm3Smartcard() ? _GREEN_("present") : _YELLOW_("absent")); + PrintAndLogEx(NORMAL, " USART for addon support: %s\n", IfPm3FpcHost() ? _GREEN_("present") : _YELLOW_("absent")); PrintAndLogEx(NORMAL, (char *)resp.data.asBytes); lookupChipID(resp.oldarg[0], resp.oldarg[1]); diff --git a/client/cmdmain.c b/client/cmdmain.c index 2349dac9b..646df1b3c 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -53,12 +53,8 @@ static command_t CommandTable[] = { {"reveng", CmdRev, AlwaysAvailable, "{ Crc calculations from the RevEng software... }"}, {"script", CmdScript, AlwaysAvailable, "{ Scripting commands }"}, {"trace", CmdTrace, AlwaysAvailable, "{ Trace manipulation... }"}, -#ifdef WITH_FLASH - {"mem", CmdFlashMem, AlwaysAvailable, "{ Flash Memory manipulation... }"}, -#endif -#ifdef WITH_SMARTCARD - {"sc", CmdSmartcard, AlwaysAvailable, "{ Smart card ISO7816 commands... }"}, -#endif + {"mem", CmdFlashMem, IfPm3Flash, "{ Flash Memory manipulation... }"}, + {"sc", CmdSmartcard, IfPm3Smartcard, "{ Smart card ISO7816 commands... }"}, {"quit", CmdQuit, AlwaysAvailable, ""}, {"exit", CmdQuit, AlwaysAvailable, "Exit program"}, {NULL, NULL, NULL, NULL} diff --git a/client/scripting.c b/client/scripting.c index d2fd4fd90..468c63cfa 100644 --- a/client/scripting.c +++ b/client/scripting.c @@ -264,36 +264,36 @@ static int l_GetFromBigBuf(lua_State *L) { */ static int l_GetFromFlashMem(lua_State *L) { -#ifndef WITH_FLASH - return returnToLuaWithError(L, "Not compiled with FLASH MEM support"); -#else - int len = 0, startindex = 0; + if (IfPm3Flash()) { + int len = 0, startindex = 0; - int n = lua_gettop(L); - if (n == 0) - return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); + int n = lua_gettop(L); + if (n == 0) + return returnToLuaWithError(L, "You need to supply number of bytes and startindex"); - if (n >= 2) { - startindex = luaL_checknumber(L, 1); - len = luaL_checknumber(L, 2); - } + if (n >= 2) { + startindex = luaL_checknumber(L, 1); + len = luaL_checknumber(L, 2); + } - if (len == 0) - return returnToLuaWithError(L, "You need to supply number of bytes larger than zero"); + if (len == 0) + return returnToLuaWithError(L, "You need to supply number of bytes larger than zero"); - uint8_t *data = calloc(len, sizeof(uint8_t)); - if (!data) - return returnToLuaWithError(L, "Allocating memory failed"); + uint8_t *data = calloc(len, sizeof(uint8_t)); + if (!data) + return returnToLuaWithError(L, "Allocating memory failed"); - if (!GetFromDevice(FLASH_MEM, data, len, startindex, NULL, -1, false)) { + if (!GetFromDevice(FLASH_MEM, data, len, startindex, NULL, -1, false)) { + free(data); + return returnToLuaWithError(L, "command execution time out"); + } + + lua_pushlstring(L, (const char *)data, len); free(data); - return returnToLuaWithError(L, "command execution time out"); + return 1; + } else { + return returnToLuaWithError(L, "No FLASH MEM support"); } - - lua_pushlstring(L, (const char *)data, len); - free(data); - return 1; -#endif }