public Injector(string processName) { if (processName.EndsWith(".exe")) { processName.Replace(".exe", ""); } Process process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)); if (process == null) { throw new InjectorException($"Could not find a process with the name {processName}"); } 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); }
public Injector(Process process) { //etcPath = Path.GetDirectoryName(process.MainModule.FileName) + @"\" + Path.GetFileNameWithoutExtension(process.MainWindowTitle) + @"_Data\il2cpp_data\etc"; etcPath = Path.GetDirectoryName(process.MainModule.FileName) + @"\" + Path.GetFileNameWithoutExtension(process.MainWindowTitle) + @"_Data\Native\Data\etc"; if (process == null) { throw new InjectorException($"Bad process"); } if ((_handle = Native.OpenProcess(ProcessAccessRights.PROCESS_ALL_ACCESS, false, process.Id)) == IntPtr.Zero) { throw new InjectorException("Failed to open process", new Win32Exception(Marshal.GetLastWin32Error())); } KernelMemorySharp.MemoryDriver._ProcessId = process.Id; #if DEBUG ProcessUtils.ShowConsole(_handle); #endif Is64Bit = ProcessUtils.Is64BitProcess(_handle); if (!ProcessUtils.GetMonoModule(_handle, out _mono)) { var monoPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); var monoDll = monoPath + @"\mono\mono-2.0-bdwgc.dll"; /*if (!File.Exists(monoDll)) * { * File.WriteAllBytes("mono-2.0-bdwgc.dl_", new WebClient().DownloadData("https://symbolserver.unity3d.com/mono-2.0-bdwgc.dll/5F36619D76c000/mono-2.0-bdwgc.dl_")); * var cab = new Microsoft.Deployment.Compression.Cab.CabInfo("mono-2.0-bdwgc.dl_"); * cab.UnpackFile("mono-2.0-bdwgc.dll", monoDll); * File.Delete("mono-2.0-bdwgc.dl_"); * }*/ ProcessUtils.InjectDll(_handle, monoDll); if (!ProcessUtils.GetMonoModule(_handle, out _mono)) { throw new InjectorException("Failed to find mono.dll in the target process"); } } if (!ProcessUtils.GetGameAssembly(_handle, out _gameAssembly)) { throw new InjectorException("Failed to find GameAssembly.dll in the target process"); } _memory = new Memory(_handle); }
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); }