I am looking for a c# method to add to my winforms app which can either:
a. Detect any loaded modules/dlls that shouldnt be there. Or,
b. (Preferably) totally prevent a dll injection. I've reviewed this article which is helpful, but doesnt provide the actual code to defend against CreateRemoteThread, SetWindowsHookEx or Code Cave.
EDIT
I was thinking of a background thread running code like the following. I am quite new to the topic so please excuse my naivety
var trustedModules = new[] {"kernel32.dll", "user32.dll", "etc"};
var intrusionDetected =
Process.GetCurrentProcess()
.Modules.Cast<ProcessModule>()
.Any(module => !trustedModules.Contains(module.FileName.ToLowerInvariant()));
if (intrusionDetected)
{
// do something
}