There is an application that checks for activation using DLL Check
function. Check
returns 1 if application is activated and 0 otherwise. I create simple application and DLL containing function MyCheck
(which always returns 1) with the same signature and detoured Check
function with my version using MS detours lib for function hooking. Obviously it works and the application is successfully cracked, so I need to avoid it.
I tried to call
Check
function directly (by specifying exact address), without even usingGetProcAddress
, but looks like detours lib is modifying the function body itself, not export table.[UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate bool CheckFunctionDelegate(); static void Main(string[] args) { ProcessModule module = Process.GetCurrentProcess().Modules .Cast<ProcessModule>() .First(m => m.ModuleName == "licensing_check.dll"); IntPtr procedurePtr = IntPtr.Add(module.BaseAddress, 0x00003FF0); // Calling validation function by pointer CheckFunctionDelegate checkFunction = (CheckFunctionDelegate) Marshal.GetDelegateForFunctionPointer(procedurePtr, typeof(CheckFunctionDelegate)); if (checkFunction()) { // do some stuff } }
}
Then I tried to read function body and I see that after detour MD5 checksum differs from the original one. So I'm trying to read entire contents of DLL in memory and check it to confirm that DLL contents are not changed, but it doesn't work either. It throws
AccessViolationException
.Process.EnterDebugMode();
ProcessModule module = Process.GetCurrentProcess().MainModule; byte[] data = new byte[module.ModuleMemorySize]; Marshal.Copy(module.BaseAddress, data, 0, module.ModuleMemorySize);
I used MainModule here, but it gives the same error for each module in Process.GetCurrentProcess().Modules
collection.
I would appreciate any help on this, I'm not necessarily expecting to solve it in one of the ways I describe, any good solution is acceptable.
Thanks.