diff --git a/CHANGELOG.md b/CHANGELOG.md index ee649ac76..084441cc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added new command `data bmap` - breaks down a hexvalue to a binary template (@iceman1001) - Changed aid_desfire.json - added entreis from the Metrodroid project (@iceman1001) - Changed mad.json - added entries from the Metrodroid project (@iceman1001) - Changed `hf iclass dump` - now allow no save of dumped data (@iceman1001) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index a1ed8dc65..ea37ccfd5 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -3451,6 +3451,69 @@ static int CmdAtrLookup(const char *Cmd) { return PM3_SUCCESS; } +static int CmdBinaryMap(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "data bmap", + "Breaks down a hex value to binary according a template\n" + " data bmap -d 16 -m 4,4\n" + "This will give two rows each with four bits", + "data bmap -d 3B -m 2,5,1\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_str0("d", NULL, "", "hex string"), + arg_str0("m", NULL, "", "binary template"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int hlen = 5; + uint8_t hex[5 + 1]; + CLIGetStrWithReturn(ctx, 1,hex, &hlen); + + int tlen = 40; + uint8_t template[40 + 1]; + CLIGetStrWithReturn(ctx, 2, template, &tlen); + CLIParserFree(ctx); + + char bits[(8 * 4) + 1] = {0}; + hextobinstring_n(bits, hex, hlen); + + int x = 0; + char *token = strtok(template, ","); + + PrintAndLogEx(INFO, "---+---------------------------"); + PrintAndLogEx(INFO, " | b0 b1 b2 b3 b4 b5 b6 b7"); + PrintAndLogEx(INFO, "---+---------------------------"); + + uint8_t i = 0; + uint8_t cnt = 1; + while (token != NULL) { + sscanf(token, "%d", &x); + + if (i) { + PrintAndLogEx(INFO, " %d | %*.s" NOLF, cnt, i * 3, " "); + } else { + PrintAndLogEx(INFO, " %d | " NOLF, cnt); + } + + // incease with previous offset + x += i; + + for (;i < x; i++) { + PrintAndLogEx(NORMAL, "%c " NOLF, bits[7 - i]); + } + + PrintAndLogEx(NORMAL, ""); + token = strtok(NULL, ","); + cnt++; + } + + PrintAndLogEx(NORMAL, ""); + return PM3_SUCCESS; +} + static command_t CommandTable[] = { {"help", CmdHelp, AlwaysAvailable, "This help"}, @@ -3493,6 +3556,7 @@ static command_t CommandTable[] = { {"atr", CmdAtrLookup, AlwaysAvailable, "ATR lookup"}, {"bin2hex", Cmdbin2hex, AlwaysAvailable, "Converts binary to hexadecimal"}, {"bitsamples", CmdBitsamples, IfPm3Present, "Get raw samples as bitstring"}, + {"bmap", CmdBinaryMap, AlwaysAvailable, "Convert hex value according a binary template"}, {"clear", CmdBuffClear, AlwaysAvailable, "Clears bigbuf on deviceside and graph window"}, {"diff", CmdDiff, AlwaysAvailable, "Diff of input files"}, {"hexsamples", CmdHexsamples, IfPm3Present, "Dump big buffer as hex bytes"},