0

I have wrote a program in C++ and I built it as a DLL. I want to utilize functions that are in this DLL in another program to overwrite other functions. Unfortunately, they're not any exports and cannot be added to the imports table. Not only that I have functions that I would like to be able to jmp to and utilize and then return.

Did I perhaps build this incorrectly ?

I have the source so I can make changes in VSC++ although, I can would preferable like to do this in ASM.

I have thought about calling LoadLibrary() but that I believe will put the DLL in a random location and making patches to this will be a bit difficult, if I am not mistaken.

Let me know your ideas on how I can solve this.

2
  • 1
    why can't you make them exports? and you could just use loadlibrary -> patch at base returned + displacment.. ie:base address may vary, but the relative address to the base shouldnt Commented Sep 22, 2014 at 20:26
  • 1
    LoadLibrary returns address as handle to the dll's location and you just do math everytime before doing patchs. There is a work around if you can't edit the imports of the program you can hijack one of the dll's the program loads normally and proxy every call to the original dll file (There's tools for this too :P) The functions you won't use you can use those for your program's special functions, remember a DLL file will always load first if it's next to the program then it will start loading from windows/system32 whatever. Which makes making proxy dll's pretty clean alternative. Commented Sep 23, 2014 at 4:39

1 Answer 1

1

The most efficient and easiest way is to export the functionality using dllexport in C++.

Any other way is rewriting the functionality of windows APIs which defeats point of writing an 'efficient' way to extend the functionality.

You thought about doing what with LoadLibrary? You know that LoadLibrary returns the base address of where it's loaded? Or you could even use GetModuleHandle to get the base. So, it's easy enough to do Base + Offset

If this doesn't answer your question then you can elaborate why you can't use dllexport?

Edit: Inside your dll add the code:

__declspec(dllexport) void __stdcall ShowMessageBox( ) { MessageBoxA( 0, "HelloWorld from exported function!", "", MB_OK ); } 

Inside your exe add the code:

#pragma comment(lib, "TheFullPathToYourOutputDirOrUseRelaltive\\Bla.lib") __declspec(dllimport) void __stdcall ShowMessageBox( ); 

The lib file will be generated in the output directory of your dll. This is only required for build and isn't required for distribution to your end-users.

Finally call our function ShowMessageBox( );.

1
  • I am currently using the Base + Offset for my fix. Can you provide an example of using dllexport in c++ . I am fairly new to C++ and mainly use ASM. Commented Sep 23, 2014 at 18:36

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.