public void Inject(int pid, string pathToDll, InjectionOptions injectionOptions = null)
        {
            if (pid <= 0)
            {
                throw new ArgumentException("Invalid process pid: " + pid, "pid");
            }
            if (string.IsNullOrWhiteSpace(pathToDll) || !File.Exists(pathToDll))
            {
                throw new ArgumentException($"Cannot access DLL: " { pathToDll } "");
            }
            if (injectionOptions == null)
            {
            }
            injectionOptions = InjectionOptions.Defaults;
            IntPtr processHandle = WinAPI.OpenProcess(WinAPI.ProcessAccessFlags.CreateThread | WinAPI.ProcessAccessFlags.QueryInformation | WinAPI.ProcessAccessFlags.VirtualMemoryOperation | WinAPI.ProcessAccessFlags.VirtualMemoryRead | WinAPI.ProcessAccessFlags.VirtualMemoryWrite, false, pid);

            object[] args = new object[] { pid };
            Utils.CheckForFailure(processHandle == IntPtr.Zero, "Cannot open process with PID: {0}", args);
            IntPtr hHandle = this._injectionStrategy.Inject(processHandle, pathToDll);

            if (injectionOptions.WaitForThreadExit)
            {
                WinAPI.WaitForSingleObject(hHandle, uint.MaxValue);
            }
            WinAPI.CloseHandle(processHandle);
        }
        public void Inject(int pid, string pathToDll, InjectionOptions injectionOptions = null)
        {
            if (pid <= 0)
                throw new ArgumentException("Invalid process pid: " + pid, "pid");

            if (string.IsNullOrWhiteSpace(pathToDll) || !File.Exists(pathToDll))
                throw new ArgumentException(string.Format("Cannot access DLL: \"{0}\"", pathToDll));

            injectionOptions = injectionOptions ?? InjectionOptions.Defaults;

            IntPtr processHandle = WinAPI.OpenProcess(
                WinAPI.ProcessAccessFlags.CreateThread |
                WinAPI.ProcessAccessFlags.QueryInformation |
                WinAPI.ProcessAccessFlags.VirtualMemoryOperation |
                WinAPI.ProcessAccessFlags.VirtualMemoryRead |
                WinAPI.ProcessAccessFlags.VirtualMemoryWrite,
                bInheritHandle: false,
                processId: pid);

            Utils.CheckForFailure(processHandle == IntPtr.Zero, "Cannot open process with PID: {0}", pid);

            IntPtr remoteThreadHandle = _injectionStrategy.Inject(processHandle, pathToDll);
            if (injectionOptions.WaitForThreadExit) {
                WinAPI.WaitForSingleObject(remoteThreadHandle, WinAPI.INFINITE);
            }

            WinAPI.CloseHandle(processHandle);
        }
Exemple #3
0
        public void Inject(int pid, string pathToDll, InjectionOptions injectionOptions = null)
        {
            if (pid <= 0)
            {
                throw new ArgumentException("Invalid process pid: " + pid, "pid");
            }

            if (string.IsNullOrWhiteSpace(pathToDll) || !File.Exists(pathToDll))
            {
                throw new ArgumentException(string.Format("Cannot access DLL: \"{0}\"", pathToDll));
            }

            injectionOptions = injectionOptions ?? InjectionOptions.Defaults;


            IntPtr processHandle = WinAPI.OpenProcess(
                WinAPI.ProcessAccessFlags.CreateThread |
                WinAPI.ProcessAccessFlags.QueryInformation |
                WinAPI.ProcessAccessFlags.VirtualMemoryOperation |
                WinAPI.ProcessAccessFlags.VirtualMemoryRead |
                WinAPI.ProcessAccessFlags.VirtualMemoryWrite,
                bInheritHandle: false,
                processId: pid);

            Utils.CheckForFailure(processHandle == IntPtr.Zero, "Cannot open process with PID: {0}", pid);


            IntPtr remoteThreadHandle = _injectionStrategy.Inject(processHandle, pathToDll);

            if (injectionOptions.WaitForThreadExit)
            {
                WinAPI.WaitForSingleObject(remoteThreadHandle, WinAPI.INFINITE);
            }


            WinAPI.CloseHandle(processHandle);
        }
Exemple #4
0
 // Token: 0x06000039 RID: 57 RVA: 0x00004768 File Offset: 0x00002768
 public void Inject(int pid, string pathToDll, InjectionOptions injectionOptions = null)
 {
 }