hf mf setmod - now uses cliparser

This commit is contained in:
iceman1001 2021-04-11 17:54:17 +02:00
commit 55e1b95f21
3 changed files with 46 additions and 35 deletions

View file

@ -524,7 +524,7 @@ static int CmdHF14AMfRdBl(const char *Cmd) {
arg_int1(NULL, "blk", "<dec>", "block number"), arg_int1(NULL, "blk", "<dec>", "block number"),
arg_lit0("a", NULL, "input key type is key A (def)"), arg_lit0("a", NULL, "input key type is key A (def)"),
arg_lit0("b", NULL, "input key type is key B"), arg_lit0("b", NULL, "input key type is key B"),
arg_str0("k", "key", "<hex>", "key specified as 6 hex bytes"), arg_str0("k", "key", "<hex>", "key, 6 hex bytes"),
arg_lit0("v", "verbose", "verbose output"), arg_lit0("v", "verbose", "verbose output"),
arg_param_end arg_param_end
}; };
@ -569,9 +569,9 @@ static int CmdHF14AMfRdBl(const char *Cmd) {
static int CmdHF14AMfRdSc(const char *Cmd) { static int CmdHF14AMfRdSc(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mf rdbl", CLIParserInit(&ctx, "hf mf rdsc",
"Read MIFARE Classic sector", "Read MIFARE Classic sector",
"hf mf rdbl -s 0 -k FFFFFFFFFFFF\n" "hf mf rdsc -s 0 -k FFFFFFFFFFFF\n"
); );
void *argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
@ -4975,43 +4975,56 @@ static int CmdHf14AMfDecryptBytes(const char *Cmd) {
} }
static int CmdHf14AMfSetMod(const char *Cmd) { static int CmdHf14AMfSetMod(const char *Cmd) {
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
uint8_t mod = 2;
char ctmp = param_getchar(Cmd, 0); CLIParserContext *ctx;
if (ctmp == '0') { CLIParserInit(&ctx, "hf mf setmod",
mod = 0; "Sets the load modulation strength of a MIFARE Classic EV1 card",
} else if (ctmp == '1') { "hf mf setmod -k ffffffffffff -0"
mod = 1; );
} void *argtable[] = {
int gethexfail = param_gethex(Cmd, 1, key, 12); arg_param_begin,
if (mod == 2 || gethexfail) { arg_lit0("0", NULL, "normal modulation"),
PrintAndLogEx(NORMAL, "Sets the load modulation strength of a MIFARE Classic EV1 card."); arg_lit0("1", NULL, "strong modulation (def)"),
PrintAndLogEx(NORMAL, "Usage: hf mf setmod <0|1> <block 0 key A>"); arg_str0("k", "key", "<hex>", "key A, Sector 0, 6 hex bytes"),
PrintAndLogEx(NORMAL, " 0 = normal modulation"); arg_param_end
PrintAndLogEx(NORMAL, " 1 = strong modulation (default)"); };
return PM3_ESOFT; CLIExecWithReturn(ctx, Cmd, argtable, true);
bool m0 = arg_get_lit(ctx, 1);
bool m1 = arg_get_lit(ctx, 2);
int keylen = 0;
uint8_t key[6] = {0};
CLIGetHexWithReturn(ctx, 3, key, &keylen);
CLIParserFree(ctx);
if (m0 + m1 > 1) {
PrintAndLogEx(WARNING, "please select one modulation");
return PM3_EINVARG;
} }
uint8_t data[7]; uint8_t data[7] = {0};
data[0] = mod;
memcpy(data + 1, key, 6); memcpy(data + 1, key, 6);
if (m1) {
data[0] = 1;
} else {
data[0] = 0;
}
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_SETMOD, data, sizeof(data)); SendCommandNG(CMD_HF_MIFARE_SETMOD, data, sizeof(data));
PacketResponseNG resp; PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_HF_MIFARE_SETMOD, &resp, 1500)) { if (WaitForResponseTimeout(CMD_HF_MIFARE_SETMOD, &resp, 1500) == false) {
if (resp.status == PM3_SUCCESS)
PrintAndLogEx(SUCCESS, "Success");
else
PrintAndLogEx(FAILED, "Failed");
} else {
PrintAndLogEx(WARNING, "Command execute timeout"); PrintAndLogEx(WARNING, "Command execute timeout");
return PM3_ETIMEOUT;
} }
return PM3_SUCCESS;
if (resp.status == PM3_SUCCESS)
PrintAndLogEx(SUCCESS, "Change ( " _GREEN_("ok") " )");
else
PrintAndLogEx(FAILED, "Change (" _GREEN_("fail") " )");
return resp.status;
} }
// MIFARE NACK bug detection // MIFARE NACK bug detection

View file

@ -19,9 +19,7 @@ hf felica resetmode
hf mf hardnested hf mf hardnested
hf mf autopwn hf mf autopwn
hf mf decrypt hf mf decrypt
hf mf rdsc
hf mf restore hf mf restore
hf mf setmod
hf mf wrbl hf mf wrbl
lf hitag reader lf hitag reader
lf hitag writer lf hitag writer

View file

@ -424,9 +424,9 @@ Check column "offline" for their availability.
|`hf mf csetuid `|N |`Set UID on card` |`hf mf csetuid `|N |`Set UID on card`
|`hf mf cview `|N |`View card` |`hf mf cview `|N |`View card`
|`hf mf cwipe `|N |`Wipe card to default UID/Sectors/Keys` |`hf mf cwipe `|N |`Wipe card to default UID/Sectors/Keys`
|`hf mf gen3uid `|N |`Set UID without manufacturer block` |`hf mf gen3uid `|N |`Set UID without changing manufacturer block`
|`hf mf gen3blk `|N |`Overwrite full manufacturer block` |`hf mf gen3blk `|N |`Overwrite manufacturer block`
|`hf mf gen3freeze `|N |`Perma lock further UID changes` |`hf mf gen3freeze `|N |`Perma lock UID changes. irreversible`
### hf mfp ### hf mfp