Fix dispatcher crash/deadlock, instruction analyzer, cache equality, task leak, and redirection protection

- MainThreadDispatcher: guard DispatchHook with try/catch so exceptions never escape to native caller; drain and fault pending work on Dispose; synchronize Execute/ExecuteAsync/Dispose against race/dispose.
- InstructionAnalyzer: require ModRM 0xEC for 0x83/0x81 sub-esp/rsp forms, rejecting unsafe RIP-relative or memory forms.
- PatternScannerCache: implement value equality on CacheKey so repeated scans actually hit cache.
- BackgroundTaskExecutor: add remote allocations to the free list immediately after VirtualAllocEx, before any write that could fail and leak.
- redirect: capture and restore original page protection in Apply/Remove instead of leaving target RWX.
- Regression tests for all six fixes.

Tests: 198 passing, 4 integration/interactive skipped.
This commit is contained in:
kbe
2026-07-22 00:32:19 +02:00
parent 3f0bea6bd4
commit 44a368de9c
9 changed files with 301 additions and 43 deletions
+4 -2
View File
@@ -298,6 +298,8 @@ public sealed class RemoteThreadExecutor
$"Failed to allocate remote string memory: error {error}");
}
allocations.Add(remote);
int written = _reader.WriteBytes(remote, buffer);
if (written != buffer.Length)
{
@@ -305,7 +307,6 @@ public sealed class RemoteThreadExecutor
$"Failed to write string bytes to the remote process (wrote {written} of {buffer.Length} bytes).");
}
allocations.Add(remote);
return (nuint)(nint)remote;
}
@@ -351,6 +352,8 @@ public sealed class RemoteThreadExecutor
$"Failed to allocate remote struct memory: error {error}");
}
allocations.Add(remote);
int written = _reader.WriteBytes(remote, buffer);
if (written != size)
{
@@ -358,7 +361,6 @@ public sealed class RemoteThreadExecutor
$"Failed to write struct bytes to the remote process (wrote {written} of {size} bytes).");
}
allocations.Add(remote);
return (nuint)(nint)remote;
}