Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using WinAPI.Kernel32;
- namespace Injector
- {
- public class ExternalModuleLocator
- {
- private readonly CreateToolhelp32SnapshotDelegate _createToolhelp32Snapshot;
- private readonly Module32FirstDelegate _module32First;
- private readonly Module32NextDelegate _module32Next;
- public ExternalModuleLocator(CreateToolhelp32SnapshotDelegate createToolhelp32Snapshot, Module32FirstDelegate module32First, Module32NextDelegate module32Next)
- {
- _createToolhelp32Snapshot = createToolhelp32Snapshot;
- _module32First = module32First;
- _module32Next = module32Next;
- }
- public IEnumerable<Moduleentry32> EnumProcessModules(uint procId)
- {
- var snapshot = _createToolhelp32Snapshot(SnapshotFlags.Module | SnapshotFlags.Module32, procId);
- var mod = new Moduleentry32() { dwSize = (uint)Marshal.SizeOf(typeof(Moduleentry32)) };
- if (!_module32First(snapshot, ref mod))
- {
- yield break;
- }
- do
- {
- yield return mod;
- }
- while (_module32Next(snapshot, ref mod));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement