Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disassemble a .lib static library?

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.

like image 698
WileTheCoyot Avatar asked Mar 10 '14 21:03

WileTheCoyot


People also ask

How do I take apart a lib file?

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.

Is .LIB a static library?

Examples of static libraries (libraries which are statically linked) are, . a files in Linux and . lib files in Windows.

What do .LIB files contain?

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.

What are .LIB files in Windows?

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.


1 Answers

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.

like image 176
Igor Skochinsky Avatar answered Sep 24 '22 14:09

Igor Skochinsky