//Inject the DLL into TargetApplication, which gives the DLL full access to the //process' internals and allows us to hook and call methods from outside via //named pipes communication with the DLL. private void Hook() { if (!this._isHooked) { this._isHooked = true; InjectDll.Inject(this._process, "Hook.dll"); } }
private void button2_Click(object sender, EventArgs e) { IntPtr hMod = LoadLibrary(tbDllPath.Text); if (rbManualMap.Checked) { if (hMod != IntPtr.Zero) { IntPtr InjectDllPtr = GetProcAddress(hMod, "InjectDll"); InjectDllFunc = (InjectDll)Marshal.GetDelegateForFunctionPointer(InjectDllPtr, typeof(InjectDll)); } if (InjectDllFunc != null) { foreach (Process proc in Process.GetProcessesByName(tbProcessName.Text)) { Int32 rval = InjectDllFunc(this.Handle, tbDllPath.Text, proc.Id); Log(string.Format("Injected {0} into process {1}. rval = {2}\n", tbDllPath.Text, proc.Id, rval)); } button2.Enabled = false; } } else if (rbWindowHook.Checked) { if (hMod != IntPtr.Zero) { IntPtr InstallHookPtr = GetProcAddress(hMod, "InstallHook"); IntPtr ReleaseHookPtr = GetProcAddress(hMod, "ReleaseHook"); InstallHookFunc = (InstallHook)Marshal.GetDelegateForFunctionPointer(InstallHookPtr, typeof(InstallHook)); ReleaseHookFunc = (ReleaseHook)Marshal.GetDelegateForFunctionPointer(ReleaseHookPtr, typeof(ReleaseHook)); } if (InstallHookFunc != null) { InstallHookFunc(this.Handle, tbProcessName.Text); button2.Enabled = false; Log("Created global window hook. Launch the target process now...\n"); } } }
public static void HandleMessagesTick() { if (IPC.Active) { try { switch ((State)IPC.State) { case State.Idle: return; case State.GetMaterials: IPC.SetObjectBuf(Materials.Get()); break; case State.GetWeaponsRanged: IPC.SetObjectBuf(WeaponsRanged.Get()); break; case State.GetWeaponsMelee: IPC.SetObjectBuf(WeaponsMelee.Get()); break; case State.GetApparels: IPC.SetObjectBuf(Apparels.Get()); break; case State.GetBuildingsFromMaterials: IPC.SetObjectBuf(BuildingsFromMaterials.Get()); break; case State.GetAnimals: IPC.SetObjectBuf(Animals.Get()); break; case State.GetDebuffs: IPC.SetObjectBuf(Debuffs.Get()); break; case State.GetDrugs: IPC.SetObjectBuf(Drugs.Get()); break; case State.GetFoods: IPC.SetObjectBuf(Foods.Get()); break; case State.GetActiveIncidents: IPC.StringBuf = ActiveIncidents.Get(); break; case State.GetPawnsHeddifs: IPC.StringBuf = PawnsHeddifs.Get(); break; case State.GetBodyParts: IPC.SetObjectBuf(BodyParts.Get()); break; case State.GetFacilities: IPC.SetObjectBuf(Facilities.Get()); break; case State.GetPlants: IPC.SetObjectBuf(Plants.Get()); break; case State.GetBackstorys: IPC.SetObjectBuf(Backstorys.Get()); break; case State.GetTraits: IPC.SetObjectBuf(Traits.Get()); break; case State.GetCEAmmos: IPC.SetObjectBuf(CEAmmos.Get()); break; case State.GetTools: IPC.SetObjectBuf(Tools.Get()); break; case State.BuildingStuffDump: new BuildingStuffDump(); break; case State.WeaponApparelDump: IPC.StringBuf = WeaponApparelDump.Get(); break; case State.InjectDll: IPC.StringBuf = InjectDll.GetResult(IPC.GetObjectBuf <InjectParameters>()); break; case State.GcCollect: GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); GC.WaitForPendingFinalizers(); Log.Warning($"[RimHelperProxy] GC.Collect() called!"); break; default: throw new Exception($"UnknownState: {IPC.State}"); } } catch (Exception e) { Log.Error($"[HandleMessagesTick] Exception: {e.Message}"); Log.Error($"[HandleMessagesTick] StackTrace: {e.StackTrace}"); } finally { IPC.State = (int)State.Idle; } } }
private void button2_Click(object sender, EventArgs e) { IntPtr hMod = LoadLibrary(tbDllPath.Text); if (rbManualMap.Checked) { if (hMod != IntPtr.Zero) { IntPtr InjectDllPtr = GetProcAddress(hMod, "InjectDll"); InjectDllFunc = (InjectDll)Marshal.GetDelegateForFunctionPointer(InjectDllPtr, typeof(InjectDll)); } if (InjectDllFunc != null) { foreach( Process proc in Process.GetProcessesByName(tbProcessName.Text) ) { Int32 rval = InjectDllFunc(this.Handle, tbDllPath.Text, proc.Id); Log(string.Format("Injected {0} into process {1}. rval = {2}\n", tbDllPath.Text, proc.Id, rval)); } button2.Enabled = false; } } else if (rbWindowHook.Checked) { if (hMod != IntPtr.Zero) { IntPtr InstallHookPtr = GetProcAddress(hMod, "InstallHook"); IntPtr ReleaseHookPtr = GetProcAddress(hMod, "ReleaseHook"); InstallHookFunc = (InstallHook)Marshal.GetDelegateForFunctionPointer(InstallHookPtr, typeof(InstallHook)); ReleaseHookFunc = (ReleaseHook)Marshal.GetDelegateForFunctionPointer(ReleaseHookPtr, typeof(ReleaseHook)); } if (InstallHookFunc != null) { InstallHookFunc(this.Handle, tbProcessName.Text); button2.Enabled = false; Log("Created global window hook. Launch the target process now...\n"); } } }