Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

Commit

Permalink
Adjust logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
fifty-six committed Dec 30, 2020
1 parent 2b3c672 commit 9617b04
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn caught_main() !void {

var size = try get_module_size(proc_handle, mod_handle);

try stdout.print("Module handle address:: {x}\n", .{@ptrToInt(mod_handle)});
try stdout.print("Module handle address: {x}\n", .{@ptrToInt(mod_handle)});

var patch_addr = try get_memory_address(proc_handle, @ptrToInt(mod_handle), size, EGG[0..], allocator);

Expand All @@ -73,18 +73,23 @@ pub fn caught_main() !void {
var patched = try read_memory_address(proc_handle, patch_addr - PATCH_OFFSET, EGG.len, allocator);
defer allocator.free(patched);

try print_buffer(patched);

var egg_clone = try std.mem.dupe(allocator, u8, &EGG);

std.mem.copy(u8, egg_clone[PATCH_OFFSET..PATCH_OFFSET + PATCH.len], &PATCH);

// Make sure patch was applied correctly
std.debug.assert(std.mem.eql(u8, egg_clone, patched));
if (!std.mem.eql(u8, egg_clone, patched)) {
try stdout.print("Expected: ", .{});
try print_buffer(egg_clone);
try stdout.print("Got: ", .{});
try print_buffer(patched);

return error.PatchAppliedIncorrectly;
}
}

pub fn catch_if_ncli() !void {
var stdout = std.io.getStdOut();
var stdout = std.io.getStdOut().writer();

var buf: [10]c.LPDWORD = undefined;

Expand All @@ -95,7 +100,7 @@ pub fn catch_if_ncli() !void {
return;
}

std.debug.print("Press ENTER to close.", .{});
try stdout.print("Press ENTER to close.", .{});

// Keep console open
_ = try std.io.getStdIn().reader().readByte();
Expand Down Expand Up @@ -154,8 +159,6 @@ pub fn get_memory_address(proc_handle: win.HANDLE, addr: usize, size: usize, mem

var ind = std.mem.indexOf(u8, buf[0..bytes_read], mem) orelse return error.PatternNotFound;

try print_buffer(buf[ind..ind + mem.len]);

return addr + ind;
}

Expand Down

0 comments on commit 9617b04

Please sign in to comment.