Adding processor flash memory reading, viewing and writing to file.
Works when the device is running either osimage or bootloader. - New memory reading command in osimage and bootloader. - Extended 'hw readmem' command with length parameter, file writing and hex viewer. - Introduced '--dumpmem' option to proxmark3 executable to support dumping from bootloader. Simple interactive examples: hw readmem -f flashdump hw readmem -l 1024 CLI example: ./pm3 --dumpmem flashdump.bin Reading from arbitrary memory ranges can be unlocked using the 'raw' option.
This commit is contained in:
1 parent
c6adda54ed
commit
e35385fde1
10 files changed
+386
-12
No files matched your search
+51
-8
@@ -633,20 +633,63 @@ static int CmdLCDReset(const char *Cmd) {
|
||||
static int CmdReadmem(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hw readmem",
|
||||
"Read memory at decimal address from ARM chip flash.",
|
||||
"hw readmem -a 10000"
|
||||
"Reads processor flash memory into a file or views on console",
|
||||
"hw readmem -f myfile -> save 512KB processor flash memory to file\n"
|
||||
"hw readmem -a 8192 -l 512 -> display 512 bytes from offset 8192\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_u64_1("a", "adr", "<dec>", "address to read"),
|
||||
arg_int0("a", "adr", "<dec>", "flash address to start reading from"),
|
||||
arg_int0("l", "len", "<dec>", "length (default 32 or 512KB)"),
|
||||
arg_str0("f", "file", "<fn>", "save to file"),
|
||||
arg_int0("c", "cols", "<dec>", "column breaks"),
|
||||
arg_lit0("r", "raw", "use raw address mode: read from anywhere, not just flash"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
uint32_t address = arg_get_u32(ctx, 1);
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
// check for -file option first to determine the output mode
|
||||
int fnlen = 0;
|
||||
char filename[FILE_PATH_SIZE] = {0};
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 3), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
bool save_to_file = fnlen > 0;
|
||||
|
||||
// default len to 512KB when saving to file, to 32 bytes when viewing on the console.
|
||||
uint32_t default_len = save_to_file ? 512*1024 : 32;
|
||||
|
||||
uint32_t address = arg_get_u32_def(ctx, 1, 0);
|
||||
uint32_t len = arg_get_u32_def(ctx, 2, default_len);
|
||||
int breaks = arg_get_int_def(ctx, 4, 32);
|
||||
bool raw = arg_get_lit(ctx, 5);
|
||||
CLIParserFree(ctx);
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_READ_MEM, (uint8_t *)&address, sizeof(address));
|
||||
|
||||
uint8_t *buffer = calloc(len, sizeof(uint8_t));
|
||||
if (!buffer) {
|
||||
PrintAndLogEx(ERR, "error, cannot allocate memory ");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
const char *flash_str = raw ? "" : " flash";
|
||||
PrintAndLogEx(INFO, "reading "_YELLOW_("%u")" bytes from processor%s memory",
|
||||
len, flash_str);
|
||||
|
||||
DeviceMemType_t type = raw ? MCU_MEM : MCU_FLASH;
|
||||
if (!GetFromDevice(type, buffer, len, address, NULL, 0, NULL, -1, true)) {
|
||||
PrintAndLogEx(FAILED, "ERROR; reading from MCU flash memory");
|
||||
free(buffer);
|
||||
return PM3_EFLASH;
|
||||
}
|
||||
|
||||
if (save_to_file) {
|
||||
PrintAndLogEx(INFO, "saving to "_YELLOW_("%s"), filename);
|
||||
saveFile(filename, ".bin", buffer, len);
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "---- " _CYAN_("processor%s memory") " ----", flash_str);
|
||||
print_hex_break(buffer, len, breaks);
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1150,7 +1193,7 @@ static command_t CommandTable[] = {
|
||||
{"lcd", CmdLCD, IfPm3Lcd, "Send command/data to LCD"},
|
||||
{"lcdreset", CmdLCDReset, IfPm3Lcd, "Hardware reset LCD"},
|
||||
{"ping", CmdPing, IfPm3Present, "Test if the Proxmark3 is responsive"},
|
||||
{"readmem", CmdReadmem, IfPm3Present, "Read memory at decimal address from flash"},
|
||||
{"readmem", CmdReadmem, IfPm3Present, "Read from processor flash"},
|
||||
{"reset", CmdReset, IfPm3Present, "Reset the Proxmark3"},
|
||||
{"setlfdivisor", CmdSetDivisor, IfPm3Present, "Drive LF antenna at 12MHz / (divisor + 1)"},
|
||||
{"setmux", CmdSetMux, IfPm3Present, "Set the ADC mux to a specific value"},
|
||||
|
||||
Reference in new issue
Block a user