mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
output changes due to integration of 'read' into 'lf search' process
This commit is contained in:
parent
955c7a642d
commit
c6435d2f96
1 changed files with 194 additions and 184 deletions
|
@ -54,17 +54,17 @@ int usage_lf_em4x50_write_password(void) {
|
||||||
PrintAndLogEx(NORMAL, " lf em 4x50_write_password p 11223344 n 01020304");
|
PrintAndLogEx(NORMAL, " lf em 4x50_write_password p 11223344 n 01020304");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
int usage_lf_em4x50_sread(void) {
|
int usage_lf_em4x50_read(void) {
|
||||||
PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna. ");
|
PrintAndLogEx(NORMAL, "Read EM4x50 word(s). Tag must be on antenna. ");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_sread [h] a <address> p <pwd>");
|
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] a <address> p <pwd>");
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
PrintAndLogEx(NORMAL, " h - this help");
|
PrintAndLogEx(NORMAL, " h - this help");
|
||||||
PrintAndLogEx(NORMAL, " a <addr> - memory address to read (dec) (optional)");
|
PrintAndLogEx(NORMAL, " a <addr> - memory address to read (dec) (optional)");
|
||||||
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex) (optional)");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
PrintAndLogEx(NORMAL, " lf em 4x50_sread");
|
PrintAndLogEx(NORMAL, " lf em 4x50_read");
|
||||||
PrintAndLogEx(NORMAL, " lf em 4x50_sread a 2 p 00000000");
|
PrintAndLogEx(NORMAL, " lf em 4x50_read a 2 p 00000000");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ static void print_bit_table(const em4x50_word_t word) {
|
||||||
string[0] = '\0';
|
string[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
|
static void print_result(const em4x50_word_t *words, int fwr, int lwr, bool verbose) {
|
||||||
|
|
||||||
// print available information for given word from fwr to lwr, i.e.
|
// print available information for given word from fwr to lwr, i.e.
|
||||||
// bit table + summary lines with hex notation of word (msb + lsb)
|
// bit table + summary lines with hex notation of word (msb + lsb)
|
||||||
|
@ -199,28 +199,41 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
|
||||||
|
|
||||||
for (int i = fwr; i <= lwr; i++) {
|
for (int i = fwr; i <= lwr; i++) {
|
||||||
|
|
||||||
// blank line before each bit table
|
if (verbose) {
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
|
|
||||||
// print bit table
|
// blank line before each bit table
|
||||||
print_bit_table(words[i]);
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
// final result
|
// print bit table
|
||||||
string[0] = '\0';
|
print_bit_table(words[i]);
|
||||||
sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i);
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
for (int j = 0; j < 4; j++) {
|
// final result
|
||||||
sprintf(pstring, _GREEN_("%02x"), words[i].byte[j]);
|
string[0] = '\0';
|
||||||
|
sprintf(pstring, "\n word[%i] msb: " _GREEN_("0x"), i);
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
}
|
|
||||||
|
|
||||||
sprintf(pstring, "\n word[%i] lsb: 0x", i);
|
for (int j = 0; j < 4; j++) {
|
||||||
strcat(string, pstring);
|
sprintf(pstring, _GREEN_("%02x"), words[i].byte[j]);
|
||||||
|
strcat(string, pstring);
|
||||||
|
}
|
||||||
|
|
||||||
for (int j = 0; j < 4; j++) {
|
sprintf(pstring, "\n word[%i] lsb: 0x", i);
|
||||||
sprintf(pstring, "%02x", reflect8(words[i].byte[3-j]));
|
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
sprintf(pstring, "%02x", reflect8(words[i].byte[3-j]));
|
||||||
|
strcat(string, pstring);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
string[0] = '\0';
|
||||||
|
sprintf(pstring, "[" _GREEN_("+") "] word[%i]: " _YELLOW_("0x"), i);
|
||||||
|
strcat(string, pstring);
|
||||||
|
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
sprintf(pstring, _YELLOW_("%02x"), words[i].byte[j]);
|
||||||
|
strcat(string, pstring);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,string);
|
PrintAndLogEx(NORMAL,string);
|
||||||
|
@ -236,7 +249,6 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd,
|
||||||
char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0};
|
char pstring[NO_CHARS_MAX] = {0}, string[NO_CHARS_MAX] = {0};
|
||||||
|
|
||||||
bool bpwd_given = etd->pwd_given;
|
bool bpwd_given = etd->pwd_given;
|
||||||
bool bsuccess = (resp->status & STATUS_SUCCESS) >> 1;
|
|
||||||
bool blogin = resp->status & STATUS_LOGIN;
|
bool blogin = resp->status & STATUS_LOGIN;
|
||||||
|
|
||||||
prepare_result(data, 0, EM4X50_NO_WORDS - 1, words);
|
prepare_result(data, 0, EM4X50_NO_WORDS - 1, words);
|
||||||
|
@ -256,7 +268,7 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd,
|
||||||
if (bverbose) {
|
if (bverbose) {
|
||||||
|
|
||||||
// detailed data section
|
// detailed data section
|
||||||
print_result(words, 0, EM4X50_NO_WORDS - 1);
|
print_result(words, 0, EM4X50_NO_WORDS - 1, true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -336,47 +348,38 @@ static void print_info_result(PacketResponseNG *resp, const em4x50_data_t *etd,
|
||||||
sprintf(pstring, " reading ");
|
sprintf(pstring, " reading ");
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
|
|
||||||
if (!bsuccess) {
|
sprintf(pstring, _GREEN_("ok "));
|
||||||
|
strcat(string, pstring);
|
||||||
|
|
||||||
sprintf(pstring, _RED_("failed"));
|
if (blogin) {
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
} else {
|
if (bpwd_given) {
|
||||||
|
|
||||||
sprintf(pstring, _GREEN_("ok "));
|
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
||||||
strcat(string, pstring);
|
etd->password[0], etd->password[1],
|
||||||
|
etd->password[2], etd->password[3]);
|
||||||
if (blogin) {
|
strcat(string, pstring);
|
||||||
|
|
||||||
if (bpwd_given) {
|
|
||||||
|
|
||||||
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
|
||||||
etd->password[0], etd->password[1],
|
|
||||||
etd->password[2], etd->password[3]);
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
sprintf(pstring, "(login with default password 0x00000000)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (bpwd_given) {
|
sprintf(pstring, "(login with default password 0x00000000)");
|
||||||
|
strcat(string, pstring);
|
||||||
|
|
||||||
sprintf(pstring, "(login failed)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
sprintf(pstring, "(no login)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (bpwd_given) {
|
||||||
|
|
||||||
|
sprintf(pstring, "(login failed)");
|
||||||
|
strcat(string, pstring);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
sprintf(pstring, "(no login)");
|
||||||
|
strcat(string, pstring);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||||
|
@ -432,15 +435,19 @@ int CmdEM4x50Info(const char *Cmd) {
|
||||||
|
|
||||||
|
|
||||||
// get result
|
// get result
|
||||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
PrintAndLogEx(WARNING, " timeout while waiting for reply.");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// print result
|
|
||||||
print_info_result(&resp, &etd, verbose);
|
|
||||||
|
|
||||||
success = (resp.status & STATUS_SUCCESS) >> 1;
|
success = (resp.status & STATUS_SUCCESS) >> 1;
|
||||||
|
|
||||||
|
// print result
|
||||||
|
if (success)
|
||||||
|
print_info_result(&resp, &etd, verbose);
|
||||||
|
else
|
||||||
|
PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n");
|
||||||
|
|
||||||
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,41 +456,32 @@ static void print_write_result(PacketResponseNG *resp, const em4x50_data_t *etd)
|
||||||
// display result of writing operation in structured format
|
// display result of writing operation in structured format
|
||||||
|
|
||||||
bool pwd_given = etd->pwd_given;
|
bool pwd_given = etd->pwd_given;
|
||||||
bool success = (resp->status & STATUS_SUCCESS) >> 1;
|
|
||||||
bool login = resp->status & STATUS_LOGIN;
|
bool login = resp->status & STATUS_LOGIN;
|
||||||
uint8_t *data = resp->data.asBytes;
|
uint8_t *data = resp->data.asBytes;
|
||||||
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
||||||
em4x50_word_t word;
|
em4x50_word_t word;
|
||||||
|
|
||||||
if (!success) {
|
prepare_result(data, etd->address, etd->address, &word);
|
||||||
|
print_result(&word, etd->address, etd->address, true);
|
||||||
|
|
||||||
sprintf(pstring, "\n writing " _RED_("failed"));
|
sprintf(pstring, "\n writing " _GREEN_("ok "));
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
|
|
||||||
} else {
|
if (pwd_given) {
|
||||||
|
|
||||||
prepare_result(data, etd->address, etd->address, &word);
|
|
||||||
print_result(&word, etd->address, etd->address);
|
|
||||||
|
|
||||||
sprintf(pstring, "\n writing " _GREEN_("ok "));
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
if (pwd_given) {
|
|
||||||
|
|
||||||
if (login) {
|
|
||||||
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
|
||||||
etd->password[0], etd->password[1],
|
|
||||||
etd->password[2], etd->password[3]);
|
|
||||||
strcat(string, pstring);
|
|
||||||
} else {
|
|
||||||
sprintf(pstring, "(login failed)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (login) {
|
||||||
|
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
||||||
|
etd->password[0], etd->password[1],
|
||||||
|
etd->password[2], etd->password[3]);
|
||||||
|
strcat(string, pstring);
|
||||||
} else {
|
} else {
|
||||||
sprintf(pstring, "(no login)");
|
sprintf(pstring, "(login failed)");
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
sprintf(pstring, "(no login)");
|
||||||
|
strcat(string, pstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||||
|
@ -551,15 +549,19 @@ int CmdEM4x50Write(const char *Cmd) {
|
||||||
SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd));
|
SendCommandNG(CMD_LF_EM4X50_WRITE, (uint8_t *)&etd, sizeof(etd));
|
||||||
|
|
||||||
|
|
||||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get, prepare and print response
|
|
||||||
print_write_result(&resp, &etd);
|
|
||||||
|
|
||||||
success = (resp.status & STATUS_SUCCESS) >> 1;
|
success = (resp.status & STATUS_SUCCESS) >> 1;
|
||||||
|
|
||||||
|
// get, prepare and print response
|
||||||
|
if (success)
|
||||||
|
print_write_result(&resp, &etd);
|
||||||
|
else
|
||||||
|
PrintAndLogEx(NORMAL,"\nwriting " _RED_("failed") "\n");
|
||||||
|
|
||||||
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,19 +569,10 @@ static void print_write_password_result(PacketResponseNG *resp, const em4x50_dat
|
||||||
|
|
||||||
// display result of password changing operation
|
// display result of password changing operation
|
||||||
|
|
||||||
bool success = resp->status;
|
|
||||||
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
||||||
|
|
||||||
if (!success) {
|
sprintf(pstring, "\n writing new password " _GREEN_("ok"));
|
||||||
|
strcat(string, pstring);
|
||||||
sprintf(pstring, "\n writing new password " _RED_("failed"));
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
sprintf(pstring, "\n writing new password " _GREEN_("ok"));
|
|
||||||
strcat(string, pstring);
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||||
}
|
}
|
||||||
|
@ -588,7 +581,7 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
||||||
|
|
||||||
// envokes changing the password of EM4x50 tag
|
// envokes changing the password of EM4x50 tag
|
||||||
|
|
||||||
bool errors = false, bpwd = false, bnpwd = false;
|
bool errors = false, bpwd = false, bnpwd = false, success = false;
|
||||||
uint8_t cmdp = 0;
|
uint8_t cmdp = 0;
|
||||||
em4x50_data_t etd;
|
em4x50_data_t etd;
|
||||||
PacketResponseNG resp;
|
PacketResponseNG resp;
|
||||||
|
@ -636,71 +629,69 @@ int CmdEM4x50WritePassword(const char *Cmd) {
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_LF_EM4X50_WRITE_PASSWORD, (uint8_t *)&etd, sizeof(etd));
|
SendCommandNG(CMD_LF_EM4X50_WRITE_PASSWORD, (uint8_t *)&etd, sizeof(etd));
|
||||||
|
|
||||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
success = (bool)resp.status;
|
||||||
|
|
||||||
// get, prepare and print response
|
// get, prepare and print response
|
||||||
print_write_password_result(&resp, &etd);
|
if (success)
|
||||||
|
print_write_password_result(&resp, &etd);
|
||||||
|
else
|
||||||
|
PrintAndLogEx(NORMAL,"\nwriting password " _RED_("failed") "\n");
|
||||||
|
|
||||||
return ((bool)resp.status) ? PM3_SUCCESS : PM3_ESOFT;
|
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd) {
|
static void print_read_result(PacketResponseNG *resp, const em4x50_data_t *etd, bool verbose) {
|
||||||
|
|
||||||
// display result of writing operation in structured format
|
// display result of writing operation in structured format
|
||||||
|
|
||||||
bool addr_given = etd->addr_given;
|
bool addr_given = etd->addr_given;
|
||||||
bool pwd_given = etd->pwd_given;
|
bool pwd_given = etd->pwd_given;
|
||||||
bool login = resp->status & STATUS_LOGIN;
|
bool login = resp->status & STATUS_LOGIN;
|
||||||
bool success = (resp->status & STATUS_SUCCESS) >> 1;
|
|
||||||
int now = (resp->status & STATUS_NO_WORDS) >> 2;
|
int now = (resp->status & STATUS_NO_WORDS) >> 2;
|
||||||
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
char string[NO_CHARS_MAX] = {0}, pstring[NO_CHARS_MAX] = {0};
|
||||||
uint8_t *data = resp->data.asBytes;
|
uint8_t *data = resp->data.asBytes;
|
||||||
em4x50_word_t word;
|
em4x50_word_t word;
|
||||||
|
|
||||||
if (!success) {
|
if (addr_given) {
|
||||||
|
|
||||||
sprintf(pstring, "\n reading " _RED_("failed"));
|
// selective read mode
|
||||||
|
|
||||||
|
prepare_result(data, etd->address, etd->address, &word);
|
||||||
|
print_result(&word, etd->address, etd->address, true);
|
||||||
|
|
||||||
|
string[0] = '\0';
|
||||||
|
sprintf(pstring, "\n reading " _GREEN_("ok "));
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
|
|
||||||
|
if (pwd_given) {
|
||||||
|
if (login) {
|
||||||
|
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
||||||
|
etd->password[0], etd->password[1],
|
||||||
|
etd->password[2], etd->password[3]);
|
||||||
|
strcat(string, pstring);
|
||||||
|
} else {
|
||||||
|
sprintf(pstring, "(login failed)");
|
||||||
|
strcat(string, pstring);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sprintf(pstring, "(no login)");
|
||||||
|
strcat(string, pstring);
|
||||||
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (addr_given) {
|
//standard read mode
|
||||||
|
|
||||||
// selective read mode
|
prepare_result(data, 0, now - 1, &word);
|
||||||
|
print_result(&word, 0, now - 1, verbose);
|
||||||
|
|
||||||
prepare_result(data, etd->address, etd->address, &word);
|
if (verbose) {
|
||||||
print_result(&word, etd->address, etd->address);
|
|
||||||
|
|
||||||
string[0] = '\0';
|
|
||||||
sprintf(pstring, "\n reading " _GREEN_("ok "));
|
|
||||||
strcat(string, pstring);
|
|
||||||
|
|
||||||
if (pwd_given) {
|
|
||||||
if (login) {
|
|
||||||
sprintf(pstring, "(login with password 0x%02x%02x%02x%02x)",
|
|
||||||
etd->password[0], etd->password[1],
|
|
||||||
etd->password[2], etd->password[3]);
|
|
||||||
strcat(string, pstring);
|
|
||||||
} else {
|
|
||||||
sprintf(pstring, "(login failed)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sprintf(pstring, "(no login)");
|
|
||||||
strcat(string, pstring);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
//standard read mode
|
|
||||||
|
|
||||||
prepare_result(data, 0, now - 1, &word);
|
|
||||||
print_result(&word, 0, now - 1);
|
|
||||||
|
|
||||||
string[0] = '\0';
|
string[0] = '\0';
|
||||||
sprintf(pstring, "\n reading " _GREEN_("ok "));
|
sprintf(pstring, "\n reading " _GREEN_("ok "));
|
||||||
|
@ -713,13 +704,13 @@ static void print_sread_result(PacketResponseNG *resp, const em4x50_data_t *etd)
|
||||||
sprintf(pstring, "(standard read mode)");
|
sprintf(pstring, "(standard read mode)");
|
||||||
strcat(string, pstring);
|
strcat(string, pstring);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL,"%s\n", string);
|
PrintAndLogEx(NORMAL,"%s\n", string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdEM4x50SRead(const char *Cmd) {
|
int EM4x50Read(const char *Cmd, bool verbose) {
|
||||||
|
|
||||||
// envoke reading
|
// envoke reading
|
||||||
// - without option -> standard read mode
|
// - without option -> standard read mode
|
||||||
|
@ -735,55 +726,74 @@ int CmdEM4x50SRead(const char *Cmd) {
|
||||||
etd.pwd_given = false;
|
etd.pwd_given = false;
|
||||||
etd.addr_given = false;
|
etd.addr_given = false;
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
if (verbose) {
|
||||||
|
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
||||||
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
switch (tolower(param_getchar(Cmd, cmdp))) {
|
||||||
case 'h':
|
case 'h':
|
||||||
return usage_lf_em4x50_sread();
|
return usage_lf_em4x50_read();
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
if (param_gethex(Cmd, cmdp + 1, etd.password, 8)) {
|
||||||
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
PrintAndLogEx(FAILED, "\n password has to be 8 hex symbols\n");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
etd.pwd_given = true;
|
etd.pwd_given = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
param_getdec(Cmd, cmdp + 1, &etd.address);
|
param_getdec(Cmd, cmdp + 1, &etd.address);
|
||||||
|
|
||||||
// validation
|
// validation
|
||||||
if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) {
|
if (etd.address <= 0 || etd.address >= EM4X50_NO_WORDS) {
|
||||||
PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n");
|
PrintAndLogEx(FAILED, "\n error, address has to be in range [1-33]\n");
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
etd.addr_given = true;
|
etd.addr_given = true;
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
PrintAndLogEx(WARNING, "\n Unknown parameter '%c'\n", param_getchar(Cmd, cmdp));
|
||||||
errors = true;
|
errors = true;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errors)
|
||||||
|
return usage_lf_em4x50_read();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors)
|
|
||||||
return usage_lf_em4x50_sread();
|
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_LF_EM4X50_SREAD, (uint8_t *)&etd, sizeof(etd));
|
SendCommandNG(CMD_LF_EM4X50_READ, (uint8_t *)&etd, sizeof(etd));
|
||||||
|
|
||||||
|
|
||||||
if (!WaitForResponse(CMD_ACK, &resp)) {
|
if (!WaitForResponseTimeout(CMD_ACK, &resp, TIMEOUT)) {
|
||||||
PrintAndLogEx(WARNING, "\n timeout while waiting for reply.\n");
|
PrintAndLogEx(WARNING, "timeout while waiting for reply.");
|
||||||
return PM3_ETIMEOUT;
|
return PM3_ETIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get, prepare and print response
|
|
||||||
print_sread_result(&resp, &etd);
|
|
||||||
|
|
||||||
success = (resp.status & STATUS_SUCCESS) >> 1;
|
success = (resp.status & STATUS_SUCCESS) >> 1;
|
||||||
|
|
||||||
|
// get, prepare and print response
|
||||||
|
if (success)
|
||||||
|
print_read_result(&resp, &etd, verbose);
|
||||||
|
else if (verbose)
|
||||||
|
PrintAndLogEx(NORMAL,"\nreading " _RED_("failed") "\n");
|
||||||
|
|
||||||
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
return (success) ? PM3_SUCCESS : PM3_ESOFT;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CmdEM4x50Read(const char *Cmd) {
|
||||||
|
|
||||||
|
// envoke reading function
|
||||||
|
// verbose = true for manual call
|
||||||
|
// verbose = false for automatic call (e.g. lf search)
|
||||||
|
|
||||||
|
bool verbose = true;
|
||||||
|
|
||||||
|
return EM4x50Read(Cmd, verbose);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue