KMint
KMint

Reputation: 43

Detours DLL injection works only for specific applications

I try to hook some functions using Microsoft Detours. The method I'm using is CreateRemoteThread + LoadLibrary.

Yet, I've encountered that the exact same code works on notepad.exe, some chrome processes etc., but not on wmplayer.exe(Windows Media Player), Calculator.exe somehow. Is it correct to say that these applications probably tried to prevent this type of DLL injection? I can hardly come up with other possibilities.

Most of these code are copied from the Detours tutorial

The code can be seen and cloned from this repository in case anyone want to experiment them.

when the variable exeName is set to "notepad.exe", the file "D:\output.txt" will be created, while setting the variable to "Calculator.exe" won't.

If my guess is correct, is using other injection method(ex. SetWindowsHookEx) the only way I can make these work?

Upvotes: 0

Views: 1099

Answers (2)

Ankit
Ankit

Reputation: 71

On Windows 10, "Calculator" is Windows App and according to Detours documentation detours doesn't work for Windows App for following reason

Why can't my Windows Store app for Windows 8 include Detours?

Windows Store apps may use only a subset of the Win32 API. Detours requires several Win32 APIs that are forbidden in for Windows App Certification. Forbidden APIs used by Detours include VirtualAlloc, VirtualProtect, and FlushInstructionCache.

As per Microsoft documentation

Windows apps:: All apps installed in C:\Program Files\WindowsApps.

Path of "Calculator" on Windows 10 is

C:\Program Files\WindowsApps\microsoft.windowscalculator_10.2103.8.0_x64__8wekyb3d8bbwe\Calculator.exe

Upvotes: 2

KMint
KMint

Reputation: 43

Personally I think these applications indeed prevented from being injected by the CreateRemoteThread + LoadLibrary method since it's the most basic approach, but this guess needs further proof. After I switched to use the SetWindowsHookEX method in this repository, the DllMain will be called successfully.

Upvotes: 0

Related Questions