This commit is contained in:
iceman1001 2020-10-15 23:54:18 +02:00
commit 275986e743

View file

@ -1680,8 +1680,10 @@ static int unlock_write_protect(bool use_pwd, uint32_t pwd, uint32_t data, bool
return status; return status;
} }
static int unlock_reset(bool use_pwd, uint32_t pwd, uint32_t data) { static int unlock_reset(bool use_pwd, uint32_t pwd, uint32_t data, bool verbose) {
if (verbose)
PrintAndLogEx(INFO, "resetting the " _RED_("active") " lock block"); PrintAndLogEx(INFO, "resetting the " _RED_("active") " lock block");
return unlock_write_protect(use_pwd, pwd, data, false); return unlock_write_protect(use_pwd, pwd, data, false);
} }
@ -1791,7 +1793,10 @@ static int CmdEM4x05Unlock(const char *Cmd) {
PrintAndLogEx(INFO, " write value [ " _GREEN_("%08X") " ]", write_value); PrintAndLogEx(INFO, " write value [ " _GREEN_("%08X") " ]", write_value);
PrintAndLogEx(INFO, "----------------------------------------------------------------------------\n"); PrintAndLogEx(INFO, "----------------------------------------------------------------------------\n");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "press " _YELLOW_("'enter'") " to cancel the command"); PrintAndLogEx(INFO, "press " _YELLOW_("'enter'") " to cancel the command");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--------------- " _CYAN_("start") " -----------------------\n");
int exit_code = PM3_SUCCESS; int exit_code = PM3_SUCCESS;
uint32_t word14 = 0, word15 = 0; uint32_t word14 = 0, word15 = 0;
@ -1833,20 +1838,11 @@ static int CmdEM4x05Unlock(const char *Cmd) {
late = 0; late = 0;
} }
if (is_cancelled()) { if (is_cancelled()) {
exit_code = PM3_EOPABORTED; exit_code = PM3_EOPABORTED;
break; break;
} }
/*
if ( start != prev_delay) {
PrintAndLogEx(INFO, "Tear-off delay hook configured => " _GREEN_("%.0lf us"), start);
prev_delay = start;
}
*/
// set tear off trigger // set tear off trigger
clearCommandBuffer(); clearCommandBuffer();
tearoff_params_t params = { tearoff_params_t params = {
@ -1857,7 +1853,7 @@ static int CmdEM4x05Unlock(const char *Cmd) {
res = handle_tearoff(&params, verbose); res = handle_tearoff(&params, verbose);
if ( res != PM3_SUCCESS ) { if ( res != PM3_SUCCESS ) {
PrintAndLogEx(WARNING, "failed to configure tear off"); PrintAndLogEx(WARNING, "failed to configure tear off");
return PM3_EOPABORTED; return PM3_ESOFT;
} }
// write // write
@ -1865,18 +1861,16 @@ static int CmdEM4x05Unlock(const char *Cmd) {
// read after trigger // read after trigger
res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14); res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14);
if (res == PM3_SUCCESS) { if (res != PM3_SUCCESS) {
//PrintAndLogEx(INFO, "14 after [ " _GREEN_("%08X") " ]", word14); PrintAndLogEx(WARNING, "failed to read 14");
} else { return PM3_ESOFT;
break;
} }
// read after trigger // read after trigger
res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15); res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15);
if (res == PM3_SUCCESS) { if (res != PM3_SUCCESS) {
//PrintAndLogEx(INFO, "15 after [ " _GREEN_("%08X") " ]", word15); PrintAndLogEx(WARNING, "failed to read 15");
} else { return PM3_ESOFT;
break;
} }
if (verbose) if (verbose)
@ -1905,31 +1899,40 @@ static int CmdEM4x05Unlock(const char *Cmd) {
PrintAndLogEx(INFO, "Status: 15 ok, 14 partially erased => " _GREEN_("tearing too late")); PrintAndLogEx(INFO, "Status: 15 ok, 14 partially erased => " _GREEN_("tearing too late"));
} }
} }
unlock_reset(use_pwd, pwd, write_value);
unlock_reset(use_pwd, pwd, write_value, verbose);
uint32_t word14b = 0, word15b = 0; uint32_t word14b = 0, word15b = 0;
// read after reset // read after reset
res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b); res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
break; PrintAndLogEx(WARNING, "failed to read 14");
return PM3_ESOFT;
} }
if (word14b == 0) { if (word14b == 0) {
unlock_reset(use_pwd, pwd, write_value);
unlock_reset(use_pwd, pwd, write_value, verbose);
res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b); res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b);
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
break; PrintAndLogEx(WARNING, "failed to read 14");
return PM3_ESOFT;
} }
} }
if (word14b != search_value) { if (word14b != search_value) {
// read after reset
res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15b); res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15b);
if (res == PM3_SUCCESS) { if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, "Status: new definitive value! => " _RED_("SUCCESS:") " 14: " _CYAN_("%08X") " 15: %08X", word14b, word15b); PrintAndLogEx(INFO, "Status: new definitive value! => " _RED_("SUCCESS:") " 14: " _CYAN_("%08X") " 15: %08X", word14b, word15b);
success = true; success = true;
}
break; break;
} else {
PrintAndLogEx(WARNING, "failed to read 15");
return PM3_ESOFT;
}
} }
if (my_auto) { if (my_auto) {
end = start; end = start;
@ -1947,18 +1950,20 @@ static int CmdEM4x05Unlock(const char *Cmd) {
PrintAndLogEx(INFO, "Status: 15 bitflipped and active => " _RED_("SUCCESS?: ") "14: %08X 15: " _CYAN_("%08X"), word14, word15); PrintAndLogEx(INFO, "Status: 15 bitflipped and active => " _RED_("SUCCESS?: ") "14: %08X 15: " _CYAN_("%08X"), word14, word15);
PrintAndLogEx(INFO, "Committing results..."); PrintAndLogEx(INFO, "Committing results...");
unlock_reset(use_pwd, pwd, write_value); unlock_reset(use_pwd, pwd, write_value, verbose);
uint32_t word14b = 0, word15b = 0; uint32_t word14b = 0, word15b = 0;
// read after reset // read after reset
res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b); res = EM4x05ReadWord_ext(14, pwd, use_pwd, &word14b);
if ( res != PM3_SUCCESS ) { if ( res != PM3_SUCCESS ) {
PrintAndLogEx(WARNING, "failed to read 14"); PrintAndLogEx(WARNING, "failed to read 14");
return PM3_EOPABORTED; return PM3_ESOFT;
} }
res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15b); res = EM4x05ReadWord_ext(15, pwd, use_pwd, &word15b);
if ( res != PM3_SUCCESS ) { if ( res != PM3_SUCCESS ) {
PrintAndLogEx(WARNING, "failed to read 15"); PrintAndLogEx(WARNING, "failed to read 15");
return PM3_EOPABORTED; return PM3_ESOFT;
} }
if (verbose) if (verbose)