So I have a piece of software I'm hooking into. My problem is that the software has a launcher-like home window. From that home I click "Start" and it opens a second process with the same name. In my task manager they are identical in processes/details.
My program has to hook into this second process and I can only hook after the process exists. There's no way to launch it directly without the home window.
They both have randomized PID's each time. I can't figure out a way to differentiate the two processes. If my program hooks the wrong one it will freeze up the software.
p = Process.GetProcessesByName("programName");//This is specifically just the window name so that we can interact with the client using keystrokes.
System.Diagnostics.Debug.WriteLine("Attempting to hook into the program...");
process = Process.GetProcessesByName("programName").ToList().FirstOrDefault();
if (process == null) {
System.Diagnostics.Debug.Write("Hook failed! Make sure the program is open.");
Application.Exit();
}
if (process != null) {
mreader.ReadProcess = process;//Set the process we want to read to be the one we just got in the above line.
mreader.OpenProcess();//Gets the handle of the process and hook in.
for (int i = 0; i < process.Modules.Count; i++) {
System.Diagnostics.Debug.WriteLine("Module " + i + ": " + process.Modules[i].ModuleName);
if (process.Modules[i].ModuleName == "programcore.dll") {
System.Diagnostics.Debug.WriteLine("programcore.dll found at Module " + i);
iCounter = i;//Set the number programcore is on to our counter so we can hook in each time, even if it moves.
System.Diagnostics.Debug.WriteLine("Success!");
break;
}
}
}
This is how I'm hooking into the client to read/write the memory. Unfortunately both processes have the programcore.dll that I need so I don't know how to tell them apart.