mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
hf 14b sriwrite - now uses cliparser
This commit is contained in:
parent
2a6a67aa21
commit
159a12e357
1 changed files with 55 additions and 48 deletions
|
@ -37,21 +37,6 @@ bool apdu_in_framing_enable = true;
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
static int usage_hf_14b_write_srx(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf 14b [h] sriwrite <1|2> <block> <data>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h this help");
|
|
||||||
PrintAndLogEx(NORMAL, " <1|2> 1 = SRIX4K , 2 = SRI512");
|
|
||||||
PrintAndLogEx(NORMAL, " <block> (hex) block number depends on tag, special block == FF");
|
|
||||||
PrintAndLogEx(NORMAL, " <data> hex bytes of data to be written");
|
|
||||||
PrintAndLogEx(NORMAL, "Example:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sriwrite 1 7F 11223344"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sriwrite 1 FF 11223344"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sriwrite 2 15 11223344"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf 14b sriwrite 2 FF 11223344"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int switch_off_field_14b(void) {
|
static int switch_off_field_14b(void) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandMIX(CMD_HF_ISO14443B_COMMAND, ISO14B_DISCONNECT, 0, 0, NULL, 0);
|
SendCommandMIX(CMD_HF_ISO14443B_COMMAND, ISO14B_DISCONNECT, 0, 0, NULL, 0);
|
||||||
|
@ -1138,56 +1123,78 @@ static int CmdHF14BWriteSri(const char *Cmd) {
|
||||||
* Special block FF = otp_lock_reg block.
|
* Special block FF = otp_lock_reg block.
|
||||||
* Data len 4 bytes-
|
* Data len 4 bytes-
|
||||||
*/
|
*/
|
||||||
char cmdp = tolower(param_getchar(Cmd, 0));
|
|
||||||
uint8_t blockno = -1;
|
|
||||||
uint8_t data[4] = {0x00};
|
|
||||||
bool isSrix4k = true;
|
|
||||||
char str[30];
|
|
||||||
memset(str, 0x00, sizeof(str));
|
|
||||||
|
|
||||||
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_hf_14b_write_srx();
|
CLIParserContext *ctx;
|
||||||
|
CLIParserInit(&ctx, "hf 14b sriwrite",
|
||||||
|
"Write data to a SRI512 | SRIX4K block",
|
||||||
|
"hf 14b sriwrite --4k -b 100 -d 11223344\n"
|
||||||
|
"hf 14b sriwrite --4k --sb -d 11223344 --> special block write\n"
|
||||||
|
"hf 14b sriwrite --512 -b 15 -d 11223344\n"
|
||||||
|
"hf 14b sriwrite --512 --sb -d 11223344 --> special block write\n"
|
||||||
|
);
|
||||||
|
|
||||||
if (cmdp == '2')
|
void *argtable[] = {
|
||||||
isSrix4k = false;
|
arg_param_begin,
|
||||||
|
arg_int0("b", "block", "<dec>", "block number"),
|
||||||
//blockno = param_get8(Cmd, 1);
|
arg_str1("d", "data", "<hex>", "4 hex bytes"),
|
||||||
|
arg_lit0(NULL, "512", "target SRI 512 tag"),
|
||||||
if (param_gethex(Cmd, 1, &blockno, 2)) {
|
arg_lit0(NULL, "4k", "target SRIX 4k tag"),
|
||||||
PrintAndLogEx(WARNING, "block number must include 2 HEX symbols");
|
arg_lit0(NULL, "sb", "special block write at end of memory (0xFF)"),
|
||||||
return 0;
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
int blockno = arg_get_int_def(ctx, 1, -1);
|
||||||
|
int dlen = 0;
|
||||||
|
uint8_t data[4] = {0,0,0,0};
|
||||||
|
int res = CLIParamHexToBuf(arg_get_str(ctx, 2), data, sizeof(data), &dlen);
|
||||||
|
if (res) {
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSrix4k) {
|
bool use_sri512 = arg_get_lit(ctx, 3);
|
||||||
if (blockno > 0x7f && blockno != 0xff) {
|
bool use_srix4k = arg_get_lit(ctx, 4);
|
||||||
PrintAndLogEx(FAILED, "block number out of range");
|
bool special = arg_get_lit(ctx, 5);
|
||||||
return PM3_ESOFT;
|
CLIParserFree(ctx);
|
||||||
}
|
|
||||||
} else {
|
if (dlen != sizeof(data)) {
|
||||||
if (blockno > 0x0f && blockno != 0xff) {
|
PrintAndLogEx(FAILED, "data must be 4 hex bytes, got %d", dlen);
|
||||||
PrintAndLogEx(FAILED, "block number out of range");
|
return PM3_EINVARG;
|
||||||
return PM3_ESOFT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (param_gethex(Cmd, 2, data, 8)) {
|
if (use_sri512 + use_srix4k > 1) {
|
||||||
PrintAndLogEx(WARNING, "data must include 8 HEX symbols");
|
PrintAndLogEx(FAILED, "Select only one card type");
|
||||||
return PM3_ESOFT;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blockno == 0xff) {
|
if (use_srix4k && blockno > 0x7F) {
|
||||||
|
PrintAndLogEx(FAILED, "block number out of range, max 127 (0x7F)");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (use_sri512 && blockno > 0x0F) {
|
||||||
|
PrintAndLogEx(FAILED, "block number out of range, max 15 (0x0F)");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
// special block at end of memory
|
||||||
|
if (special) {
|
||||||
|
blockno = 0xFF;
|
||||||
PrintAndLogEx(SUCCESS, "[%s] Write special block %02X [ " _YELLOW_("%s")" ]",
|
PrintAndLogEx(SUCCESS, "[%s] Write special block %02X [ " _YELLOW_("%s")" ]",
|
||||||
(isSrix4k) ? "SRIX4K" : "SRI512",
|
(use_srix4k) ? "SRIX4K" : "SRI512",
|
||||||
blockno,
|
blockno,
|
||||||
sprint_hex(data, 4)
|
sprint_hex(data, sizeof(data))
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(SUCCESS, "[%s] Write block %02X [ " _YELLOW_("%s")" ]",
|
PrintAndLogEx(SUCCESS, "[%s] Write block %02X [ " _YELLOW_("%s")" ]",
|
||||||
(isSrix4k) ? "SRIX4K" : "SRI512",
|
(use_srix4k) ? "SRIX4K" : "SRI512",
|
||||||
blockno,
|
blockno,
|
||||||
sprint_hex(data, 4)
|
sprint_hex(data, sizeof(data))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char str[36];
|
||||||
|
memset(str, 0x00, sizeof(str));
|
||||||
sprintf(str, "--sr -c --data %02x%02x%02x%02x%02x%02x", ISO14443B_WRITE_BLK, blockno, data[0], data[1], data[2], data[3]);
|
sprintf(str, "--sr -c --data %02x%02x%02x%02x%02x%02x", ISO14443B_WRITE_BLK, blockno, data[0], data[1], data[2], data[3]);
|
||||||
return CmdHF14BCmdRaw(str);
|
return CmdHF14BCmdRaw(str);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue