Commit Graph
14 Commits
Author SHA1 Message Date
kbe 855595837f task 3.1-3.2: IAssembler interface + StubAssembler emit primitives
Add IAssembler seam (Assemble(text, origin)) with StubAssembler default
backend. StubAssembler provides EmitU8/EmitU32/EmitU64 little-endian
byte emitters (zero dep, no FASM). Assemble throws NotSupportedException
on StubAssembler (text assembly deferred to IcedAssembler, Phase 8).

7 new tests: EmitU8, EmitU32 x2, EmitU64 x2, IS-A check,
Assemble throws. All passing (total: 64).
2026-07-21 19:35:11 +02:00
kbe 68255f907c fix: IndexOfPattern alignment for multi-byte encodings
Stride the scan by pattern.Length (1 for ASCII/UTF-8, 2 for UTF-16,
4 for UTF-32) to avoid matching a misaligned null-terminator pattern
mid-character.
2026-07-21 19:34:01 +02:00
kbeandClaude Opus 4.8 6aaee0adce Merge feature/native-surface: native P/Invoke surface + Phase 2 core memory
Task 1.4 (Native/ LibraryImport surface, SafeMemoryHandle) and Phase 2
(MarshalCache, MemoryBase, ExternalReader, InProcessReader, string IO,
addressing). Reviewed high-effort: 4 correctness + 3 cleanup fixed and
verified. Deviation D1 (InProcessReader RPM-on-self) reconciled in spec.
Known follow-up: task 2.10 (ReadString UTF-16 null alignment).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 19:31:29 +02:00
kbeandClaude Opus 4.8 9f7848ffde docs: fix D1 Why to match RPM-on-self revision
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 19:31:12 +02:00
kbeandClaude Opus 4.8 991387198d Reconcile spec with Phase 2 review outcome; ignore *.log
Record the D1 deviation: InProcessReader reads the current process through
ReadProcessMemory/WriteProcessMemory on a self-handle, not unsafe direct
deref. Rationale: .NET cannot catch AccessViolationException, so a raw deref
of a bad address terminates the host with no soft-failure path. Update the
memory-access spec (new fail-soft scenario), design D1, and task 2.9.

Log task 2.10: ReadString null-terminator scan is not code-unit aligned, so
UTF-16/UTF-32 can match a misaligned multi-byte null or miss one split
across a chunk boundary (harmless for ASCII/UTF-8, the WoW case).

Ignore *.log (testrun.log).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 19:28:28 +02:00
kbe 8374650aac fix 7 correctness and cleanup issues
Blocking fixes:
1. Read<T> now returns default(T) on failed/partial read instead of crash
   (applies to single Read<T>, array Read<T>, and ReadBytes)
2. InProcessReader uses ReadProcessMemory via handle instead of unsafe
   Buffer.MemoryCopy — fails soft on bad address instead of AV'ing
3. GetRelative now returns absolute - ImageBase (inverse of GetAbsolute).
   Fix round-trip test to validate at arbitrary offsets, not just ImageBase
4. ReadString reads in 64-byte chunks with encoding-aware null-terminator
   pattern matching (handles UTF-16's 2-byte null, UTF-32's 4-byte null)

Cleanup:
5. InProcessReader validates handle on open and uses RPM through it
   (handle is no longer unused)
6. Array marshal read: pin raw buffer once, PtrToStructure at offset
7. StructureToByteArray(Span) delegates to byte[] overload, no duplicate

New tests: 4 invalid-address grace tests (returns default/empty/false).
All 57 passing.
2026-07-21 19:24:18 +02:00
kbe 6eb78e7974 Phase 2: Core Memory Access complete
task 2.9: implement InProcessReader with tests

Add InProcessReader: direct pointer dereference (unsafe) against own
process via Buffer.MemoryCopy. Implements MemoryBase API for in-process
scenarios (injected managed DLL).

8 tests: ImageBase, Read/Write int, ReadBytes, WriteBytes, Read/Write
struct, dispose lifecycle.

All passing: 52 tests (7 Native + 12 MarshalCache + 11 MemoryBase +
8 String + 6 Addressing + 8 InProcessReader).
2026-07-21 17:09:36 +02:00
kbe 8219ac95a6 task 2.7-2.8: addressing helpers with tests
Add GetAbsolute/GetRelative with nint-based arithmetic (bitness-agnostic).
Add 6 tests: absolute resolution, relative computation, base-round-trip,
isRelative flag on Read/Write/ReadBytes.
Fix MemoryBase.cs: restore for-loop body damaged by prior edit, clean up
StructureToByteArray overloads.

