the first < 5 bytesmaster
public _loop | public _loop | ||||
_loop: | _loop: | ||||
xor eax, eax | |||||
inc eax | |||||
mov rbx, rdx ; RDX is overwritten by mul | |||||
@again: | |||||
cmp rbx, 0 | |||||
je @loop_end | |||||
mov rax, rcx | |||||
@loop_loop: | |||||
mul rcx | mul rcx | ||||
dec rbx | |||||
jmp @again | |||||
@loop_end: | |||||
nop | |||||
nop | |||||
nop | |||||
loop @loop_loop ; lol | |||||
ret | ret | ||||
public _tail_recursion | public _tail_recursion |
#pragma once | #pragma once | ||||
extern "C" { | extern "C" { | ||||
/** | /** | ||||
* Raises @num @cnt times | |||||
* $$ x*x * (x-1)! $$ | |||||
* | * | ||||
* @param num | |||||
* @param cnt | * @param cnt | ||||
*/ | */ | ||||
uint32_t _loop(uint32_t num, uint32_t cnt); | |||||
uint32_t _loop(uint32_t x); | |||||
/** | /** | ||||
* Computes factorial | * Computes factorial |
} | } | ||||
TEST_CASE("Loops & tail recursion work as expected, unhook") { | TEST_CASE("Loops & tail recursion work as expected, unhook") { | ||||
REQUIRE(_loop(2, 3) == 8); | |||||
REQUIRE(_loop(5, 3) == 125); | |||||
REQUIRE(_loop(5, 0) == 1); | |||||
REQUIRE(_loop(5, 1) == 5); | |||||
REQUIRE(_loop(1) == 1); | |||||
REQUIRE(_loop(2) == 4); | |||||
REQUIRE(_loop(3) == 18); | |||||
REQUIRE(_loop(5) == 25*24); | |||||
REQUIRE(_tail_recursion(0) == 1); | REQUIRE(_tail_recursion(0) == 1); | ||||
REQUIRE(_tail_recursion(1) == 1); | REQUIRE(_tail_recursion(1) == 1); |
return trueRDRAND(); | return trueRDRAND(); | ||||
} | } | ||||
uint32_t MHook_Hooks::hookLoop(uint32_t num, uint32_t cnt) { | |||||
uint32_t MHook_Hooks::hookLoop(uint32_t x) { | |||||
g_mhook->loop = true; | g_mhook->loop = true; | ||||
return trueLoop(num, cnt); | |||||
return trueLoop(x); | |||||
} | } | ||||
uint32_t MHook_Hooks::hookTail_recursion(uint32_t x) { | uint32_t MHook_Hooks::hookTail_recursion(uint32_t x) { |
uint64_t hookRip_relative(void); | uint64_t hookRip_relative(void); | ||||
void hookAVX(float num, void* res); | void hookAVX(float num, void* res); | ||||
uint32_t hookRDRAND(void); | uint32_t hookRDRAND(void); | ||||
uint32_t hookLoop(uint32_t num, uint32_t cnt); | |||||
uint32_t hookLoop(uint32_t x); | |||||
uint32_t hookTail_recursion(uint32_t x); | uint32_t hookTail_recursion(uint32_t x); | ||||
}; | }; | ||||
friend void MHook_Hooks::hookAVX(float num, void* res); | friend void MHook_Hooks::hookAVX(float num, void* res); | ||||
friend uint32_t MHook_Hooks::hookRDRAND(void); | friend uint32_t MHook_Hooks::hookRDRAND(void); | ||||
friend uint32_t MHook_Hooks::hookLoop(uint32_t num, uint32_t cnt); | |||||
friend uint32_t MHook_Hooks::hookLoop(uint32_t x); | |||||
friend uint32_t MHook_Hooks::hookTail_recursion(uint32_t x); | friend uint32_t MHook_Hooks::hookTail_recursion(uint32_t x); | ||||
}; | }; |
return trueRDRAND(); | return trueRDRAND(); | ||||
} | } | ||||
uint32_t MinHook_Hooks::hookLoop(uint32_t num, uint32_t cnt) { | |||||
uint32_t MinHook_Hooks::hookLoop(uint32_t x) { | |||||
g_MinHook->loop = true; | g_MinHook->loop = true; | ||||
return trueLoop(num, cnt); | |||||
return trueLoop(x); | |||||
} | } | ||||
uint32_t MinHook_Hooks::hookTail_recursion(uint32_t x) { | uint32_t MinHook_Hooks::hookTail_recursion(uint32_t x) { |
uint64_t hookRip_relative(void); | uint64_t hookRip_relative(void); | ||||
void hookAVX(float num, void* res); | void hookAVX(float num, void* res); | ||||
uint32_t hookRDRAND(void); | uint32_t hookRDRAND(void); | ||||
uint32_t hookLoop(uint32_t num, uint32_t cnt); | |||||
uint32_t hookLoop(uint32_t x); | |||||
uint32_t hookTail_recursion(uint32_t x); | uint32_t hookTail_recursion(uint32_t x); | ||||
}; | }; | ||||
friend void MinHook_Hooks::hookAVX(float num, void* res); | friend void MinHook_Hooks::hookAVX(float num, void* res); | ||||
friend uint32_t MinHook_Hooks::hookRDRAND(void); | friend uint32_t MinHook_Hooks::hookRDRAND(void); | ||||
friend uint32_t MinHook_Hooks::hookLoop(uint32_t num, uint32_t cnt); | |||||
friend uint32_t MinHook_Hooks::hookLoop(uint32_t x); | |||||
friend uint32_t MinHook_Hooks::hookTail_recursion(uint32_t x); | friend uint32_t MinHook_Hooks::hookTail_recursion(uint32_t x); | ||||
}; | }; |
return trueRDRAND(); | return trueRDRAND(); | ||||
} | } | ||||
uint32_t PolyHook_Hooks::hookLoop(uint32_t num, uint32_t cnt) { | |||||
uint32_t PolyHook_Hooks::hookLoop(uint32_t x) { | |||||
g_PolyHook->loop = true; | g_PolyHook->loop = true; | ||||
return trueLoop(num, cnt); | |||||
return trueLoop(x); | |||||
} | } | ||||
uint32_t PolyHook_Hooks::hookTail_recursion(uint32_t x) { | uint32_t PolyHook_Hooks::hookTail_recursion(uint32_t x) { |
uint64_t hookRip_relative(void); | uint64_t hookRip_relative(void); | ||||
void hookAVX(float num, void* res); | void hookAVX(float num, void* res); | ||||
uint32_t hookRDRAND(void); | uint32_t hookRDRAND(void); | ||||
uint32_t hookLoop(uint32_t num, uint32_t cnt); | |||||
uint32_t hookLoop(uint32_t x); | |||||
uint32_t hookTail_recursion(uint32_t x); | uint32_t hookTail_recursion(uint32_t x); | ||||
}; | }; | ||||
friend void PolyHook_Hooks::hookAVX(float num, void* res); | friend void PolyHook_Hooks::hookAVX(float num, void* res); | ||||
friend uint32_t PolyHook_Hooks::hookRDRAND(void); | friend uint32_t PolyHook_Hooks::hookRDRAND(void); | ||||
friend uint32_t PolyHook_Hooks::hookLoop(uint32_t num, uint32_t cnt); | |||||
friend uint32_t PolyHook_Hooks::hookLoop(uint32_t num); | |||||
friend uint32_t PolyHook_Hooks::hookTail_recursion(uint32_t x); | friend uint32_t PolyHook_Hooks::hookTail_recursion(uint32_t x); | ||||
}; | }; |
typedef uint32_t (*TypeRDRAND)(void); | typedef uint32_t (*TypeRDRAND)(void); | ||||
typedef uint32_t (*TypeLoop)(uint32_t num, uint32_t cnt); | |||||
typedef uint32_t (*TypeLoop)(uint32_t num); | |||||
typedef uint32_t (*TypeTailRecursion)(uint32_t x); | typedef uint32_t (*TypeTailRecursion)(uint32_t x); |