added a new command -data bmap- it breaks down a hex value in rows of bits according to a supplied template

This commit is contained in:
iceman1001 2023-10-22 14:08:18 +02:00
commit 9a9d2cf621
2 changed files with 65 additions and 0 deletions

View file

@ -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)

View file

@ -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>", "hex string"),
arg_str0("m", NULL, "<str>", "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"},