39

Is any possiblility to save some buffer in any binary file, to view in standalone hex editor.

For example, can I save data from memory window in VS to hex dump, but not as ASCII ?

StNickolay
  • 950
  • 2
  • 9
  • 21

6 Answers6

10

StNickolay has the answer that references some tool called "dumper" but, somehow, I was unable to find it around the net (also, user142207 is long gone). So I created the very same tool - it opens up running process (even with a debugger attached) and copies portion of its memory into the file. Very useful when you want to store some structure for later and don't want to struggle with VS Memory View "copy" output. Enjoy!

https://github.com/Alexx999/Dumper

10

user142207 has done a great job investigating VS internals, I recommend that solution. I have another way that was invented by my colleague, Sergey S., which is very useful:

Windows: Use a couple of functions ReadProcessMemory/WriteProcessMemory. It needs a standalone app that calls these functions with a target process id like:

dumper.exe <debugged process id> <memory_start_addr> <memory_length>

This app can be called directly during the VS debug session(compared to Linux, which doesn't have such a possibility). We can capture the memory address in the watch window, then pass the address to the dumper and voila. As user142207 says in his article, it's very useful in long-time recompiled projects.

Linux/MacOS has different approaches. For example: from the gdb console, use command dump memory. This command can also be used directly during the debug session.

Dan Mandel
  • 637
  • 1
  • 8
  • 26
StNickolay
  • 950
  • 2
  • 9
  • 21
6

I don't know if this helps, but you can use WinDbg's .writemem command. It takes a filename and a memory range and dumps it (as binary) to the disk.

Sasha Goldshtein
  • 3,499
  • 22
  • 35
  • I believe WinDbg will need to attach to process, but because VS is already attached it. Only one debugger can be attached at the time, so .writemem is not accessible. See [1](http://stackoverflow.com/a/5590924/142207) and [2](http://stackoverflow.com/a/8017023/142207) for other ways. – okigan Mar 22 '12 at 17:34
  • You can indeed attach WinDbg to a process already being debugged, but you need to check the "noninvasive" box when you do, and you will find that some options aren't available and that your VS process will soon become unresponsive. :) – Curt Hagenlocher Jul 21 '12 at 00:01
  • Also GDB's command `dump memory` does it, but the question was specifically to VS, right? :Ь – Hi-Angel Dec 04 '14 at 12:23
5

There is an extension for that: https://marketplace.visualstudio.com/items?itemName=OvidiuIonescu.VSDebugTool. It opens its console in VisualStudio window and allows dumping memory to file and a couple of other memory operation (enter "help" in the console for details).

Also, some hex editors (e.g. Hex Editor Neo) can browse process memory as an ordinary file. Maybe you'll find a free editor with this feature too.

Steed
  • 1,292
  • 1
  • 14
  • 33
  • 1
    in vs 2019 the extension is named VSDebugPro (example of usage: dumpmem c:\dump.bin 0x000002257e46c00c 408942 ) – mojmir Jun 08 '21 at 18:20
2

The watch window in the Visual Studio debugger can run functions, if you are debugging your own code, you can just add some function to your code for saving a buffer to file and call it from the watch window. for example:

void WriteToFile(char* name, void* buffer, size_t size)
{
    FILE* fp;
    fopen_s(&fp, name, "wb");
    fwrite(buffer, 1, size, fp);
    fclose(fp);
}

Then just type something like this in the watch window:

WriteToFile("c:\\temp\\dump.dat", buffer, len)
erankor
  • 21
  • 1
0

I suspect that you can get what you want from the ClrMD, you can then same the data however you want.

If you literally want a core dump then WinDbg might be what you're looking for?

There is also this post on MSDN Blogs: https://blogs.msdn.microsoft.com/dondu/2010/10/24/writing-minidumps-in-c/

It describes how to create dump-ish things in .NET programmatically.

BanksySan
  • 27,362
  • 33
  • 117
  • 216
  • I know I can get a dump file of all available memory, but I just want to get a snippet of memory into a file while debugging without modifying the source code. – marsh Aug 02 '17 at 17:20
  • @marsh So you want Me external program to analyse the memory and save it bit by bit? – BanksySan Aug 02 '17 at 17:24
  • @marsh I'd assumed you were working in .NET, are you working with unmanaged memory though? – BanksySan Aug 02 '17 at 17:26
  • I am working in native c++. Yes I would like an external program to read a section of memory and save it. I would give it a start address and a size or a start and end address. I would have though visual studio Memory Debugger window could do this as it already displays it. – marsh Aug 02 '17 at 18:00
  • @marsh a long winded solution would be to write a VS extension to add that functionality to the window. Daft it's not there. – BanksySan Aug 02 '17 at 19:36
  • Yea I guess that is the only option, I am surprised one does not already exist. – marsh Aug 02 '17 at 21:40