I have written this simple library in c:
library.h:
int sum(int a, int b);
library.c:
#include "library.h"
int sum(int a, int b) {
return a+b;
}
I compiled it with cl.exe (visual studio 2012) using these commands:
cl /c /EHsc library.cpp
lib library.obj
which compiled it as a static link .lib library file. Now I would like to have a look at how the compiler generated the assembly code, for learning/academic purposes. Please note, I don't want to decompile it, I just want to read the generated assembly. I have tried to open the .lib with w32dasm but I get a lot of strange symbols and it looks like the tool is unable to read the file. I've HAVE done a similar task with a dynamic link library (generated from the same source) and it worked; in that I was able to view the assembly code using w32dasm. So, my question is: is possible to view the assembly code of a static link library as you can do with a dynamic link library? If so, what would be the correct tool to use, since w32dasm does not appear to be the correct tool.
If you are using Visual Studio IDE you can also set a breakpoint, start debugging and then right click a source line and choose Go To Disassembly.
Examples of static libraries (libraries which are statically linked) are, . a files in Linux and . lib files in Windows.
lib file contains all the code and data for the library. The linker then identifies the bits it needs and puts them in the final executable. For a dynamic library, the . lib file contains a list of the exported functions and data elements from the library, and information about which DLL they came from.
LIB (lib.exe) creates standard libraries, import libraries, and export files you can use with LINK when building a program. LIB runs from a command prompt. You can use LIB in the following modes: Building or modifying a COFF library.
If you do want to disassemble the library instead of looking at the compiler-generated assembler, you can use the DUMPBIN
tool:
dumpbin /disasm library.lib
IDA can also handle static libraries and object files (and dozens of other file formats). Disclaimer: I work for Hex-Rays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With