private static void Inject(Injector injector, CommandLineArguments args) { string assemblyPath, @namespace, className, methodName; byte[] assembly; if (args.GetStringArg("-a", out assemblyPath)) { try { assembly = File.ReadAllBytes(assemblyPath); } catch { System.Console.WriteLine("Could not read the file " + assemblyPath); return; } } else { System.Console.WriteLine("No assembly specified"); return; } args.GetStringArg("-n", out @namespace); if (!args.GetStringArg("-c", out className)) { System.Console.WriteLine("No class name specified"); return; } if (!args.GetStringArg("-m", out methodName)) { System.Console.WriteLine("No method name specified"); return; } using (injector) { IntPtr remoteAssembly = IntPtr.Zero; try { remoteAssembly = injector.Inject(assembly, @namespace, className, methodName); } catch (InjectorException ie) { System.Console.WriteLine("Failed to inject assembly: " + ie); } catch (Exception exc) { System.Console.WriteLine("Failed to inject assembly (unknown error): " + exc); } if (remoteAssembly == IntPtr.Zero) { return; } System.Console.WriteLine($"{Path.GetFileName(assemblyPath)}: " + (injector.Is64Bit ? $"0x{remoteAssembly.ToInt64():X16}" : $"0x{remoteAssembly.ToInt32():X8}")); } }
private static void Eject(Injector injector, CommandLineArguments args) { IntPtr assembly; string @namespace, className, methodName; if (args.GetIntArg("-a", out int intPtr)) { assembly = (IntPtr)intPtr; } else if (args.GetLongArg("-a", out long longPtr)) { assembly = (IntPtr)longPtr; } else { System.Console.WriteLine("No assembly pointer specified"); return; } args.GetStringArg("-n", out @namespace); if (!args.GetStringArg("-c", out className)) { System.Console.WriteLine("No class name specified"); return; } if (!args.GetStringArg("-m", out methodName)) { System.Console.WriteLine("No method name specified"); return; } using (injector) { try { injector.Eject(assembly, @namespace, className, methodName); System.Console.WriteLine("Ejection successful"); } catch (InjectorException ie) { System.Console.WriteLine("Ejection failed: " + ie); } catch (Exception exc) { System.Console.WriteLine("Ejection failed (unknown error): " + exc); } } }
private static void Main(string[] args) { System.Console.Clear(); bool IsElevated = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator); if (!IsElevated) { System.Console.WriteLine("\r\nSharpMonoInjector 2.3 wh0am1 Mod\r\n\r\nWARNING: You are running this in an unpriveleged process, try from an Elevated Command Prompt.\r\n"); System.Console.WriteLine("\t As an alternative, right-click Game .exe and uncheck the Compatibility\r\n\t setting 'Run this program as Administrator'.\r\n\r\n"); //System.Console.ReadKey(); //return; } if (args.Length == 0) { PrintHelp(); return; } CommandLineArguments cla = new CommandLineArguments(args); bool inject = cla.IsSwitchPresent("inject"); bool eject = cla.IsSwitchPresent("eject"); if (!inject && !eject) { System.Console.WriteLine("No operation (inject/eject) specified"); return; } Injector injector; if (cla.GetIntArg("-p", out int pid)) { injector = new Injector(pid); } else if (cla.GetStringArg("-p", out string pname)) { injector = new Injector(pname); } else { System.Console.WriteLine("No process id/name specified"); return; } if (inject) { Inject(injector, cla); } else { Eject(injector, cla); } }
private static void Main(string[] args) { if (args.Length == 0) { PrintHelp(); return; } CommandLineArguments cla = new CommandLineArguments(args); bool inject = cla.IsSwitchPresent("inject"); bool eject = cla.IsSwitchPresent("eject"); if (!inject && !eject) { System.Console.WriteLine("No operation (inject/eject) specified"); return; } Injector injector; if (cla.GetIntArg("-p", out int pid)) { injector = new Injector(pid); } else if (cla.GetStringArg("-p", out string pname)) { injector = new Injector(pname); } else { System.Console.WriteLine("No process id/name specified"); return; } if (inject) { Inject(injector, cla); } else { Eject(injector, cla); } }