mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-22 05:37:06 +00:00
Fix #2992 - Add dmpf
and dmpt
to dump/restore snapshots from/to disk
This commit is contained in:
parent
b56207ebb7
commit
a6cb6ab07d
@ -525,10 +525,63 @@ static int cmd_debug_map_snapshot(RCore *core, const char *input) {
|
||||
"dmsd", " id", "hexdiff given snapshot. See `ccc`.",
|
||||
"dmsw", "", "snapshot of the writable maps",
|
||||
"dmsa", "", "full snapshot of all `dm` maps",
|
||||
"dmsf", " [file] @ addr", "read snapshot from disk",
|
||||
"dmst", " [file] @ addr", "dump snapshot to disk",
|
||||
// TODO: dmsj - for json
|
||||
NULL
|
||||
};
|
||||
switch (*input) {
|
||||
case 'f':
|
||||
{
|
||||
char *file;
|
||||
RDebugSnap *snap;
|
||||
if (input[1] == ' ') {
|
||||
file = strdup (input+2);
|
||||
} else {
|
||||
file = r_str_newf ("0x%08"PFMT64x".dump", core->offset);
|
||||
}
|
||||
snap = r_debug_snap_get (core->dbg, core->offset);
|
||||
if (!snap) {
|
||||
r_debug_snap (core->dbg, core->offset);
|
||||
snap = r_debug_snap_get (core->dbg, core->offset);
|
||||
}
|
||||
if (snap) {
|
||||
int fsz = 0;
|
||||
char *data = r_file_slurp (file, &fsz);
|
||||
if (data) {
|
||||
if (fsz >= snap->size) {
|
||||
memcpy (snap->data, data, snap->size);
|
||||
} else {
|
||||
eprintf ("This file is smaller than the snapshot size\n");
|
||||
}
|
||||
free (data);
|
||||
} else eprintf ("Cannot slurp '%s'\n", file);
|
||||
} else {
|
||||
eprintf ("Unable to find a snapshot for 0x%08"PFMT64x"\n", core->offset);
|
||||
}
|
||||
free (file);
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
{
|
||||
char *file;
|
||||
RDebugSnap *snap;
|
||||
if (input[1] == ' ') {
|
||||
file = strdup (input+2);
|
||||
} else {
|
||||
file = r_str_newf ("0x%08"PFMT64x".dump", core->offset);
|
||||
}
|
||||
snap = r_debug_snap_get (core->dbg, core->offset);
|
||||
if (snap) {
|
||||
if (!r_file_dump (file, snap->data, snap->size, 0)) {
|
||||
eprintf ("Cannot slurp '%s'\n", file);
|
||||
}
|
||||
} else {
|
||||
eprintf ("Unable to find a snapshot for 0x%08"PFMT64x"\n", core->offset);
|
||||
}
|
||||
free (file);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
r_core_cmd_help (core, help_msg);
|
||||
break;
|
||||
|
@ -67,6 +67,17 @@ R_API void r_debug_snap_list(RDebug *dbg, int idx, int mode) {
|
||||
dbg->cb_printf ("]\n");
|
||||
}
|
||||
|
||||
R_API RDebugSnap* r_debug_snap_get (RDebug *dbg, ut64 addr) {
|
||||
RListIter *iter;
|
||||
RDebugSnap *snap;
|
||||
r_list_foreach (dbg->snaps, iter, snap) {
|
||||
if (snap->addr >= addr && snap->addr_end < addr) {
|
||||
return snap;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int r_debug_snap_map (RDebug *dbg, RDebugMap *map) {
|
||||
RDebugSnap *snap;
|
||||
if (map->size<1) {
|
||||
|
@ -423,6 +423,7 @@ R_API int r_debug_snap_diff(RDebug *dbg, int idx);
|
||||
R_API int r_debug_snap(RDebug *dbg, ut64 addr);
|
||||
R_API int r_debug_snap_comment (RDebug *dbg, int idx, const char *msg);
|
||||
R_API int r_debug_snap_all(RDebug *dbg, int perms);
|
||||
R_API RDebugSnap* r_debug_snap_get (RDebug *dbg, ut64 addr);
|
||||
|
||||
/* plugin pointers */
|
||||
extern RDebugPlugin r_debug_plugin_native;
|
||||
|
Loading…
x
Reference in New Issue
Block a user