You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.c 1.3KB

5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <stdio.h>
  2. #include "misc.h"
  3. #include "hook.h"
  4. #if 0
  5. Check whether trampoline works correctly
  6. start:
  7. je lbl1
  8. jmp lbl1
  9. lbl1:
  10. ---
  11. hook() == LOOPS_INTO_OVERWRITTEN_CODE
  12. start:
  13. mov eax, 3
  14. l:
  15. dec eax
  16. test eax, eax
  17. je l
  18. #endif
  19. static int test(int a, int b);
  20. static void normal(int a, int b, int c, int d, int e);
  21. static void normal2(int a, int b, int c, int d, int e);
  22. typedef void(*FUNCTYPE)(int a, int b, int c, int d, int e);
  23. static void hooked(int a, int b, int c, int d, int e);
  24. static FUNCTYPE original;
  25. int main(int argc, char** argv)
  26. {
  27. int r = 0;
  28. if((r = hook(normal2, 0, hooked, &original)) < 0)
  29. {
  30. printf("CAn't hook: %d\n", r);
  31. return 1;
  32. }
  33. printf("---\nDisass. trampoline/original\n");
  34. disassemble_func(original, 10);
  35. original(3, 1, 1, 1, 1);
  36. //original(5, 1, 1, 1, 1);
  37. #if WINDOWS
  38. VirtualFree(original, 0, MEM_RELEASE);
  39. #endif
  40. (void)getc(stdin);
  41. }
  42. static int test(int a, int b)
  43. {
  44. if(a == 0)
  45. return 5;
  46. else if(a == 1)
  47. return b;
  48. return a;
  49. }
  50. static void normal(int a, int b, int c, int d, int e)
  51. {
  52. printf("Result: %d\n", a*b*c*d*e);
  53. }
  54. static void normal2(int a, int b, int c, int d, int e)
  55. {
  56. if(a == 3)
  57. return;
  58. printf("Result: %d\n", a*b*c*d*e);
  59. }
  60. static void hooked(int a, int b, int c, int d, int e)
  61. {
  62. original(1, b, c, d, e);
  63. }