()
| 13 | class Program |
| 14 | { |
| 15 | static void Main() |
| 16 | { |
| 17 | var currentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); |
| 18 | var bootstrapperSettingsFilePath = Path.Combine(currentFolder, "bootstrapperSettings.json"); |
| 19 | var bootstrapperSettings = JsonConvert.DeserializeObject<BootstrapperSettings>(File.ReadAllText(bootstrapperSettingsFilePath)); |
| 20 | |
| 21 | var startupInfo = new STARTUPINFO(); |
| 22 | |
| 23 | // run BloogBot.exe in a new process |
| 24 | CreateProcess( |
| 25 | bootstrapperSettings.PathToWoW, |
| 26 | null, |
| 27 | IntPtr.Zero, |
| 28 | IntPtr.Zero, |
| 29 | false, |
| 30 | ProcessCreationFlag.CREATE_DEFAULT_ERROR_MODE, |
| 31 | IntPtr.Zero, |
| 32 | null, |
| 33 | ref startupInfo, |
| 34 | out PROCESS_INFORMATION processInfo); |
| 35 | |
| 36 | // this seems to help prevent timing issues |
| 37 | Thread.Sleep(1000); |
| 38 | |
| 39 | // get a handle to the BloogBot process |
| 40 | var processHandle = Process.GetProcessById((int)processInfo.dwProcessId).Handle; |
| 41 | |
| 42 | // resolve the file path to Loader.dll relative to our current working directory |
| 43 | var loaderPath = Path.Combine(currentFolder, "Loader.dll"); |
| 44 | |
| 45 | // allocate enough memory to hold the full file path to Loader.dll within the BloogBot process |
| 46 | var loaderPathPtr = VirtualAllocEx( |
| 47 | processHandle, |
| 48 | (IntPtr)0, |
| 49 | loaderPath.Length, |
| 50 | MemoryAllocationType.MEM_COMMIT, |
| 51 | MemoryProtectionType.PAGE_EXECUTE_READWRITE); |
| 52 | |
| 53 | // this seems to help prevent timing issues |
| 54 | Thread.Sleep(500); |
| 55 | |
| 56 | int error = Marshal.GetLastWin32Error(); |
| 57 | if (error > 0) |
| 58 | throw new InvalidOperationException($"Failed to allocate memory for Loader.dll, error code: {error}"); |
| 59 | |
| 60 | // write the file path to Loader.dll to the EoE process's memory |
| 61 | var bytes = Encoding.Unicode.GetBytes(loaderPath); |
| 62 | var bytesWritten = 0; // throw away |
| 63 | WriteProcessMemory(processHandle, loaderPathPtr, bytes, bytes.Length, ref bytesWritten); |
| 64 | |
| 65 | // this seems to help prevent timing issues |
| 66 | Thread.Sleep(1000); |
| 67 | |
| 68 | error = Marshal.GetLastWin32Error(); |
| 69 | if (error > 0 || bytesWritten == 0) |
| 70 | throw new InvalidOperationException($"Failed to write Loader.dll into the WoW.exe process, error code: {error}"); |
| 71 | |
| 72 | // search current process's for the memory address of the LoadLibraryW function within the kernel32.dll module |
nothing calls this directly
no outgoing calls
no test coverage detected