2020-06-15 20:31:34 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 2020 tharexde
|
|
|
|
//
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Low frequency EM4x50 commands
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "cmdlfem4x50.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "fileutils.h"
|
|
|
|
#include "comms.h"
|
2020-06-18 05:39:00 +08:00
|
|
|
#include "commonutil.h"
|
2020-06-15 20:31:34 +08:00
|
|
|
#include "em4x50.h"
|
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
static int usage_lf_em4x50_info(void) {
|
2020-06-15 20:31:34 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Read all information of EM4x50. Tag nust be on antenna.");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_info [h] [v] [p <pwd>]");
|
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " v - verbose output");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info"));
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info p fa225de1"));
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_info v p fa225de1"));
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-15 20:31:34 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
static int usage_lf_em4x50_write(void) {
|
2020-06-17 05:25:27 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Write EM4x50 word. Tag must be on antenna. ");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write [h] [a <address>] [w <data>]");
|
2020-06-17 05:25:27 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " a <addr> - memory address to write to (dec)");
|
|
|
|
PrintAndLogEx(NORMAL, " w <word> - word to write (hex)");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_write a 3 w deadc0de"));
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-17 05:25:27 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
static int usage_lf_em4x50_write_password(void) {
|
2020-06-17 05:25:27 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Write EM4x50 password. Tag must be on antenna. ");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write_password [h] [p <pwd>] [n <pwd>]");
|
2020-06-17 05:25:27 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex)");
|
|
|
|
PrintAndLogEx(NORMAL, " n <pwd> - new password (hex)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_write_password p 11223344 n 01020304"));
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-17 05:25:27 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
static int usage_lf_em4x50_read(void) {
|
|
|
|
PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna.");
|
2020-06-26 20:20:46 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] [a <address>] [p <pwd>]");
|
2020-06-26 20:20:46 +08:00
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " a <addr> - memory address to read (dec) (optional)");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_read"));
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_read a 2 p 00000000"));
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
2020-06-26 20:20:46 +08:00
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
static int usage_lf_em4x50_dump(void) {
|
|
|
|
PrintAndLogEx(NORMAL, "Dump EM4x50 tag. Tag must be on antenna.");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_dump [h] [f <filename prefix>] [p <pwd>]");
|
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " f <filename prefix> - overide filename prefix (optional). Default is based on UID");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_dump"));
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_dump p 11223344"));
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_dump f card_nnn p 11223344"));
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-09 08:00:09 +08:00
|
|
|
static int usage_lf_em4x50_wipe(void) {
|
|
|
|
PrintAndLogEx(NORMAL, "Wipe data from EM4x50 tag. Tag must be on antenna. ");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_wipe [h] [p <pwd>]");
|
|
|
|
PrintAndLogEx(NORMAL, "Options:");
|
|
|
|
PrintAndLogEx(NORMAL, " h - this help");
|
|
|
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex)");
|
|
|
|
PrintAndLogEx(NORMAL, "Examples:");
|
|
|
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_wwipe p 11223344"));
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-06-15 20:31:34 +08:00
|
|
|
|
|
|
|
static void prepare_result(const uint8_t *byte, int fwr, int lwr, em4x50_word_t *words) {
|
|
|
|
|
|
|
|
// restructure received result in "em4x50_word_t" structure and check all
|
|
|
|
// parities including stop bit; result of each check is stored in structure
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
int p = 0, c[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
for (int i = fwr; i <= lwr; i++) {
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
words[i].stopparity = true;
|
|
|
|
words[i].parity = true;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
for (int j = 0; j < 8; j++)
|
|
|
|
c[j] = 0;
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
words[i].byte[j] = byte[i*7+j];
|
|
|
|
words[i].row_parity[j] = (byte[i*7+4] >> (3-j)) & 1;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// collect parities
|
|
|
|
p = 0;
|
|
|
|
|
|
|
|
for (int k = 0; k < 8; k++) {
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// row parity
|
|
|
|
p ^= (words[i].byte[j] >> k) & 1;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// column parity
|
|
|
|
c[k] ^= (words[i].byte[j] >> (7-k)) & 1;
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// check row parities
|
|
|
|
words[i].rparity[j] = (words[i].row_parity[j] == p) ? true : false;
|
|
|
|
|
|
|
|
if (!words[i].rparity[j])
|
|
|
|
words[i].parity = false;
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// check column parities
|
2020-06-26 20:20:46 +08:00
|
|
|
words[i].col_parity = byte[i*7+5];
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
for (int j = 0; j < 8; j++) {
|
|
|
|
words[i].cparity[j] = (((words[i].col_parity >> (7-j)) & 1) == c[j]) ? true : false;
|
|
|
|
|
|
|
|
if (!words[i].cparity[j])
|
2020-06-26 20:20:46 +08:00
|
|
|
words[i].parity = false;
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// check stop bit
|
|
|
|
words[i].stopbit = byte[i*7+6] & 1;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
if (words[i].stopbit == 1)
|
|
|
|
words[i].stopparity = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// print available information for given word from fwr to lwr, i.e.
|
|
|
|
// bit table + summary lines with hex notation of word (msb + lsb)
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, " # | word (msb) | word (lsb) | desc");
|
|
|
|
PrintAndLogEx(INFO, "----+-------------+-------------+--------------------");
|
2020-06-15 20:31:34 +08:00
|
|
|
|
|
|
|
for (int i = fwr; i <= lwr; i++) {
|
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
char s[50] = {0};
|
|
|
|
switch(i) {
|
|
|
|
case EM4X50_DEVICE_PASSWORD:
|
|
|
|
sprintf(s, _YELLOW_("password, write only"));
|
|
|
|
break;
|
|
|
|
case EM4X50_PROTECTION:
|
|
|
|
sprintf(s, _YELLOW_("protection cfg (locked)"));
|
|
|
|
break;
|
|
|
|
case EM4X50_CONTROL:
|
|
|
|
sprintf(s, _YELLOW_("control cfg (locked)"));
|
|
|
|
break;
|
|
|
|
case EM4X50_DEVICE_SERIAL:
|
|
|
|
sprintf(s, _YELLOW_("device serial number (read only)"));
|
|
|
|
break;
|
|
|
|
case EM4X50_DEVICE_ID:
|
|
|
|
sprintf(s, _YELLOW_("device identification (read only)"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf(s, "user data");
|
|
|
|
break;
|
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
char r[30] = {0};
|
|
|
|
for (int j = 3; j >= 0; j--) {
|
|
|
|
sprintf(r + strlen(r), "%02x ", reflect8(words[i].byte[j]));
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
|
|
|
|
PrintAndLogEx(INFO, " %2i | " _GREEN_("%s") "| %s| %s",
|
|
|
|
i,
|
|
|
|
sprint_hex(words[i].byte, 4),
|
|
|
|
r,
|
|
|
|
s
|
|
|
|
);
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
PrintAndLogEx(INFO, "----+-------------+-------------+--------------------");
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
static void print_info_result(uint8_t *data, bool verbose) {
|
2020-06-15 20:31:34 +08:00
|
|
|
|
2020-06-23 06:36:19 +08:00
|
|
|
// display all information of info result in structured format
|
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
|
|
|
prepare_result(data, 0, EM4X50_NO_WORDS - 1, words);
|
|
|
|
|
|
|
|
bool bpwc = words[EM4X50_CONTROL].byte[CONFIG_BLOCK] & PASSWORD_CHECK;
|
|
|
|
bool braw = words[EM4X50_CONTROL].byte[CONFIG_BLOCK] & READ_AFTER_WRITE;
|
2020-06-30 23:43:47 +08:00
|
|
|
|
2020-06-23 06:36:19 +08:00
|
|
|
int fwr = reflect8(words[EM4X50_CONTROL].byte[FIRST_WORD_READ]);
|
|
|
|
int lwr = reflect8(words[EM4X50_CONTROL].byte[LAST_WORD_READ]);
|
|
|
|
int fwrp = reflect8(words[EM4X50_PROTECTION].byte[FIRST_WORD_READ_PROTECTED]);
|
|
|
|
int lwrp = reflect8(words[EM4X50_PROTECTION].byte[LAST_WORD_READ_PROTECTED]);
|
|
|
|
int fwwi = reflect8(words[EM4X50_PROTECTION].byte[FIRST_WORD_WRITE_INHIBITED]);
|
|
|
|
int lwwi = reflect8(words[EM4X50_PROTECTION].byte[LAST_WORD_WRITE_INHIBITED]);
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------");
|
|
|
|
PrintAndLogEx(INFO, "-------------------------------------------------------------");
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// data section
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, _YELLOW_("EM4x50 data:"));
|
2020-07-06 11:41:44 +08:00
|
|
|
print_result(words, 0, EM4X50_NO_WORDS - 1);
|
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
// configuration section
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, "---- " _CYAN_("Configuration") " ----");
|
2020-06-15 20:31:34 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(INFO, "first word read %3i", fwr);
|
|
|
|
PrintAndLogEx(INFO, "last word read %3i", lwr);
|
|
|
|
PrintAndLogEx(INFO, "password check %3s", (bpwc) ? _RED_("on"): _GREEN_("off"));
|
|
|
|
PrintAndLogEx(INFO, "read after write %3s", (braw) ? "on" : "off");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, "--------- " _CYAN_("Protection") " ---------");
|
|
|
|
PrintAndLogEx(INFO, "first word read protected %3i", fwrp);
|
|
|
|
PrintAndLogEx(INFO, "last word read protected %3i", lwrp);
|
|
|
|
PrintAndLogEx(INFO, "first word write inhibited %3i", fwwi);
|
|
|
|
PrintAndLogEx(INFO, "last word write inhibited %3i", lwwi);
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
PrintAndLogEx(INFO, "zero values may indicate read protection");
|
|
|
|
PrintAndLogEx(NORMAL, "");
|
|
|
|
}
|
2020-06-15 20:31:34 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
//quick test for EM4x50 tag
|
|
|
|
bool detect_4x50_block(void) {
|
|
|
|
em4x50_data_t etd = {
|
|
|
|
.pwd_given = false,
|
|
|
|
.addr_given = true,
|
|
|
|
.address = EM4X50_DEVICE_ID,
|
|
|
|
};
|
2020-07-01 00:50:38 +08:00
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
2020-06-30 23:43:47 +08:00
|
|
|
return (em4x50_read(&etd, words, false) == PM3_SUCCESS);
|
|
|
|
}
|
2020-06-15 20:31:34 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
int read_em4x50_uid(void) {
|
|
|
|
em4x50_data_t etd = {
|
|
|
|
.pwd_given = false,
|
|
|
|
.addr_given = true,
|
|
|
|
.address = EM4X50_DEVICE_SERIAL,
|
|
|
|
};
|
2020-07-01 00:50:38 +08:00
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
2020-06-30 23:43:47 +08:00
|
|
|
int res = em4x50_read(&etd, words, false);
|
|
|
|
if (res == PM3_SUCCESS)
|
|
|
|
PrintAndLogEx(INFO, " Serial: " _GREEN_("%s"), sprint_hex(words[EM4X50_DEVICE_SERIAL].byte, 4));
|
|
|
|
return res;
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int CmdEM4x50Info(const char *Cmd) {
|
|
|
|
|
2020-06-17 05:25:27 +08:00
|
|
|
// envoke reading of a EM4x50 tag which has to be on the antenna because
|
2020-06-15 20:31:34 +08:00
|
|
|
// decoding is done by the device (not on client side)
|
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
bool errors = false, verbose = false;
|
2020-06-15 20:31:34 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
em4x50_data_t etd;
|
2020-06-17 05:25:27 +08:00
|
|
|
etd.pwd_given = false;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
return usage_lf_em4x50_info();
|
|
|
|
|
|
|
|
case 'p':
|
2020-06-19 07:19:01 +08:00
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
2020-06-15 20:31:34 +08:00
|
|
|
etd.pwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
verbose = true;
|
|
|
|
cmdp += 1;
|
|
|
|
break;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-15 20:31:34 +08:00
|
|
|
default:
|
|
|
|
PrintAndLogEx(WARNING, " Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// validation
|
2020-06-19 07:19:01 +08:00
|
|
|
if (errors)
|
2020-06-15 20:31:34 +08:00
|
|
|
return usage_lf_em4x50_info();
|
|
|
|
|
|
|
|
clearCommandBuffer();
|
2020-06-18 05:50:52 +08:00
|
|
|
SendCommandNG(CMD_LF_EM4X50_INFO, (uint8_t *)&etd, sizeof(etd));
|
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
PacketResponseNG resp;
|
2020-06-29 03:35:06 +08:00
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
2020-06-18 05:13:13 +08:00
|
|
|
return PM3_ETIMEOUT;
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
bool success = (resp.status & STATUS_SUCCESS) >> 1;
|
|
|
|
if (success) {
|
|
|
|
print_info_result(resp.data.asBytes, verbose);
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(FAILED, "reading tag " _RED_("failed"));
|
|
|
|
return PM3_ESOFT;
|
2020-06-15 20:31:34 +08:00
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-17 05:25:27 +08:00
|
|
|
int CmdEM4x50Write(const char *Cmd) {
|
|
|
|
|
|
|
|
// envoke writing a single word (32 bit) to a EM4x50 tag
|
|
|
|
|
2020-06-30 23:59:06 +08:00
|
|
|
em4x50_data_t etd = { .pwd_given = false };
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:59:06 +08:00
|
|
|
bool errors = false, bword = false, baddr = false;
|
2020-06-17 05:25:27 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
|
|
|
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
2020-06-30 23:59:06 +08:00
|
|
|
case 'h': {
|
2020-06-17 05:25:27 +08:00
|
|
|
return usage_lf_em4x50_write();
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
|
|
|
case 'p': {
|
2020-06-19 07:19:01 +08:00
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
2020-06-17 05:25:27 +08:00
|
|
|
etd.pwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
|
|
|
case 'w': {
|
2020-06-19 07:19:01 +08:00
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.word, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n word has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-19 07:19:01 +08:00
|
|
|
bword = true;
|
2020-06-17 05:25:27 +08:00
|
|
|
cmdp += 2;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
|
|
|
case 'a': {
|
2020-06-19 07:19:01 +08:00
|
|
|
param_getdec(Cmd, cmdp + 1, &etd.address);
|
|
|
|
|
2020-06-17 05:25:27 +08:00
|
|
|
// validation
|
2020-06-19 07:19:01 +08:00
|
|
|
if (etd.address < 1 || etd.address > 31) {
|
|
|
|
PrintAndLogEx(FAILED, "\n error, address has to be in range [1-31]\n");
|
|
|
|
return PM3_EINVARG;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-19 07:19:01 +08:00
|
|
|
baddr = true;
|
2020-06-17 05:25:27 +08:00
|
|
|
cmdp += 2;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
|
|
|
default: {
|
2020-06-17 05:25:27 +08:00
|
|
|
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 07:19:01 +08:00
|
|
|
if (errors || !bword || !baddr)
|
2020-06-17 05:25:27 +08:00
|
|
|
return usage_lf_em4x50_write();
|
|
|
|
|
|
|
|
clearCommandBuffer();
|
2020-06-18 05:50:52 +08:00
|
|
|
SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd));
|
2020-06-30 23:59:06 +08:00
|
|
|
PacketResponseNG resp;
|
2020-06-29 03:35:06 +08:00
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
2020-06-18 05:13:13 +08:00
|
|
|
return PM3_ETIMEOUT;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-06-30 23:59:06 +08:00
|
|
|
bool isOK = (resp.status & STATUS_SUCCESS) >> 1;
|
|
|
|
if (isOK == false) {
|
|
|
|
PrintAndLogEx(FAILED, "writing " _RED_("failed"));
|
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:59:06 +08:00
|
|
|
if (etd.pwd_given) {
|
|
|
|
bool login = resp.status & STATUS_LOGIN;
|
|
|
|
if (login == false) {
|
|
|
|
PrintAndLogEx(FAILED, "login failed");
|
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
|
|
|
PrintAndLogEx(SUCCESS, "login with password " _YELLOW_("%s"), sprint_hex_inrow(etd.password, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
// display result of writing operation in structured format
|
|
|
|
uint8_t *data = resp.data.asBytes;
|
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
|
|
|
|
|
|
|
prepare_result(data, etd.address, etd.address, words);
|
2020-07-06 11:41:44 +08:00
|
|
|
print_result(words, etd.address, etd.address);
|
2020-06-30 23:59:06 +08:00
|
|
|
PrintAndLogEx(SUCCESS, "Successfully wrote to tag");
|
|
|
|
PrintAndLogEx(HINT, "Try `" _YELLOW_("lf em 4x50_read a %u") "` - to read your data", etd.address);
|
|
|
|
return PM3_SUCCESS;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void print_write_password_result(PacketResponseNG *resp, const em4x50_data_t *etd) {
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-17 05:25:27 +08:00
|
|
|
// display result of password changing operation
|
|
|
|
|
2020-06-23 06:36:19 +08:00
|
|
|
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
2020-06-17 05:25:27 +08:00
|
|
|
|
2020-06-29 03:35:06 +08:00
|
|
|
sprintf(pstring, "\n writing new password " _GREEN_("ok"));
|
|
|
|
strcat(string, pstring);
|
2020-06-17 05:25:27 +08:00
|
|
|
|
|
|
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CmdEM4x50WritePassword(const char *Cmd) {
|
|
|
|
|
|
|
|
// envokes changing the password of EM4x50 tag
|
|
|
|
|
2020-06-29 03:35:06 +08:00
|
|
|
bool errors = false, bpwd = false, bnpwd = false, success = false;
|
2020-06-17 05:25:27 +08:00
|
|
|
uint8_t cmdp = 0;
|
|
|
|
em4x50_data_t etd;
|
|
|
|
PacketResponseNG resp;
|
|
|
|
|
|
|
|
// init
|
|
|
|
etd.pwd_given = false;
|
|
|
|
etd.newpwd_given = false;
|
|
|
|
|
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
|
|
|
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
|
|
case 'h':
|
|
|
|
return usage_lf_em4x50_write_password();
|
|
|
|
|
|
|
|
case 'p':
|
2020-06-19 07:19:01 +08:00
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-19 07:19:01 +08:00
|
|
|
bpwd = true;
|
2020-06-17 05:25:27 +08:00
|
|
|
etd.pwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
2020-06-19 07:19:01 +08:00
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.new_password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
|
|
|
bnpwd = true;
|
2020-06-17 05:25:27 +08:00
|
|
|
etd.newpwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 07:19:01 +08:00
|
|
|
if (errors || !bpwd || !bnpwd)
|
2020-06-17 05:25:27 +08:00
|
|
|
return usage_lf_em4x50_write_password();
|
|
|
|
|
|
|
|
clearCommandBuffer();
|
2020-06-18 05:50:52 +08:00
|
|
|
SendCommandNG(CMD_LF_EM4X50_WRITE_PASSWORD, (uint8_t *)&etd, sizeof(etd));
|
2020-06-17 05:25:27 +08:00
|
|
|
|
2020-06-29 03:35:06 +08:00
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
2020-06-18 05:13:13 +08:00
|
|
|
return PM3_ETIMEOUT;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
success = (bool)resp.status;
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-17 05:25:27 +08:00
|
|
|
// get, prepare and print response
|
2020-06-29 03:35:06 +08:00
|
|
|
if (success)
|
|
|
|
print_write_password_result(&resp, &etd);
|
|
|
|
else
|
|
|
|
PrintAndLogEx(NORMAL,"\nwriting password " _RED_("failed") "\n");
|
|
|
|
|
|
|
|
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
2020-06-17 05:25:27 +08:00
|
|
|
}
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
int em4x50_read(em4x50_data_t *etd, em4x50_word_t *out, bool verbose) {
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
// envoke reading
|
|
|
|
// - without option -> standard read mode
|
|
|
|
// - with given address (option a) (and optional password if address is
|
|
|
|
// read protected) -> selective read mode
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:59:06 +08:00
|
|
|
em4x50_data_t edata = { .pwd_given = false, .addr_given = false };
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
if (etd != NULL) {
|
|
|
|
edata = *etd;
|
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
clearCommandBuffer();
|
|
|
|
SendCommandNG(CMD_LF_EM4X50_READ, (uint8_t *)&edata, sizeof(edata));
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
PacketResponseNG resp;
|
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
|
|
|
return PM3_ETIMEOUT;
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
bool isOK = (resp.status & STATUS_SUCCESS) >> 1;
|
|
|
|
if (isOK == false) {
|
|
|
|
if (verbose)
|
|
|
|
PrintAndLogEx(FAILED, "reading " _RED_("failed"));
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
if (edata.pwd_given) {
|
|
|
|
bool login = resp.status & STATUS_LOGIN;
|
|
|
|
if (login == false) {
|
|
|
|
PrintAndLogEx(FAILED, "login failed");
|
|
|
|
return PM3_ESOFT;
|
2020-06-29 03:35:06 +08:00
|
|
|
}
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(SUCCESS, "login with password " _YELLOW_("%s"), sprint_hex_inrow(etd->password, 4));
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
uint8_t *data = resp.data.asBytes;
|
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
|
|
|
if (edata.addr_given) {
|
2020-07-01 00:50:38 +08:00
|
|
|
prepare_result(data, etd->address, etd->address, words);
|
2020-06-26 20:20:46 +08:00
|
|
|
} else {
|
2020-06-30 23:43:47 +08:00
|
|
|
int now = (resp.status & STATUS_NO_WORDS) >> 2;
|
2020-06-30 07:51:24 +08:00
|
|
|
prepare_result(data, 0, now - 1, words);
|
2020-06-30 23:43:47 +08:00
|
|
|
}
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
if (out != NULL) {
|
|
|
|
memcpy(out, &words, sizeof(em4x50_word_t) * EM4X50_NO_WORDS);
|
|
|
|
}
|
2020-07-01 00:50:38 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
print_result(words, etd->address, etd->address);
|
2020-06-30 23:43:47 +08:00
|
|
|
return PM3_SUCCESS;
|
2020-06-26 20:20:46 +08:00
|
|
|
}
|
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
int CmdEM4x50Read(const char *Cmd) {
|
2020-06-26 20:20:46 +08:00
|
|
|
|
|
|
|
em4x50_data_t etd;
|
|
|
|
etd.pwd_given = false;
|
|
|
|
etd.addr_given = false;
|
2020-08-13 18:21:40 +08:00
|
|
|
etd.newpwd_given = false;
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
bool errors = false;
|
2020-07-01 00:50:38 +08:00
|
|
|
uint8_t cmdp = 0;
|
2020-06-30 23:43:47 +08:00
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
2020-06-30 23:59:06 +08:00
|
|
|
case 'h': {
|
2020-06-30 23:43:47 +08:00
|
|
|
return usage_lf_em4x50_read();
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
|
|
|
case 'a': {
|
2020-06-30 23:43:47 +08:00
|
|
|
param_getdec(Cmd, cmdp + 1, &etd.address);
|
2020-06-26 20:20:46 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
// validation
|
|
|
|
if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) {
|
|
|
|
PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
|
|
|
etd.addr_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
case 'p': {
|
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
|
|
|
etd.pwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
}
|
2020-06-30 23:59:06 +08:00
|
|
|
default: {
|
2020-06-30 23:43:47 +08:00
|
|
|
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
2020-06-30 23:59:06 +08:00
|
|
|
}
|
2020-06-30 23:43:47 +08:00
|
|
|
}
|
2020-06-26 20:20:46 +08:00
|
|
|
}
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
if (errors || strlen(Cmd) == 0 || etd.addr_given == false)
|
2020-06-30 23:43:47 +08:00
|
|
|
return usage_lf_em4x50_read();
|
2020-06-29 03:35:06 +08:00
|
|
|
|
2020-06-30 23:43:47 +08:00
|
|
|
return em4x50_read(&etd, NULL, true);
|
2020-06-26 20:20:46 +08:00
|
|
|
}
|
2020-07-06 11:41:44 +08:00
|
|
|
|
|
|
|
int CmdEM4x50Dump(const char *Cmd) {
|
|
|
|
|
|
|
|
em4x50_data_t etd;
|
|
|
|
etd.pwd_given = false;
|
|
|
|
etd.addr_given = false;
|
2020-07-12 02:46:37 +08:00
|
|
|
etd.newpwd_given = false;
|
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
char filename[FILE_PATH_SIZE] = {0x00};
|
|
|
|
char *fptr = filename;
|
2020-07-12 02:46:37 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
bool errors = false;
|
|
|
|
uint8_t cmdp = 0;
|
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
|
|
case 'h':
|
|
|
|
return usage_lf_em4x50_dump();
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE);
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
case 'p': {
|
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
|
|
|
etd.pwd_given = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
PrintAndLogEx(WARNING, " Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// validation
|
|
|
|
if (errors)
|
|
|
|
return usage_lf_em4x50_dump();
|
|
|
|
|
|
|
|
PrintAndLogEx(INFO, "reading EM4x50 tag");
|
|
|
|
clearCommandBuffer();
|
|
|
|
SendCommandNG(CMD_LF_EM4X50_INFO, (uint8_t *)&etd, sizeof(etd));
|
|
|
|
PacketResponseNG resp;
|
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
|
|
|
return PM3_ETIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool success = (resp.status & STATUS_SUCCESS) >> 1;
|
|
|
|
if (success == false) {
|
|
|
|
PrintAndLogEx(FAILED, "reading tag " _RED_("failed"));
|
2020-07-12 02:46:37 +08:00
|
|
|
return PM3_ESOFT;
|
2020-07-06 11:41:44 +08:00
|
|
|
}
|
2020-07-12 02:46:37 +08:00
|
|
|
|
2020-07-06 11:41:44 +08:00
|
|
|
// structured format
|
|
|
|
em4x50_word_t words[EM4X50_NO_WORDS];
|
|
|
|
prepare_result(resp.data.asBytes, 0, EM4X50_NO_WORDS - 1, words);
|
|
|
|
|
|
|
|
PrintAndLogEx(INFO, _YELLOW_("EM4x50 data:"));
|
|
|
|
print_result(words, 0, EM4X50_NO_WORDS - 1);
|
|
|
|
|
|
|
|
// user supplied filename?
|
|
|
|
if (strlen(filename) == 0) {
|
|
|
|
PrintAndLogEx(INFO, "Using UID as filename");
|
|
|
|
fptr += sprintf(fptr, "lf-4x50-");
|
|
|
|
FillFileNameByUID(fptr, words[EM4X50_DEVICE_SERIAL].byte, "-dump", 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t data[EM4X50_NO_WORDS * 4] = {0};
|
|
|
|
for (int i=0; i < EM4X50_NO_WORDS; i++) {
|
|
|
|
memcpy(data + (i*4), words[i].byte, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// saveFileEML will add .eml extension to filename
|
|
|
|
// saveFile (binary) passes in the .bin extension.
|
|
|
|
saveFileEML(filename, data, sizeof(data), 4);
|
|
|
|
saveFile(filename, ".bin", data, sizeof(data));
|
|
|
|
//saveFileJSON...
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|
2020-07-09 08:00:09 +08:00
|
|
|
|
|
|
|
int CmdEM4x50Wipe(const char *Cmd) {
|
|
|
|
|
|
|
|
// fills EM4x50 tag with zeros including password
|
|
|
|
|
|
|
|
bool errors = false, bpwd = false;
|
|
|
|
uint8_t cmdp = 0;
|
|
|
|
em4x50_data_t etd;
|
|
|
|
PacketResponseNG resp;
|
|
|
|
|
|
|
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
|
|
|
|
|
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
|
|
case 'h':
|
|
|
|
return usage_lf_em4x50_wipe();
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
|
|
|
PrintAndLogEx(FAILED, "\npassword has to be 8 hex symbols\n");
|
|
|
|
return PM3_EINVARG;
|
|
|
|
}
|
|
|
|
bpwd = true;
|
|
|
|
cmdp += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
PrintAndLogEx(WARNING, "\nUnknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
|
|
|
errors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errors || !bpwd)
|
|
|
|
return usage_lf_em4x50_wipe();
|
|
|
|
|
|
|
|
clearCommandBuffer();
|
|
|
|
SendCommandNG(CMD_LF_EM4X50_WIPE, (uint8_t *)&etd, sizeof(etd));
|
|
|
|
|
|
|
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, 2*TIMEOUT)) {
|
|
|
|
PrintAndLogEx(WARNING, "\ntimeout while waiting for reply.\n");
|
|
|
|
return PM3_ETIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print response
|
|
|
|
bool isOK = resp.status;
|
|
|
|
if (isOK) {
|
|
|
|
PrintAndLogEx(SUCCESS,"\nwiping data " _GREEN_("ok") "\n");
|
|
|
|
} else {
|
|
|
|
PrintAndLogEx(FAILED,"\nwiping data " _RED_("failed") "\n");
|
|
|
|
return PM3_ESOFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PM3_SUCCESS;
|
|
|
|
}
|