Solved

searching in the memory pane

Posted on 2013-11-26
6
309 Views
Last Modified: 2013-12-12
Hi

Can the memory pane in visual studio be searched for particular values? Let's say I was looking out for a value -8.000000 in column 10 starting from address 0x10AB0040. Is there a way to do this without scrolling up and down and hoping the eyes are still young enough to catch it?

thanks
0
Comment
Question by:LuckyLucks
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
VS isn't really good at that. In fact, there isn't even a 'Search' option for Memory Watch windows at all. If you need to do that, try "Quick Memory Editor" (http://download.cnet.com/Quick-Memory-Editor/3000-2121_4-10386321.html). It was created for a completely different purpose (cheating in games), but is quite good for your purpose as well.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
BTW, as a side note '-8.000000' will never be displayed like that in memory unless it's a string. Floating point values are represented in IEEE format, which is documented here: http://msdn.microsoft.com/en-us/library/vstudio/0b34tf65.aspx ("IEEE Floating-Point Representation"). How both correspond to each other is illustrated best with the code snippet from http://stackoverflow.com/questions/2404675/how-do-i-convert-from-a-decimal-number-to-ieee-754-single-precision-floating-poi - which (modified for 'double' values and more C++-like) works like

#include <iostream>
using namespace std;

typedef union
{
    long int i;
    double d;
} U;

int main(void)
{
    U u;

    u.d = -8.000000;

    cout << u.d << " = " << u.i << endl;

    return 0;
}

Open in new window

0
 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
You have a couple of options that I can find (if you are on Visual Studio 2010 Ultimate... not sure what might be different for different values).

1. Right click on the memory window and change the format of the data being displayed.  The default should be '1-byte Integer' allowing you to see the raw hex values of each memory address.

But one of the options is '64-bit Floating Point' which corresponds to a double.  Since double values should be getting aligned on 64-bit boundaries (at least they do on my 64-bit system) you can indeed see the value -8.0000 by visually scanning the memory.

2. I don't know how well this would work for formats other than '1-byte Integer', but you could open a blank file in the Visual Studio binary editor.  You could then select a section of memory from the memory window.  Then right-click in the memory window to do a 'Copy', and then go paste the values in the binary editor.  You could then do a search in the binary editor for a particular hex pattern (simply key in the string of hex values with a space between each value).

Possibly the most difficult part of this issue is getting a file openned in the binary editor.  One way to do this is to use Windows Explorer to create a new text file and name it something like "mem.bin" (replacing the default .txt extension with .bin).  Then add this bin file to your project.  It will likely get automatically added to you Resource section, but you can drag-and-drop it out to the main project level (i.e. one level above the folders the source code and header files are in).  In any case, once you have this blank file added to the project, double click the file and the .bin extension should cause it to open in the binary editor.  If it does not, right click on the file and select "Open With..." to manually select the Binary Editor to open the file with.

As I say, once you have the binary editor open in Visual Studio, you can highlight a section of memory from the memory window (even highlighting the memory addresses displayed) and Copy-n-Paste it into the binary editor and only the binary memory data will get copied from the memory window to the binary editor.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 86

Expert Comment

by:jkr
Comment Utility
... OK, HooKooDooKu, so the "Search..." option is exactly where?
0
 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
Search in the binary editor...

Well... except upon further review, it turns out that a copy-n-paste from the Memory window does NOT only copy the memory data.  It instead copies the text as shown in the Memory window.

So we need a different way to get or memory data into the binary editor.  And so far, the only way I've come up with a way to do that is rather than trying to copy from the memory window, write a function like the following:
void WriteMemory( const void* p, UINT nCount )
{
	try
	{
		CFile fout;
		BOOL b = 
			fout.Open( "C:\\BW\\Test\\CPlusPlus\\mem.bin", 
			           CFile::modeWrite | 
					   CFile::shareDenyNone |
					   CFile::modeCreate );
		if( ! b ) throw "Failed";
		fout.Write( p, nCount );
		fout.Close();
	}
	catch(...)
	{
		MessageBox( NULL, "Unable to Copy Memory to Bin file", "", 0 );
	}
}

Open in new window

where you hard code the name of YOUR binary file you've attached to the project.  You can then either call this function from code, or even call it from the Debug/Immediate window.  You just have to make sure that the size of the given nCount is within the memory space allocated to your program.
0
 

Author Closing Comment

by:LuckyLucks
Comment Utility
this provides an alternative approach, it's not exactly the one i would prefer.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now