mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
Update cmdhficlass.c
This commit is contained in:
parent
047b94fbaa
commit
fbbfeaa977
1 changed files with 57 additions and 23 deletions
|
@ -3041,7 +3041,6 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
|
||||||
keyType = 0x18; //credit key
|
keyType = 0x18; //credit key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//perform initial read here, repeat if failed or 00s
|
//perform initial read here, repeat if failed or 00s
|
||||||
uint8_t data_read_orig[8] = {0};
|
uint8_t data_read_orig[8] = {0};
|
||||||
uint8_t ff_data[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
uint8_t ff_data[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
|
||||||
|
@ -3062,11 +3061,26 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
|
||||||
reread = false;
|
reread = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// turn off Device side debug messages
|
||||||
|
uint8_t dbg_curr = DBG_NONE;
|
||||||
|
if (getDeviceDebugLevel(&dbg_curr) != PM3_SUCCESS) {
|
||||||
|
return PM3_EFAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setDeviceDebugLevel(DBG_NONE, false) != PM3_SUCCESS) {
|
||||||
|
return PM3_EFAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintAndLogEx(INFO, "Starting tear off against block %u / 0x%02x", blockno, blockno);
|
||||||
|
PrintAndLogEx(INFO, "");
|
||||||
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to abort");
|
PrintAndLogEx(INFO, "Press " _GREEN_("<Enter>") " to abort");
|
||||||
|
|
||||||
while (tearoff_start <= tearoff_end && read_ok == false) {
|
while (tearoff_start <= tearoff_end && read_ok == false) {
|
||||||
|
|
||||||
if (kbd_enter_pressed()) {
|
if (kbd_enter_pressed()) {
|
||||||
PrintAndLogEx(WARNING, "\naborted via keyboard.");
|
PrintAndLogEx(WARNING, "\naborted via keyboard.");
|
||||||
return PM3_EOPABORTED;
|
isok = PM3_EOPABORTED;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set tear off trigger
|
// set tear off trigger
|
||||||
|
@ -3076,10 +3090,12 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
|
||||||
.on = true,
|
.on = true,
|
||||||
.off = false
|
.off = false
|
||||||
};
|
};
|
||||||
|
|
||||||
int res = handle_tearoff(¶ms, verbose);
|
int res = handle_tearoff(¶ms, 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_ESOFT;
|
isok = PM3_ESOFT;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write
|
// write
|
||||||
|
@ -3092,11 +3108,15 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
|
||||||
first_read = false;
|
first_read = false;
|
||||||
reread = false;
|
reread = false;
|
||||||
bool decrease = false;
|
bool decrease = false;
|
||||||
|
|
||||||
while (first_read == false) {
|
while (first_read == false) {
|
||||||
|
|
||||||
if (kbd_enter_pressed()) {
|
if (kbd_enter_pressed()) {
|
||||||
PrintAndLogEx(WARNING, "\naborted via keyboard.");
|
PrintAndLogEx(WARNING, "\naborted via keyboard.");
|
||||||
return PM3_EOPABORTED;
|
isok = PM3_EOPABORTED;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, data_read, false);
|
res = iclass_read_block_ex(key, blockno, keyType, elite, rawkey, use_replay, verbose, auth, shallow_mod, data_read, false);
|
||||||
if (res == PM3_SUCCESS && !reread) {
|
if (res == PM3_SUCCESS && !reread) {
|
||||||
if (memcmp(data_read, zeros, 8) == 0) {
|
if (memcmp(data_read, zeros, 8) == 0) {
|
||||||
|
@ -3112,50 +3132,64 @@ static int CmdHFiClass_TearBlock(const char *Cmd) {
|
||||||
decrease = true;
|
decrease = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decrease && tearoff_start > 0) { //if there was an error reading repeat the tearoff with the same delay
|
if (decrease && tearoff_start > 0) { //if there was an error reading repeat the tearoff with the same delay
|
||||||
tearoff_start -= tearoff_increment;
|
tearoff_start -= tearoff_increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tear_success = true;
|
bool tear_success = true;
|
||||||
bool expected_values = true;
|
bool expected_values = true;
|
||||||
|
|
||||||
if (memcmp(data_read, data, 8) != 0) {
|
if (memcmp(data_read, data, 8) != 0) {
|
||||||
tear_success = false;
|
tear_success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tear_success == false) && (memcmp(data_read, zeros, 8) != 0) && (memcmp(data_read, data_read_orig, 8) != 0)) { //tearoff succeeded (partially)
|
if ((tear_success == false) && (memcmp(data_read, zeros, 8) != 0) && (memcmp(data_read, data_read_orig, 8) != 0)) { //tearoff succeeded (partially)
|
||||||
|
|
||||||
expected_values = false;
|
expected_values = false;
|
||||||
|
|
||||||
if (memcmp(data_read, ff_data, 8) == 0 && memcmp(data_read_orig, ff_data, 8) != 0) {
|
if (memcmp(data_read, ff_data, 8) == 0 && memcmp(data_read_orig, ff_data, 8) != 0) {
|
||||||
erase_phase = true;
|
erase_phase = true;
|
||||||
PrintAndLogEx(SUCCESS, _BLUE_("Erase phase hit: ALL ONES"));
|
PrintAndLogEx(SUCCESS, _BLUE_("Erase phase hit: ALL ONES"));
|
||||||
PrintAndLogEx(INFO, "Original: %s", sprint_hex(data_read_orig, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Original: %s", sprint_hex_inrow(data_read_orig, sizeof(data_read)));
|
||||||
PrintAndLogEx(INFO, "Read: "_BLUE_("%s"), sprint_hex(data_read, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Read: "_BLUE_("%s"), sprint_hex_inrow(data_read, sizeof(data_read)));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (erase_phase) {
|
if (erase_phase) {
|
||||||
PrintAndLogEx(SUCCESS, _MAGENTA_("Tearing! Write Phase (post erase)"));
|
PrintAndLogEx(SUCCESS, _MAGENTA_("Tearing! Write Phase (post erase)"));
|
||||||
PrintAndLogEx(INFO, "Original: %s", sprint_hex(data_read_orig, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Original: %s", sprint_hex_inrow(data_read_orig, sizeof(data_read)));
|
||||||
PrintAndLogEx(INFO, "Read: "_CYAN_("%s"), sprint_hex(data_read, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Read: "_CYAN_("%s"), sprint_hex_inrow(data_read, sizeof(data_read)));
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(SUCCESS, _CYAN_("Tearing!(unknown phase)!"));
|
PrintAndLogEx(SUCCESS, _CYAN_("Tearing!(unknown phase)!"));
|
||||||
PrintAndLogEx(INFO, "Original: %s", sprint_hex(data_read_orig, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Original: %s", sprint_hex_inrow(data_read_orig, sizeof(data_read)));
|
||||||
PrintAndLogEx(INFO, "Read: "_CYAN_("%s"), sprint_hex(data_read, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Read: "_CYAN_("%s"), sprint_hex_inrow(data_read, sizeof(data_read)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { //tearoff did not succeed
|
} else { //tearoff did not succeed
|
||||||
PrintAndLogEx(INFO, "Read: %s", sprint_hex(data_read, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Read: %s", sprint_hex_inrow(data_read, sizeof(data_read)));
|
||||||
PrintAndLogEx(INFO, "Expected: %s", sprint_hex(data, sizeof(data)));
|
PrintAndLogEx(INFO, "Expected: %s", sprint_hex_inrow(data, sizeof(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tear_success) { //tearoff succeeded with expected values
|
if (tear_success) { //tearoff succeeded with expected values
|
||||||
read_ok = true;
|
read_ok = true;
|
||||||
tear_success = true;
|
tear_success = true;
|
||||||
if (expected_values) {
|
if (expected_values) {
|
||||||
PrintAndLogEx(SUCCESS, _GREEN_("Expected values!"));
|
PrintAndLogEx(SUCCESS, _GREEN_("Expected values!"));
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "Read: "_GREEN_("%s"), sprint_hex(data_read, sizeof(data_read)));
|
PrintAndLogEx(INFO, "Read: "_GREEN_("%s"), sprint_hex_inrow(data_read, sizeof(data_read)));
|
||||||
}
|
}
|
||||||
loop_count++;
|
loop_count++;
|
||||||
if (loop_count == tearoff_loop){
|
if (loop_count == tearoff_loop){
|
||||||
tearoff_start += tearoff_increment;
|
tearoff_start += tearoff_increment;
|
||||||
loop_count = 0;
|
loop_count = 0;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "---------------");
|
PrintAndLogEx(INFO, "--------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (setDeviceDebugLevel(verbose ? MAX(dbg_curr, DBG_INFO) : DBG_NONE, false) != PM3_SUCCESS) {
|
||||||
|
return PM3_EFAILED;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return isok;
|
return isok;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue