diff --git a/src/arm64/detours_arm64.h b/src/arm64/detours_arm64.h index c56e99e..323739d 100644 --- a/src/arm64/detours_arm64.h +++ b/src/arm64/detours_arm64.h @@ -56,12 +56,12 @@ static_assert(sizeof(detour_trampoline) == 192); typedef uint32_t detours_arm64_opcode_t; -static inline detours_arm64_opcode_t fetch_opcode(uint8_t* code) +static inline detours_arm64_opcode_t fetch_opcode(const uint8_t* code) { return *(detours_arm64_opcode_t*)code; } -static inline void write_opcode(uint8_t** int_out_code, detours_arm64_opcode_t opcode) +static inline void write_opcode(uint8_t** int_out_code, const detours_arm64_opcode_t opcode) { uint8_t* code = *int_out_code; *(detours_arm64_opcode_t*)code = opcode; @@ -98,10 +98,10 @@ union detours_arm64_indirect_imm { uint64_t adrp_immhi : 19; }; - int64_t value; + uint64_t value; }; -static inline uint8_t* internal_detour_gen_jmp_indirect(uint8_t* code, uint64_t* jump_val) +static inline uint8_t* internal_detour_gen_jmp_indirect(uint8_t* code, const uint64_t* jump_val) { // adrp x17, [jmpval] // ldr x17, [x17, jmpval] @@ -135,7 +135,7 @@ static inline uint8_t* internal_detour_gen_jmp_indirect(uint8_t* code, uint64_t* return code; } -static inline uint8_t* internal_detour_gen_brk(uint8_t* code, uint8_t* limit) +static inline uint8_t* internal_detour_gen_brk(uint8_t* code, const uint8_t* limit) { while (code < limit) { write_opcode(&code, 0xd4100000 | (0xf000 << 5)); diff --git a/src/detours_internal.h b/src/detours_internal.h index bafc9e3..999e048 100644 --- a/src/detours_internal.h +++ b/src/detours_internal.h @@ -26,7 +26,11 @@ #endif #ifndef ARRAYSIZE -#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0])) +#endif + +#ifndef UNUSED_VARIABLE +#define UNUSED_VARIABLE(x) (void)(x) #endif #endif //MACH_DETOURS_INTERNAL_H \ No newline at end of file diff --git a/src/mach_detours.c b/src/mach_detours.c index 98183a2..d4b8c09 100644 --- a/src/mach_detours.c +++ b/src/mach_detours.c @@ -30,6 +30,7 @@ typedef struct detour_region detour_trampoline* free_list_head; // List of free trampolines in this region. } detour_region; +// ReSharper disable once CppMultiCharacterLiteral static const uint32_t DETOUR_REGION_SIGNATURE = 'Rrtd'; static const uint32_t DETOUR_REGION_SIZE = 0x10000; static const uint32_t DETOUR_TRAMPOLINES_PER_REGION = (DETOUR_REGION_SIZE / sizeof(detour_trampoline)) - 1; @@ -119,7 +120,8 @@ static void internal_detour_free_unused_trampoline_regions() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Trampoline Helpers -static uint8_t internal_detour_align_from_trampoline(detour_trampoline* trampoline, uint8_t offset_trampoline) +static uint8_t internal_detour_align_from_trampoline(const detour_trampoline* trampoline, + const uint8_t offset_trampoline) { for (int32_t n = 0; n < ARRAYSIZE(trampoline->align); n++) { if (trampoline->align[n].offset_trampoline == offset_trampoline) { @@ -129,7 +131,7 @@ static uint8_t internal_detour_align_from_trampoline(detour_trampoline* trampoli return 0; } -static uint8_t internal_detour_align_from_target(detour_trampoline* trampoline, uint8_t offset_target) +static uint8_t internal_detour_align_from_target(const detour_trampoline* trampoline, const uint8_t offset_target) { for (int32_t n = 0; n < ARRAYSIZE(trampoline->align); n++) { if (trampoline->align[n].offset_target == offset_target) { @@ -285,6 +287,7 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target) uint8_t* code = internal_detour_gen_jmp_indirect(operation->target, (uint64_t*)&(operation->trampoline->ptr_detour)); code = internal_detour_gen_brk(code, operation->trampoline->ptr_remain); + UNUSED_VARIABLE(code); *operation->pointer = operation->trampoline->code; #endif // DETOURS_ARM64 @@ -315,8 +318,8 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target) for (detour_pending_thread* thread = s_pending_threads_head; thread != nullptr; thread = thread->next) { arm_thread_state64_t threadState; mach_msg_type_number_t threadStateCnt = ARM_THREAD_STATE64_COUNT; - kern_return_t error = thread_get_state(thread->thread, ARM_THREAD_STATE64, (thread_state_t)&threadState, - &threadStateCnt); + const kern_return_t error = thread_get_state(thread->thread, ARM_THREAD_STATE64, (thread_state_t)&threadState, + &threadStateCnt); if (error != err_none) { DETOUR_BREAK(); continue;