ソースを参照

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

the first < 5 bytes
master
aaaaaa aaaaaaa 6年前
コミット
2048bdb6e1
10個のファイルの変更25行の追加29行の削除
  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 ファイルの表示

@@ -6,16 +6,13 @@ use64

public _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
dec rbx
jmp @again
@loop_end:
nop
nop
nop
loop @loop_loop ; lol
ret

public _tail_recursion

+ 2
- 3
test_cases/backwards.h ファイルの表示

@@ -1,12 +1,11 @@
#pragma once
extern "C" {
/**
* Raises @num @cnt times
* $$ x*x * (x-1)! $$
*
* @param num
* @param cnt
*/
uint32_t _loop(uint32_t num, uint32_t cnt);
uint32_t _loop(uint32_t x);

/**
* Computes factorial

+ 4
- 4
test_cases/main.cpp ファイルの表示

@@ -32,10 +32,10 @@ TEST_CASE("Advanced instruction functions work as expected, unhokked") {
}

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(1) == 1);

+ 2
- 2
tester/mhook.cpp ファイルの表示

@@ -49,10 +49,10 @@ uint32_t MHook_Hooks::hookRDRAND(void) {
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;

return trueLoop(num, cnt);
return trueLoop(x);
}

uint32_t MHook_Hooks::hookTail_recursion(uint32_t x) {

+ 2
- 2
tester/mhook.h ファイルの表示

@@ -6,7 +6,7 @@ namespace MHook_Hooks {
uint64_t hookRip_relative(void);
void hookAVX(float num, void* res);
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);
};

@@ -25,6 +25,6 @@ public:
friend void MHook_Hooks::hookAVX(float num, void* res);
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);
};

+ 2
- 2
tester/minhook.cpp ファイルの表示

@@ -50,10 +50,10 @@ uint32_t MinHook_Hooks::hookRDRAND(void) {
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;

return trueLoop(num, cnt);
return trueLoop(x);
}

uint32_t MinHook_Hooks::hookTail_recursion(uint32_t x) {

+ 2
- 2
tester/minhook.h ファイルの表示

@@ -6,7 +6,7 @@ namespace MinHook_Hooks {
uint64_t hookRip_relative(void);
void hookAVX(float num, void* res);
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);
};

@@ -28,6 +28,6 @@ public:

friend void MinHook_Hooks::hookAVX(float num, void* res);
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);
};

+ 2
- 2
tester/polyhook.cpp ファイルの表示

@@ -49,10 +49,10 @@ uint32_t PolyHook_Hooks::hookRDRAND(void) {
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;

return trueLoop(num, cnt);
return trueLoop(x);
}

uint32_t PolyHook_Hooks::hookTail_recursion(uint32_t x) {

+ 2
- 2
tester/polyhook.h ファイルの表示

@@ -6,7 +6,7 @@ namespace PolyHook_Hooks {
uint64_t hookRip_relative(void);
void hookAVX(float num, void* res);
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);
};

@@ -58,6 +58,6 @@ public:

friend void PolyHook_Hooks::hookAVX(float num, void* res);
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);
};

+ 1
- 1
tester/typedefs.h ファイルの表示

@@ -11,6 +11,6 @@ typedef void (*TypeAVX)(float num, void* res);

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

読み込み中…
キャンセル
保存