Browse Source

simplify _loop so that the "prologe" is shorter and the jump is back into

the first < 5 bytes
master
aaaaaa aaaaaaa 6 years ago
parent
commit
2048bdb6e1
10 changed files with 25 additions and 29 deletions
  1. +6
    -9
      test_cases/backwards.asm
  2. +2
    -3
      test_cases/backwards.h
  3. +4
    -4
      test_cases/main.cpp
  4. +2
    -2
      tester/mhook.cpp
  5. +2
    -2
      tester/mhook.h
  6. +2
    -2
      tester/minhook.cpp
  7. +2
    -2
      tester/minhook.h
  8. +2
    -2
      tester/polyhook.cpp
  9. +2
    -2
      tester/polyhook.h
  10. +1
    -1
      tester/typedefs.h

+ 6
- 9
test_cases/backwards.asm View File



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

+ 2
- 3
test_cases/backwards.h View File

#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

+ 4
- 4
test_cases/main.cpp View File

} }


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);

+ 2
- 2
tester/mhook.cpp View File

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) {

+ 2
- 2
tester/mhook.h View File

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);
}; };

+ 2
- 2
tester/minhook.cpp View File

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) {

+ 2
- 2
tester/minhook.h View File

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);
}; };

+ 2
- 2
tester/polyhook.cpp View File

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) {

+ 2
- 2
tester/polyhook.h View File

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);
}; };

+ 1
- 1
tester/typedefs.h View File



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);

Loading…
Cancel
Save