Skip to content

Commit ba8a68f

Browse files
committed
fixes entering bootload messages to be less scary
1 parent 16b56f4 commit ba8a68f

File tree

5 files changed

+56
-24
lines changed

5 files changed

+56
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
44

55
## [unreleased][unreleased]
6+
7+
## [Backdoor][2024-09-10]
8+
- Changed flashing messages to be less scary (@iceman1001)
9+
- Fixed docker containers and their documentation (@doegox)
10+
- Fixed `hf ict` - buffer overflow (@doegox)
611
- Fixed `hf felica raw -s` - dont check crc for select tag response, thanks @RebornedBrian! (@iceman1001)
712
- Added a multi-threaded of ht2crack2search (@iceman1001)
813
- Fixed ISO14443a bounds-checking because @doegex found cards not following ISO14443a when fuzzed (@iceman1001)

armsrc/mifaresim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
763763
}
764764

765765
// all commands must have a valid CRC
766-
if (!CheckCrc14A(receivedCmd_dec, receivedCmd_len)) {
766+
if (CheckCrc14A(receivedCmd_dec, receivedCmd_len) == false) {
767767
EmSend4bit(encrypted_data ? mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA) : CARD_NACK_NA);
768768
FpgaDisableTracing();
769769

client/src/comms.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ __attribute__((force_align_arg_pointer))
428428
// Signal to main thread that communications seems off.
429429
// main thread will kill and restart this thread.
430430
if (commfailed) {
431-
if (g_conn.last_command != CMD_HARDWARE_RESET) {
431+
if (g_conn.last_command != CMD_HARDWARE_RESET &&
432+
g_conn.last_command != CMD_START_FLASH) {
432433
PrintAndLogEx(WARNING, "\nCommunicating with Proxmark3 device " _RED_("failed"));
433434
}
434435
__atomic_test_and_set(&comm_thread_dead, __ATOMIC_SEQ_CST);

client/src/flash.c

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -428,21 +428,24 @@ static int get_proxmark_state(uint32_t *state) {
428428

429429
// Enter the bootloader to be able to start flashing
430430
static int enter_bootloader(char *serial_port_name, bool wait_appear) {
431-
uint32_t state;
432-
int ret;
433431

434-
if ((ret = get_proxmark_state(&state)) != PM3_SUCCESS)
432+
uint32_t state = 0;
433+
int ret = get_proxmark_state(&state);
434+
if (ret != PM3_SUCCESS) {
435435
return ret;
436+
}
436437

437438
/* Already in flash state, we're done. */
438-
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM)
439+
if ((state & DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) == DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM) {
439440
return PM3_SUCCESS;
441+
}
440442

441-
if (state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
443+
if ((state & DEVICE_INFO_FLAG_CURRENT_MODE_OS) == DEVICE_INFO_FLAG_CURRENT_MODE_OS) {
442444
PrintAndLogEx(SUCCESS, _CYAN_("Entering bootloader..."));
443445

444-
if ((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT)
445-
&& (state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
446+
if (
447+
((state & DEVICE_INFO_FLAG_BOOTROM_PRESENT) == DEVICE_INFO_FLAG_BOOTROM_PRESENT) &&
448+
((state & DEVICE_INFO_FLAG_OSIMAGE_PRESENT) == DEVICE_INFO_FLAG_OSIMAGE_PRESENT)) {
446449
// New style handover: Send CMD_START_FLASH, which will reset the board
447450
// and enter the bootrom on the next boot.
448451
SendCommandBL(CMD_START_FLASH, 0, 0, 0, NULL, 0);
@@ -453,6 +456,7 @@ static int enter_bootloader(char *serial_port_name, bool wait_appear) {
453456
PrintAndLogEx(SUCCESS, "Press and hold down button NOW if your bootloader requires it.");
454457
}
455458
msleep(500);
459+
PrintAndLogEx(SUCCESS, _CYAN_("Trigger restart..."));
456460
CloseProxmark(g_session.current_device);
457461
// Let time to OS to make the port disappear
458462
msleep(1000);
@@ -487,8 +491,9 @@ static int wait_for_ack(PacketResponseNG *ack) {
487491

488492
static bool gs_printed_msg = false;
489493
static void flash_suggest_update_bootloader(void) {
490-
if (gs_printed_msg)
494+
if (gs_printed_msg) {
491495
return;
496+
}
492497

493498
PrintAndLogEx(ERR, _RED_("It is recommended that you first" _YELLOW_(" update your bootloader") _RED_(" alone,")));
494499
PrintAndLogEx(ERR, _RED_("reboot the Proxmark3 then only update the main firmware") "\n");
@@ -510,31 +515,36 @@ static void flash_suggest_update_flasher(void) {
510515

511516
// Go into flashing mode
512517
int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t *max_allowed) {
513-
uint32_t state;
514-
uint32_t chipinfo = 0;
515-
int ret;
516518

517-
ret = enter_bootloader(serial_port_name, true);
518-
if (ret != PM3_SUCCESS)
519+
int ret = enter_bootloader(serial_port_name, true);
520+
if (ret != PM3_SUCCESS) {
519521
return ret;
522+
}
520523

524+
uint32_t state;
521525
ret = get_proxmark_state(&state);
522-
if (ret != PM3_SUCCESS)
526+
if (ret != PM3_SUCCESS) {
523527
return ret;
528+
}
529+
530+
uint32_t chipinfo = 0;
524531

525-
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) {
532+
if ((state & DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) == DEVICE_INFO_FLAG_UNDERSTANDS_CHIP_INFO) {
526533
SendCommandBL(CMD_CHIP_INFO, 0, 0, 0, NULL, 0);
527534
PacketResponseNG resp;
528535
WaitForResponse(CMD_CHIP_INFO, &resp);
529536
chipinfo = resp.oldarg[0];
530537
}
531538

532539
int version = BL_VERSION_INVALID;
533-
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_VERSION) {
540+
541+
if ((state & DEVICE_INFO_FLAG_UNDERSTANDS_VERSION) == DEVICE_INFO_FLAG_UNDERSTANDS_VERSION) {
542+
534543
SendCommandBL(CMD_BL_VERSION, 0, 0, 0, NULL, 0);
535544
PacketResponseNG resp;
536545
WaitForResponse(CMD_BL_VERSION, &resp);
537546
version = resp.oldarg[0];
547+
538548
if ((BL_VERSION_MAJOR(version) < BL_VERSION_FIRST_MAJOR) || (BL_VERSION_MAJOR(version) > BL_VERSION_LAST_MAJOR)) {
539549
// version info seems fishy
540550
version = BL_VERSION_INVALID;
@@ -562,7 +572,9 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
562572

563573
int mem_avail = chipid_to_mem_avail(chipinfo);
564574
if (mem_avail != 0) {
575+
565576
PrintAndLogEx(INFO, "Available memory on this board: "_YELLOW_("%uK") " bytes\n", mem_avail);
577+
566578
if (mem_avail > 256) {
567579
if (BL_VERSION_MAJOR(version) < BL_VERSION_MAJOR(BL_VERSION_1_0_0)) {
568580
PrintAndLogEx(ERR, _RED_("====================== OBS ! ======================"));
@@ -573,6 +585,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
573585
*max_allowed = mem_avail;
574586
}
575587
}
588+
576589
} else {
577590
PrintAndLogEx(INFO, "Available memory on this board: "_RED_("UNKNOWN")"\n");
578591
PrintAndLogEx(ERR, _RED_("====================== OBS ! ======================================"));
@@ -585,15 +598,17 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, uint32_t
585598
} else {
586599
PrintAndLogEx(INFO, "Permitted flash range: 0x%08x-0x%08x", BOOTLOADER_END, flash_end);
587600
}
588-
if (state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
589-
PacketResponseNG resp;
601+
602+
if ((state & DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) == DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH) {
590603

591604
if (enable_bl_writes) {
592605
SendCommandBL(CMD_START_FLASH, FLASH_START, flash_end, START_FLASH_MAGIC, NULL, 0);
593606
} else {
594607
SendCommandBL(CMD_START_FLASH, BOOTLOADER_END, flash_end, 0, NULL, 0);
595608
}
609+
PacketResponseNG resp;
596610
return wait_for_ack(&resp);
611+
597612
} else {
598613
PrintAndLogEx(ERR, _RED_("====================== OBS ! ========================================"));
599614
PrintAndLogEx(ERR, _RED_("Note: Your bootloader does not understand the new" _YELLOW_(" START_FLASH") _RED_(" command")));
@@ -664,8 +679,9 @@ int flash_write(flash_file_t *ctx) {
664679

665680
while (length) {
666681
uint32_t block_size = length;
667-
if (block_size > BLOCK_SIZE)
682+
if (block_size > BLOCK_SIZE) {
668683
block_size = BLOCK_SIZE;
684+
}
669685

670686
if (write_block(baddr, data, block_size) < 0) {
671687
PrintAndLogEx(ERR, "Error writing block %d of %u", block, blocks);
@@ -676,9 +692,11 @@ int flash_write(flash_file_t *ctx) {
676692
baddr += block_size;
677693
length -= block_size;
678694
block++;
695+
679696
if (len < ice3len) {
680697
fprintf(stdout, "%c", ice3[len++]);
681698
} else {
699+
682700
if ((len - ice3len) % 67 == 0) {
683701
fprintf(stdout, "\n");
684702
}
@@ -695,21 +713,29 @@ int flash_write(flash_file_t *ctx) {
695713

696714
// free a file context
697715
void flash_free(flash_file_t *ctx) {
698-
if (!ctx)
716+
717+
if (!ctx) {
699718
return;
719+
}
720+
700721
if (ctx->filename != NULL) {
701722
free(ctx->filename);
702723
ctx->filename = NULL;
703724
}
725+
704726
if (ctx->elf) {
705727
free(ctx->elf);
706728
ctx->elf = NULL;
707729
ctx->phdrs = NULL;
708730
ctx->num_phdrs = 0;
709731
}
732+
710733
if (ctx->segments) {
711-
for (int i = 0; i < ctx->num_segs; i++)
734+
735+
for (int i = 0; i < ctx->num_segs; i++) {
712736
free(ctx->segments[i].data);
737+
}
738+
713739
free(ctx->segments);
714740
ctx->segments = NULL;
715741
ctx->num_segs = 0;

doc/commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12886,6 +12886,6 @@
1288612886
"metadata": {
1288712887
"commands_extracted": 743,
1288812888
"extracted_by": "PM3Help2JSON v1.00",
12889-
"extracted_on": "2024-09-06T20:59:05"
12889+
"extracted_on": "2024-09-10T12:26:03"
1289012890
}
1289112891
}

0 commit comments

Comments
 (0)