| 202 | |
| 203 | |
| 204 | void PatchManager::patch() { |
| 205 | |
| 206 | win32ThreadManager threadMgr; |
| 207 | auto pid = threadMgr.getTargetPid(); |
| 208 | result_t result; |
| 209 | |
| 210 | systemMgr.log("patch(): entering."); |
| 211 | |
| 212 | // check if kernel driver is initialized. |
| 213 | if (!driver.driverReady) { |
| 214 | systemMgr.log("patch(): kdriver is not initialized correctly, quit."); |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | if (pid != 0 /* target exist */ && |
| 219 | pid != patchPid /* target is not current */) { |
| 220 | |
| 221 | // reset status. |
| 222 | patchPid = 0; |
| 223 | patchStatus.NtQueryVirtualMemory = false; |
| 224 | patchStatus.NtReadVirtualMemory = false; |
| 225 | patchStatus.GetAsyncKeyState = false; |
| 226 | patchStatus.NtWaitForSingleObject = false; |
| 227 | patchStatus.NtDelayExecution = false; |
| 228 | patchStatus.DeviceIoControl_1 = false; |
| 229 | patchStatus.DeviceIoControl_1x = false; |
| 230 | patchStatus.DeviceIoControl_2 = false; |
| 231 | |
| 232 | |
| 233 | // start driver. |
| 234 | if (!(result = driver.load())) { |
| 235 | systemMgr.panic(result.error()); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | // patch ioctl. |
| 240 | if (patchSwitches.DeviceIoControl_1 || patchSwitches.DeviceIoControl_2) { |
| 241 | |
| 242 | patchSwitches_t switches; |
| 243 | switches.DeviceIoControl_1 = patchSwitches.DeviceIoControl_1.load(); |
| 244 | switches.DeviceIoControl_1x = patchSwitches.DeviceIoControl_1x.load(); |
| 245 | switches.DeviceIoControl_2 = patchSwitches.DeviceIoControl_2.load(); |
| 246 | |
| 247 | if (!_patch_ntdll(pid, switches)) { |
| 248 | driver.unload(); // if _patch_ntdll() fails, stop driver and quit (to retry). |
| 249 | return; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // unload to wait. |
| 254 | driver.unload(); |
| 255 | |
| 256 | |
| 257 | // wait if adv search: before patch ntdll etc. |
| 258 | systemMgr.log(format("patch(): waiting {}s before manip ntdll etc.", patchDelayBeforeNtdlletc.load())); |
| 259 | |
| 260 | for (DWORD time = 0; patchEnabled && time < patchDelayBeforeNtdlletc; time++) { |
| 261 | if (systemMgr.sleepFor(1000)) { |
no test coverage detected