简体   繁体   中英

How to recover from lost source code?

I have a one-function DLL that exports GetHash(). However, the source code for this DLL is lost. I need to integrate this code into my MSVC++ project.

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. Run the code in the debugger and step in and disassemble the function and translate it back into a high level language.

If this isn't good enough, disassemble code into a series of functions you can implement with ASM blocks.

Do you have a LIB file for the DLL? AH(eader) file? 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. And here's where things get tricky: what calling convention does the function use, what parameters, and what return type? If you have those, you can define an appropriate function pointer type (eg "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. Caveat: I haven't tested this particular version.

I think another avenue would be to disassemble the DLL and recover the original source code. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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