Deassembling memory function on Windows in C/C++
I use MSVC 2008.
Let's say I have a function in my code:
int foo()
{
return 2 + 5;
}
What tools can I use to obtain ASCII representation of开发者_如何学C this routine in X86 assembler?
void bar()
{
std::string s = disassemble(foo);
printf("%s\n", s.c_str());
}
You can use the marvelous BEAEngine library.
You can output the assembly code by clicking Project->properties->C++->Assembly output and then choose your preference, the assembly file will be created next time you build.
You can also view the assembly code while debugging(at a breakpoint) by pressing ctrl+Alt+D.
This obviously assumes you are on an x86 machine to get x86 assembly.
Ensure that file is part of a project. Go to Project properties -> Configuration Properties -> C/C++ -> Output Files, and then under "Assembler output", select something other than "no listing". Then when you compile you'll get a .asm file if you specified assembly only, or a .lst file if you specified a listing file. Whichever you've selected will hold the generated assembly code from your file (though, as a warning, the code for the parts you wrote will often be almost buried under a mountain of other mishmash from standard libraries and such.
精彩评论