All passing (total: 44).
2026-07-21 17:08:08 +02:00
kbe b2a5090533 task 2.5-2.6: string Read/Write with encoding tests
Add 8 tests for string IO: ASCII/UTF8/Unicode round-trip, null-terminator
stop, max-length truncation, auto-append of null terminator, empty string.
Fix ReadString null-terminator detection for multi-byte encodings (UTF-16):
decode string first, then find \0 in characters not bytes.

All passing (total: 38).
2026-07-21 17:06:34 +02:00
kbe 6b34e0fab8 task 2.3-2.4: implement MemoryBase + ExternalReader with tests
Add abstract MemoryBase base class with typed Read<T>/Write<T>, array
IO, string IO, and relative/absolute addressing. Uses MarshalCache<T>
to branch between blittable (MemoryMarshal) and marshal-required paths.

Add ExternalReader (out-of-process via ReadProcessMemory/WriteProcessMemory)
with SafeMemoryHandle lifecycle management.

11 new tests: ImageBase, Read/Write of int/byte/long/struct, byte array,
int array, struct array, invalid address, dispose, double-dispose.
All passing (total: 30).
2026-07-21 17:05:29 +02:00
kbe ccde012e45 task 2.1-2.2: implement MarshalCache<T> with tests
Add MarshalCache<T> static class that computes Size, SizeU,
TypeRequiresMarshal, IsIntPtr, TypeCode, and RealType once per type
in the static constructor. Handles bool (size=1), enums (underlying
type), and MarshalAs-attributed fields (TypeRequiresMarshal).

12 new tests covering: blittable sizes, bool size, enum size, struct
size, marshal-required flag, IsIntPtr, computed-once caching.
All passing.
2026-07-21 17:03:23 +02:00
kbe 302da5f3c2 task 1.4: add NativeMethods.cs LibraryImport P/Invoke surface
Add LibraryImport-based P/Invoke declarations for all required Win32
APIs: OpenProcess, CloseHandle, ReadProcessMemory, WriteProcessMemory,
VirtualAllocEx, VirtualProtectEx, VirtualFreeEx, CreateRemoteThread,
GetThreadContext, SetThreadContext, Wow64GetThreadContext,
Wow64SetThreadContext, LoadLibrary, GetProcAddress, and
WaitForSingleObject.

Add InternalsVisibleTo WhiteMagicTest so the test project can call
internal NativeMethods.

Tests (NativeSurfaceTests): 7/7 passing.
2026-07-21 17:01:41 +02:00
kbeandClaude Opus 4.8 eea175499d Scaffold WhiteMagic solution and add AGENTS.md
Create the WhiteMagic net8.0-windows class library and the WhiteMagicTest
xUnit project, grouped in WhiteMagic.slnx (SDK 10 default format). Library
enables nullable, unsafe blocks, x86/x64 platforms, warnings-as-errors.
Empty solution builds clean (0 errors, 0 warnings).

Add AGENTS.md (ASD-STE100) defining the build/test commands, the test-first
rule, and the one-feature-one-branch workflow with review before merge to
master.

Mark project-setup tasks 1.1-1.3, 1.5 done; 1.4 (Native P/Invoke surface)
is the first feature branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 16:55:33 +02:00
kbeandClaude Opus 4.8 4405af15fd Add whitemagic-foundation OpenSpec design; isolate reference libs
Design-only foundation for WhiteMagic, a .NET 8 x64 library unifying the
four studied process-manipulation libs. Adds proposal, design (7 decisions),
7 capability specs, and TDD task breakdown; all validate strict.

Move Blackmagic, Blackmagic-old, GreyMagic, MemorySharp, fasm into
reference/ (gitignored) — studied, not built here; each has its own
upstream repo and nested .git. Rewrite plan doc paths to reference/.

Corrects two factual defects found in review:
- current BlackMagic has no D3D EndScene hook; MainThreadPump is net-new
  built on DetourManager, not a port
- no BlackMagic.slnx exists; task 1.3 creates a fresh solution

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-21 16:50:03 +02:00