Search code examples
c++winapivisual-c++dlldll-injection

DLL only containing code in DLL_PROCESS_ATTACH missing from executable dependencies?


I've got a DLL injection based project that I'm looking to test locally. In the target environment the DLL is loaded via AppInit_DLLs, which means it's loaded at approximately the same time user32.dll is loaded when a process is first executed. All of this works, the DLL creates a log file demonstrating success.

I'm now looking to test the behavior of the DLL in a controlled environment, specifically within the context of a test win32 program I've created in Visual Studio 2015. I took the generated lib file from the DLL project and added it as an additional dependency under Project Settings -> Linker -> Input, added the directory containing that lib file to VC++ Directories -> Library Directories and placed the DLL file alongside the generated executable. When I run the executable, however, I do not see my log file.

I decided to investigate further using dependency walker, and I don't see any mention of my DLL, so it would appear that the dependency was never added.

Some additional information:

  • Both are built using the same target architecture
  • The win32 test application is built using /MDd (Multi-threaded debug DLL)
  • The test application does not use any exported functions from the DLL, since all I'm seeking to test is that the code executed in DLL_PROCESS_ATTACH does the right thing

I can test using a separate injection process to create a thread in the remote test process, but I'm looking to replicate the behavior of the DLL being loaded early in process execution, so this alternative is not ideal.

Any help would be greatly appreciated. Thanks :-)


Solution

  • RbMm's answer was correct. The issue was that the DLL was not being linked as it was not being used. Adding an exported method and calling it in the test program did the trick.