Exemplo n.º 1
0
        public Injector(int processId)
        {
            Process process = Process.GetProcesses().FirstOrDefault(p => p.Id == processId);

            if (process == null)
            {
                throw new InjectorException($"Could not find a process with the id {processId}");
            }

            if ((_handle = Native.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, process.Id)) == IntPtr.Zero)
            {
                throw new InjectorException("Failed to open process", new Win32Exception(Marshal.GetLastWin32Error()));
            }

            Is64Bit = ProcessUtils.Is64BitProcess(_handle);

            if (!ProcessUtils.GetMonoModule(_handle, out _mono))
            {
                throw new InjectorException("Failed to find mono.dll in the target process");
            }

            _memory = new Memory(_handle);
        }