简体   繁体   English

Visual Studio 2010:如何将内存打印到文本文件?

[英]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? 在Visual Studio中,有没有一种方法可以将大量内存打印到文本文件中,以便我可以搜索所需的位?

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. 在调试模式下,您可以在Visual Studio中打开“内存窗口”,复制内容,将其粘贴到文本编辑器中,然后保存到文本文件中以进行进一步分析。 From the Debug menu, choose Window / Memory / Memory 1 (2, 3, or 4, as needed). 从“调试”菜单中,选择“窗口” /“内存” /“内存1”(根据需要选择2、3或4)。 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. AAAAAAAA-内存地址(指针的内容),通常为十六进制。
BB -- Byte of memory, usually in hexadecimal. BB-内存字节,通常为十六进制。
.... -- ASCII character represented by the byte or '.' ....-由字节或'。'表示的ASCII字符 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. 正如其他人所评论的那样,您可能需要使用OS API来读取内存的受限区域,或者您的应用程序需要以系统特权运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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