Exemple #1
0
        ////////////////////////////////////////////////////////////////////////////////
        //
        ////////////////////////////////////////////////////////////////////////////////
        internal static IntPtr GetModuleAddress(String module, UInt32 processId, ref UInt32 dwSize)
        {
            IntPtr hModule   = IntPtr.Zero;
            IntPtr hSnapshot = IntPtr.Zero;

            try
            {
                hSnapshot = kernel32.CreateToolhelp32Snapshot(TiHelp32.TH32CS_SNAPMODULE | TiHelp32.TH32CS_SNAPMODULE32, processId);
                if (IntPtr.Zero == hSnapshot)
                {
                    return(hModule);
                }

                TiHelp32.tagMODULEENTRY32 moduleEntry = new TiHelp32.tagMODULEENTRY32();
                moduleEntry.dwSize = (UInt32)Marshal.SizeOf(moduleEntry);
                if (!kernel32.Module32First(hSnapshot, ref moduleEntry))
                {
                    return(hModule);
                }

                do
                {
                    if (moduleEntry.szModule == module)
                    {
                        hModule = moduleEntry.modBaseAddr;
                        dwSize  = moduleEntry.modBaseSize;
                    }

                    moduleEntry        = new TiHelp32.tagMODULEENTRY32();
                    moduleEntry.dwSize = (UInt32)Marshal.SizeOf(moduleEntry);
                }while (kernel32.Module32Next(hSnapshot, ref moduleEntry));
            }
            catch (Exception)
            {
                return(hModule);
            }
            finally
            {
                kernel32.CloseHandle(hSnapshot);
            }
            return(hModule);
        }
Exemple #2
0
 public static extern Boolean Module32Next(IntPtr hSnapshot, ref TiHelp32.tagMODULEENTRY32 lpme);
Exemple #3
0
 public static extern bool Module32First(IntPtr hSnapshot, ref TiHelp32.tagMODULEENTRY32 lpme);