Monday, January 14, 2013

Saturday, January 5, 2013

The way to load different version DLL on the same process

The way to load different version DLL on the same process


Problem

App need to load version1: v.dll and version 2: v.dll at the same time. and these two lib have the same file name, but different export API. the v.dll export as symbol, App need to v.dll with Load Time dynamic linking.



Load Time dynamic linking: Module makes explicit calls to exported DLL function and it looks like as if the function located locally. This required you to link a .lib file which is generated during the creation of DLL. This import library supplies all the information to load a DLL and locate the exported function when application is loaded. When we launch an application it loads all DLL’s which during loading of application, if Loader fails to locate a DLL, it will display error message saying “unable to locate DLL” and then stops launching application.
Run-time dynamic linking: To use this method we need to know prototype of a function and we can load any specific DLL using LoadLibrary() function. Once we load a DLL we get a handle to use for getting address of a function in memory and use it. To get address of a function we have to use GetProcAddress() function. FreeLibrary () function is used to unload DLL from memory.
http://www.ksyash.com/2011/01/dll-internals/


Solution:
So to load the same DLL at the same time, 
  • create two wrapper dll, these wrapper can be loaded by App by  explicitly LoadLibrary().
  • modify the import table of wrapper1.dll  by CFF Explorer. which can be found at :http://www.ntcore.com/exsuite.php