From 16bc59de41305d09f5ae969911db5c67f438c5e5 Mon Sep 17 00:00:00 2001 From: Pascal Zittlau Date: Fri, 21 Nov 2025 22:01:27 +0100 Subject: [PATCH] int3 padding --- src/Patcher.zig | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Patcher.zig b/src/Patcher.zig index 25986f0..e22faf3 100644 --- a/src/Patcher.zig +++ b/src/Patcher.zig @@ -294,8 +294,17 @@ pub fn patchRegion(patcher: *Patcher, region: []align(page_size) u8) !void { @memcpy(request.bytes[0..pii.num_prefixes], prefixes[0..pii.num_prefixes]); request.bytes[pii.num_prefixes] = jump_rel32; - mem.writeInt(i32, request.bytes[pii.num_prefixes + 1 ..][0..4], jump_to_offset, .little); - // TODO: pad remaining with nops or int3 + mem.writeInt( + i32, + request.bytes[pii.num_prefixes + 1 ..][0..4], + jump_to_offset, + .little, + ); + // Pad remaining with int3. + const patch_end_index = pii.num_prefixes + jump_rel32_size; + if (patch_end_index < request.size) { + @memset(request.bytes[patch_end_index..request.size], int3); + } break; } @@ -360,9 +369,13 @@ const PatchInstructionIterator = struct { }; } - fn next(pii: *PatchInstructionIterator, gpa: mem.Allocator, address_allocator: *AddressAllocator) !?Range { + fn next( + pii: *PatchInstructionIterator, + gpa: mem.Allocator, + address_allocator: *AddressAllocator, + ) !?Range { // TODO: This is basically a state machine here, so maybe use labeled switch instead for - // clarity + // clarity. while (true) { if (try address_allocator.allocate( gpa,