Implement core diagnostic memory layer, execution helpers, and high-level facade slices
Implemented: - Core: UTF-16 ReadString boundary/alignment fix, target bitness and process id on MemoryBase - function interception: PatchManager, DetourManager, InstructionAnalyzer, MainThreadDispatcher - Execution: BackgroundTaskExecutor, InProcessInvoker - High-level: Magic facade, RemotePointer, async wrappers - Discovery/external code loading/Window groundwork (PEB/TEB, pattern scanning, raw allocations, DLL external code loading, window/input) Tests: 180 passing, 4 integration/interactive tests skipped.
This commit is contained in:
@@ -157,6 +157,61 @@ public class StringReadWriteTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UTF-16 null terminator split across the 64-byte chunk boundary must still be found.
|
||||
/// The first chunk ends at byte 63, so the null bytes at 64/65 are in the second chunk.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ReadString_utf16_null_across_chunk_boundary_is_found()
|
||||
{
|
||||
using var reader = OpenSelf();
|
||||
byte[] slot = new byte[256];
|
||||
|
||||
// 32 'A' UTF-16 chars = 64 bytes, no embedded null.
|
||||
byte[] text = Encoding.Unicode.GetBytes(new string('A', 32));
|
||||
Assert.Equal(64, text.Length);
|
||||
text.CopyTo(slot, 0);
|
||||
|
||||
// Null terminator at bytes 64/65.
|
||||
slot[64] = 0x00;
|
||||
slot[65] = 0x00;
|
||||
|
||||
GCHandle pin = GCHandle.Alloc(slot, GCHandleType.Pinned);
|
||||
try
|
||||
{
|
||||
IntPtr addr = pin.AddrOfPinnedObject();
|
||||
string result = reader.ReadString(addr, Encoding.Unicode, maxLength: 256);
|
||||
Assert.Equal(new string('A', 32), result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pin.Free();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A byte sequence that looks like a null at a misaligned offset must not stop the scan.
|
||||
/// "A" + U+4200 produces bytes 41 00 00 42 00 00; bytes 1-2 are an aligned-position null
|
||||
/// only if scanned byte-by-byte. The aligned UTF-16 scan must see the real terminator.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ReadString_utf16_does_not_stop_at_misaligned_null()
|
||||
{
|
||||
using var reader = OpenSelf();
|
||||
byte[] slot = Encoding.Unicode.GetBytes("A\u4200\0");
|
||||
GCHandle pin = GCHandle.Alloc(slot, GCHandleType.Pinned);
|
||||
try
|
||||
{
|
||||
IntPtr addr = pin.AddrOfPinnedObject();
|
||||
string result = reader.ReadString(addr, Encoding.Unicode, maxLength: 64);
|
||||
Assert.Equal("A\u4200", result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pin.Free();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteString_empty_string_writes_only_null()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user