简体   繁体   English

如何从丢失的源代码中恢复?

[英]How to recover from lost source code?

I have a one-function DLL that exports GetHash().我有一个导出 GetHash() 的单功能 DLL。 However, the source code for this DLL is lost.但是,此 DLL 的源代码丢失了。 I need to integrate this code into my MSVC++ project.我需要将此代码集成到我的 MSVC++ 项目中。

I know that there are some shareware tools for doing this, but I think that I can do it manually.我知道有一些共享软件工具可以做到这一点,但我认为我可以手动完成。

What do I need to do, to accomplish this manually?我需要做什么才能手动完成此操作?

In a project that you build, reference the dll and call the hash function.在您构建的项目中,引用 dll 并调用 hash function。 Run the code in the debugger and step in and disassemble the function and translate it back into a high level language.在调试器中运行代码并单步执行并反汇编 function 并将其翻译回高级语言。

If this isn't good enough, disassemble code into a series of functions you can implement with ASM blocks.如果这还不够好,请将代码反汇编成一系列可以用 ASM 块实现的函数。

Do you have a LIB file for the DLL?你有 DLL 的 LIB 文件吗? AH(eader) file? AH(前导)文件? Both are needed to link statically, which is the simplest way.两者都需要静态链接,这是最简单的方法。

Otherwise, the easiest route is probably just to link it dynamically.否则,最简单的路线可能只是动态链接它。 (Unless this is a COM DLL -- does you have to RegSvr32 it? If so, you can reference it and call it COM-style.) In order to do so, you use the LoadLibrary () and GetProcAddress () to obtain a function pointer. (除非这是一个 COM DLL - 你必须 RegSvr32 吗?如果是,你可以引用它并称之为 COM 样式。)为此,你使用LoadLibrary () 和GetProcAddress () 来获得一个function 指针。 And here's where things get tricky: what calling convention does the function use, what parameters, and what return type?这就是事情变得棘手的地方:function 使用什么调用约定,什么参数,什么返回类型? If you have those, you can define an appropriate function pointer type (eg "int fphasher*(char *)").如果你有这些,你可以定义一个合适的 function 指针类型(例如“int fphasher*(char *)”)。 Otherwise, prepare for a lot of amusing experimentation or even disassembly listing to get things right...否则,准备进行大量有趣的实验甚至反汇编列表以使事情正确...

A DLL viewer like DllExportViewer can help with getting the function name right, and get some hints whether C++ or C style calling conventions should be used. A DLL viewer like DllExportViewer can help with getting the function name right, and get some hints whether C++ or C style calling conventions should be used. Caveat: I haven't tested this particular version.警告:我没有测试过这个特定的版本。

I think another avenue would be to disassemble the DLL and recover the original source code.我认为另一种方法是反汇编 DLL 并恢复原始源代码。 You are then able to integrate the code into your code base and manage it better.然后,您可以将代码集成到您的代码库中并更好地管理它。

This would likely be a longer term solution to this problem.这可能是这个问题的长期解决方案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM