简体   繁体   中英

Visual Studio 2010: How to print memory to a text file?

I am searching for a specific series of bits in memory, but I do not know the exact address. Is there a way in Visual Studio to print a large block of memory to a text file so I can run a search for the bits I am looking for?

Programmatic access to memory that has not been allocated to your program is undefined behavior. If you start reading memory at arbitrary locations, your program may crash.

In debug mode you can open the Memory Window in Visual Studio, copy the content, paste it in a text editor, and save to a text file for further analysis. From the Debug menu, choose Window / Memory / Memory 1 (2, 3, or 4, as needed). Enter the initial address of the range at the top, make a selection, and copy the data to clipboard.

Given that your program may generate faults for accessing undefined or illegal areas of memory, here is how to print from memory:

  // Assign a point to point to memory.
  uint8_t const * pointer_to_memory = (uint8_t const *) /* Put address here */;

  // Read from memory
  uint8_t byte = *pointer_to_memory;

  // Output the value
  std::cout << std::hex << byte << " ";

The common output for dumping memory is:

AAAAAAAA    BB BB BB BB BB BB BB BB   BB BB BB BB BB BB BB BB  .................

Where:
AAAAAAAA -- Address of memory (the content of your pointer), usually in hexadecimal.
BB -- Byte of memory, usually in hexadecimal.
.... -- ASCII character represented by the byte or '.' for unprintable characters.

As other people have commented, you may need to use OS APIs to read restricted areas of memory or your application needs to run with System privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM