improve hf mf wrbl with text and a new param --force to make sure user understands when writing to block 0.

This commit is contained in:
iceman1001 committed 2022-03-24 12:30:48 +01:00
1 parent cdf079a0c1
commit 758e7d9d2b
5 files changed
+28 -10

No files matched your search

+21 -4
View File
@@ -427,7 +427,12 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mf wrbl",
"Write MIFARE Classic block",
"Write MIFARE Classic block with 16 hex bytes of data\n"
" \n"
"Sector 0 / Block 0 - Manufacturer block\n"
"When writing to block 0 you must use a VALID block 0 data (UID, BCC, SAK, ATQA)\n"
"Writing an invalid block 0 means rendering your Magic GEN2 card undetectable. \n"
"Look in the magic_cards_notes.md file for help to resolve it.",
"hf mf wrbl --blk 1 -k FFFFFFFFFFFF -d 000102030405060708090a0b0c0d0e0f"
);
void *argtable[] = {
@@ -435,6 +440,7 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
arg_int1(NULL, "blk", "<dec>", "block number"),
arg_lit0("a", NULL, "input key type is key A (def)"),
arg_lit0("b", NULL, "input key type is key B"),
arg_lit0(NULL, "force", "enforce block0 writes"),
arg_str0("k", "key", "<hex>", "key, 6 hex bytes"),
arg_str0("d", "data", "<hex>", "bytes to write, 16 hex bytes"),
@@ -442,7 +448,7 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
int b = arg_get_int_def(ctx, 1, 0);
int b = arg_get_int_def(ctx, 1, 1);
uint8_t keytype = MF_KEY_A;
if (arg_get_lit(ctx, 2) && arg_get_lit(ctx, 3)) {
@@ -453,13 +459,15 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
keytype = MF_KEY_B;;
}
bool force = arg_get_lit(ctx, 4);
int keylen = 0;
uint8_t key[6] = {0};
CLIGetHexWithReturn(ctx, 4, key, &keylen);
CLIGetHexWithReturn(ctx, 5, key, &keylen);
uint8_t block[MFBLOCK_SIZE] = {0x00};
int blen = 0;
CLIGetHexWithReturn(ctx, 5, block, &blen);
CLIGetHexWithReturn(ctx, 6, block, &blen);
CLIParserFree(ctx);
if (blen != MFBLOCK_SIZE) {
@@ -470,6 +478,15 @@ static int CmdHF14AMfWrBl(const char *Cmd) {
if (b > 255) {
return PM3_EINVARG;
}
if (b == 0 && force == false) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "Targeting Sector 0 / Block 0 - Manufacturer block");
PrintAndLogEx(INFO, "Read the helptext for details before writing to this block");
PrintAndLogEx(INFO, "You must use param `" _YELLOW_("--force") "` to write to this block");
PrintAndLogEx(NORMAL, "");
return PM3_EINVARG;
}
uint8_t blockno = (uint8_t)b;
PrintAndLogEx(INFO, "Writing block no %d, key %c - %s", blockno, (keytype == MF_KEY_B) ? 'B' : 'A', sprint_hex_inrow(key, sizeof(key)));
-1
View File
@@ -133,7 +133,6 @@ static int CmdCOTAGReader(const char *Cmd) {
int res = PM3_SUCCESS;
while (!WaitForResponseTimeout(CMD_LF_COTAG_READ, &resp, 1000)) {
timeout--;
PrintAndLogEx(NORMAL, "." NOLF);
if (timeout == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(WARNING, "command execution time out");
+2 -2
View File
@@ -162,14 +162,14 @@ int demodIndalaEx(int clk, int invert, int maxErr, bool verbose) {
// to reduce false_positives
// let's check the ratio of zeros in the demod buffer.
size_t cnt_zeros = 0;
for (size_t i=0; i< g_DemodBufferLen; i++) {
for (size_t i = 0; i < g_DemodBufferLen; i++) {
if (g_DemodBuffer[i] == 0x00)
++cnt_zeros;
}
// if more than 95% zeros in the demodbuffer then assume its wrong
int32_t stats = (int32_t)((cnt_zeros * 100 / g_DemodBufferLen));
if ( stats > 95) {
if (stats > 95) {
return PM3_ESOFT;
}