tags:

views:

230

answers:

3

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?

+2  A: 

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.

plinth
thanks, will try it and return
Omega
+1  A: 

Do you have a LIB file for the DLL? A H(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 (e.g. "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.

Pontus Gagge
+1  A: 

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.

Gavin Miller