Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Windows insider build 20246 #3

Merged
merged 2 commits into from
Nov 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions clink/shared/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ static char* write_trampoline_out(char* write, void* to_hook, void* hook)
const int rel_jmp_size = 5;
int offset = 0;
char* patch = (char*)to_hook;
unsigned char failed_bytes[125];
memset(failed_bytes, 0, 125);

// Scan backwards for a nop slide or int3 block to patch into.
int viable_bytes = 0;
Expand All @@ -199,11 +197,7 @@ static char* write_trampoline_out(char* write, void* to_hook, void* hook)
offset++;

unsigned char c = *patch;
if (offset > 125 || c == 0xc3){
// if c is '0xc33, we've hit a RET, which likely means that we're in another function.
// Skip the rest.
if (c == 0xc3)
LOG_INFO("Hit RET");
if (offset > 127){
LOG_INFO("No nop slide or int3 block detected nearby prior to hook target, checked %d prior bytes", offset-1);
LOG_INFO("Now checking bytes after hook target");
// reset for checking forwards
Expand All @@ -222,7 +216,7 @@ static char* write_trampoline_out(char* write, void* to_hook, void* hook)
patch++;
offset--;

if (offset < -125)
if (offset < -131)
{
LOG_INFO("No nop slide or int3 block detected nearby after hook target, checked %d later bytes", (-1 * (offset+1)));
return NULL;
Expand All @@ -240,6 +234,8 @@ static char* write_trampoline_out(char* write, void* to_hook, void* hook)
offset += 4;
patch -= 4;
}

LOG_INFO("Patching at offset %d", -1 * (offset));

// Patch the API.
patch = write_rel_jmp(patch, write);
Expand Down