fix detour_set_ignore_too_small + more docs

This commit is contained in:
Lysann Tranvouez 2025-10-03 22:25:53 +02:00
parent 728e795c2c
commit 7c25e72f15
2 changed files with 42 additions and 20 deletions

View file

@ -658,11 +658,10 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
if (detour == (detour_func_t)target) {
if (s_ignore_too_small) {
goto stop;
} else {
DETOUR_BREAK();
error = detour_err_too_small;
goto fail;
}
error = detour_err_too_small;
DETOUR_BREAK();
goto fail;
}
if (out_real_target) {
@ -677,6 +676,7 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
error = KERN_RESOURCE_SHORTAGE;
fail:
s_pending_error = error;
s_pending_error_pointer = inout_pointer;
DETOUR_BREAK();
stop:
if (trampoline) {
@ -698,7 +698,6 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
if (out_real_target) {
*out_real_target = nullptr;
}
s_pending_error_pointer = inout_pointer;
return error;
}
@ -771,13 +770,12 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
if (target_override_len < DETOUR_PLATFORM_SIZE_OF_JMP || align_idx > ARRAYSIZE(trampoline->align)) {
// Too few instructions.
error = detour_err_too_small;
if (s_ignore_too_small) {
goto stop;
} else {
DETOUR_BREAK();
goto fail;
}
error = detour_err_too_small;
DETOUR_BREAK();
goto fail;
}
if (trampoline_code > trampoline_code_limit) {
@ -892,12 +890,12 @@ mach_error_t detour_detach(detour_func_t* inout_pointer, detour_func_t detour)
error = KERN_RESOURCE_SHORTAGE;
fail:
s_pending_error = error;
s_pending_error_pointer = inout_pointer;
DETOUR_BREAK();
stop:
free(op);
// ReSharper disable once CppDFAUnusedValue
op = nullptr;
s_pending_error_pointer = inout_pointer;
return error;
}
@ -908,23 +906,21 @@ mach_error_t detour_detach(detour_func_t* inout_pointer, detour_func_t detour)
const uint32_t restore_code_size = trampoline->restore_code_size;
uint8_t* target = trampoline->ptr_remain - restore_code_size;
if (restore_code_size == 0 || restore_code_size > sizeof(trampoline->code)) {
error = KERN_FAILURE;
if (s_ignore_too_small) {
goto stop;
} else {
DETOUR_BREAK();
goto fail;
}
error = KERN_FAILURE;
DETOUR_BREAK();
goto fail;
}
if (trampoline->ptr_detour != detour) {
error = KERN_FAILURE;
if (s_ignore_too_small) {
goto stop;
} else {
DETOUR_BREAK();
goto fail;
}
error = KERN_FAILURE;
DETOUR_BREAK();
goto fail;
}
const mach_port_t port = mach_task_self();