dumpmem (Memory Dump Utility)
Description
The dumpmem command allows you to dump memory contents from the debugged process to a file. This feature is useful for offline analysis, comparison, or backup of memory regions.
Syntax
dumpmem [options] <filename> <address> <size>
Parameters
<filename>: Path and name of the output file where memory contents will be saved.<address>: Starting address in memory to begin the dump.<size>: Number of bytes to dump from the starting address.
Options
-f: Force overwrite. Overwrites the output file if it already exists.-a: Append mode. Appends new data to the end of an existing file.
Usage Notes
- The command uses the current process context in the debugger.
- Address can be specified in various formats:
- Hexadecimal: Prefixed with ‘0x’ (e.g., 0x00656789)
- Decimal: Plain number (e.g., 6789456)
- Symbol name: If symbols are loaded (e.g., &myVariable)
- Size can use expressions for convenience (e.g., 1024*1024 for 1 MB) (must not have spaces).
- Without
-for-a, the command returns an error if the output file exists.
Examples
-
Basic usage:
dumpmem c:\temp\memdump.bin 0x00656789 200Dumps 200 bytes starting from address 0x00656789 to the file
c:\temp\memdump.bin. -
Using force overwrite:
dumpmem -f c:\temp\memdump.bin 0x00656789 200Overwrites
c:\temp\memdump.binif it already exists. -
Appending to an existing file:
dumpmem -a c:\temp\memdump.bin 0x00656789 200Appends 200 bytes to the end of
c:\temp\memdump.binif it exists. -
Using a symbol name:
dumpmem c:\temp\variable_dump.bin &myGlobalVar 256Dumps 256 bytes starting from the address of
myGlobalVar. -
Dumping a larger region:
dumpmem c:\temp\large_dump.bin 0x10000000 1024*1024Dumps 1 MB of memory starting from address 0x10000000.
Error Handling
- Invalid or inaccessible address: Displays an error message.
- Size exceeds available memory: Dumps as much as possible and reports actual bytes written.
- Output file creation/write issues: Shows appropriate error message.
Example Code and Usage
Sample code
int main()
{
// buffer size
int bufferSize = 16;
// create buffer
void* buffer = calloc(1, bufferSize);
// set some bytes into the buffer
memset(buffer, 0xAB, bufferSize);
// release memory
free(buffer);
return 0;
}
After running to the point just before free(buffer), you can use dumpmem to capture the buffer contents:
dumpmem buffer.bin buffer bufferSize
The resulting buffer.bin file will contain:
buffer.bin
AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB AB
Check these tutorials for more: