3.7 KiB
3.7 KiB
1. AsmBuilder — Core (TDD: tests first)
- 1.1 Create
BlackMagicTest/AsmBuilderTests.cswith tests for single-instruction assembly:nop→[0x90],pushad→[0x60],popad→[0x61],ret→[0xC3],hlt→[0xF4] - 1.2 Create
BlackMagic/Asm/AsmBuilder.cswithAssemble(string source)entry point and instruction table. Implementnop,pushad,popad,ret,hltto make step 1.1 tests pass - 1.3 Add tests for
mov reg, imm32(eax, ecx, edx, ebx, esp, ebp, esi, edi) — each register maps to0xB8 + regencoding with 4-byte little-endian immediate - 1.4 Implement
mov reg, imm32in AsmBuilder to make step 1.3 tests pass - 1.5 Add tests for
mov reg, reg(register-to-register via ModRM byte 0xC0 + (src<<3 | dst)) - 1.6 Implement
mov reg, regto make step 1.5 tests pass - 1.7 Add tests for
push reg(0x50 + reg),pop reg(0x58 + reg) - 1.8 Implement
push reg,pop regto make step 1.7 tests pass - 1.9 Add tests for
add reg, imm8(0x83 /0with sign-extended byte),sub reg, imm8(0x83 /5),xor reg, reg(0x31 /r),and reg, imm8,or reg, imm8,cmp reg, imm8(0x83 /7) - 1.10 Implement
add,sub,xor,and,or,cmpto make step 1.9 tests pass - 1.11 Add tests for
inc reg(0x40 + reg),dec reg(0x48 + reg),test reg, reg(0x85 /r) - 1.12 Implement
inc,dec,testto make step 1.11 tests pass - 1.13 Add tests for
jmp @label,je @label,jne @labelwith forward and backward references - 1.14 Implement two-pass label resolution in AsmBuilder (pass 1: record label offsets, pass 2: patch jump targets). Make step 1.13 tests pass
- 1.15 Add tests for
call @label(near call, E8 rel32) andnopmulti-instruction sequences - 1.16 Implement
callto make step 1.15 tests pass - 1.17 Add tests for error cases: unknown instruction →
ArgumentExceptionwith line number, missing operand →ArgumentException, invalid register →ArgumentException - 1.18 Implement error reporting to make step 1.17 tests pass
2. AsmBuilder — Pass Limit
- 2.1 Add tests for
SetPassLimit(): default is 10, custom value is respected, exceeded limit throwsInvalidOperationException - 2.2 Implement
SetPassLimit(int limit)and pass-limit enforcement in AsmBuilder to make step 2.1 tests pass
3. InjectAndExecuteEx — Non-blocking Execution
- 3.1 Add tests for
BlackMagic.InjectAndExecuteEx(IntPtr, IntPtr): returnsnullwhen no process open, returns valid handle when process open (mock or integration) - 3.2 Implement
InjectAndExecuteEx(IntPtr startAddress, IntPtr parameter)inBMThread.csto make step 3.1 tests pass - 3.3 Add test for single-parameter overload:
InjectAndExecuteEx(IntPtr)passesIntPtr.Zero - 3.4 Implement
InjectAndExecuteEx(IntPtr startAddress)overload inBMThread.cs
4. Convenience Overloads (text → inject → execute)
- 4.1 Add tests for
InjectAndExecute(string asm): assembles text, allocates remote memory, writes bytes, executes, returns exit code. Test assembly failure →ArgumentException - 4.2 Implement
InjectAndExecute(string asm)inBMInject.csto make step 4.1 tests pass - 4.3 Add tests for
InjectAndExecuteEx(string asm): assembles text, allocates remote memory, writes bytes, returns thread handle. Test assembly failure →ArgumentException - 4.4 Implement
InjectAndExecuteEx(string asm)inBMInject.csto make step 4.3 tests pass
5. Build Verification
- 5.1 Run full test suite:
"C:\Program Files\dotnet\dotnet.exe" test BlackMagicTest/BlackMagicTest.csproj— all tests pass - 5.2 Run full solution build:
"C:\Program Files\dotnet\dotnet.exe" build BlackMagic.slnx— zero errors