简体   繁体   English

从可执行文件中提取静态链接库

[英]Extract statically linked libraries from an executable

I'm not sure if this is even possible, but given an executable file (foo.exe), with has many libraries which has been linked statically. 我不确定这是否可行,但给定一个可执行文件(foo.exe),有许多已静态链接的库。

Is there any software that extract from this file the .lib ( or .a ) that lay inside the executable ? 是否有任何软件从该文件中提取可执行文件中的.lib(或.a)?

Thanks. 谢谢。

Incredibly unlikely since, typically, you don't get the entire contents of the library injected into your executable. 不可思议的是,通常情况下,您不会将库的全部内容注入到可执行文件中。

You only get enough to satisfy all the undefined symbols. 您只能满足所有未定义的符号。 This may actually only be a small proportion of the library. 这实际上可能只是图书馆的一小部分。 A library generally consists of a set of object files of which only those that are required are linked into your executable. 库通常由一组目标文件组成,只有那些目标文件才链接到您的可执行文件中。

For example, if the only thing you called in the C runtime library was exit() , you would be very unlikely to have the printf() family of functions in your executable. 例如,如果您在C运行时库中调用的唯一东西是exit() ,那么您的可执行文件中不太可能有printf()系列函数。

If you linked with the object files directly, you may have a chance, since they would be included whether used or not (unless your linker is a smart one). 如果直接链接到目标文件,则可能有机会,因为无论是否使用它们都将被包括在内(除非您的链接器是智能链接器)。

But even that would be a Herculean task as there may be no information in the executable as to what code sections came from specific object files. 但即使这样也是一项艰巨的任务,因为可执行文件中可能没有关于哪些代码段来自特定目标文件的信息。 It's potentially doable but, if there's another way, I'd be looking at that first. 这可能是可行的,但是,如果有另一种方式,我会先看一下。

Let me clarify the typical process: 让我澄清一下典型的过程:

  1. Four object files, ao , bo , co and do contain the functions a() , b() , c() and d() respectively. 四个目标文件aobocodo包含函数a()b()c()d() They are all added to the abcd.a archive. 他们加入到abcd.a存档。
  2. They are all standalone (no dependencies) except for the fact that b() calls c() . 它们都是独立的(没有依赖项),除了b()调用c()的事实。
  3. You have a main program which calls a() and b() and you compile it then link it with the abcd.a library. 你有一个调用a()b()abcd.a ,然后编译它然后用abcd.a库链接它。
  4. The linker drags ao and bo out of the library and into your executable, satisfying the need for a() and b() but introducing a need for c() , because b() needs it. 链接器将aobo拖出库并进入你的可执行文件,满足了对a()b()的需要,但引入了对c() b()需求,因为b()需要它。
  5. The linker then drags co out of the library and into your executable, satisfying the need for c() . 然后链接器将co拖出库并进入可执行文件,满足c()的需要。 Now all undefined symbols are satisfied, the executable is done and dusted, you can run it when ready. 现在所有未定义的符号都已满足,可执行文件已完成并且已粉碎,您可以在准备好后运行它。

At no stage in that process was do dragged into your executable so you have zero hope of getting it out. 在该过程的任何阶段do拖入你的可执行文件,所以你必须为零希望得到它的。

Update: Re the "if there's another way, I'd be looking at that first" comment I made above, you have just stated in a comment to one of the other answers that you have the source code that made the libraries you want extracted. 更新:重新“如果有另一种方式,我将首先看一下”我在上面做出的评论,你刚刚在其他答案的评论中说明你有源代码使你想要提取的库。 I need to ask: why can you not rebuild the libraries with that source? 我需要问一下:为什么你不能用这个源重建库? That seems to me a much easier solution than trying to recreate the libraries from a morass of executable code. 在我看来,这比尝试从可执行代码的混乱中重新创建库要容易得多。

Imagine having 10 books in language you don't understand, without covers, title pages, page numbers and chapters. 想象一下,有10本你不懂的语言书,没有封面,标题页,页码和章节。 Some of the books can be incomplete. 有些书可能不完整。 All pages are shuffled together so it is impossible to find out where is the beginning and end of each book.(each page is a function call) Now try to find page 123 of book 5 (let's say it is mentioned above function Exit()). 所有页面都被混合在一起,因此无法找出每本书的开头和结尾。(每个页面都是一个函数调用)现在尝试查找第5册的第123页(比如上面提到的函数Exit() )。

Well, IT IS possible... 嗯,有可能......

It seems like you're asking for a decompiler. 好像你要求反编译器。 Such tools are difficult to use (probably impossible for mildly sophisticated C++) and if there is any other way of solving your problem, including taking a couple months to rewrite the libraries, I'd recommend that course of action. 这些工具很难使用(对于稍微复杂的C ++来说可能是不可能的),如果有任何其他方法可以解决您的问题,包括花几个月时间重写库,我建议采取行动。

Like pax pointed out, even if you did use a decompiler, you would only get the library functions that the executable called. 就像pax指出的那样,即使您使用了反编译器,您也只能获得可执行文件所调用的库函数。

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

相关问题 为什么我的可执行文件的.dynstr包含静态链接库中的符号? - Why does my executable's .dynstr contain symbols from statically linked libraries? 静态链接的可执行文件需要 dll - Statically linked executable requires dll 从静态链接库中删除未引用的全局变量 - Remove unreferenced global variables from statically linked libraries 从静态链接的C ++库中抛出异常是不安全的? - Unsafe to throw exceptions from statically linked C++ libraries? 在构建我的 C++ 可执行文件 (gcc) 时,我可以获得所有链接库的报告吗? (包括静态链接) - Can I get a report of ALL the libraries linked when building my C++ executable (gcc)? (including statically linked) 减少与opencv静态链接的可执行文件的大小 - decreasing the size of executable which is statically linked with opencv 静态链接库是否需要与其依赖项链接? - Do statically linked libraries require linking with their dependencies? 是否可以在C / C ++的其他库中包含静态链接的库? - Is it possible to include statically linked libraries in other libraries in C/C++? 将动态链接库合并为一个静态链接库 - Combine Dynamically Linked Libraries into one Statically Linked Library 静态链接的 libcurl 是否仍然使用动态链接的库? - Does a statically linked libcurl still use dynamically linked libraries?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM