disableAttach.h 847 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // disableAttach.h
  3. // MCPlus
  4. //
  5. // Created by seo ha on 18/02/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. #ifndef disableAttach_h
  9. #define disableAttach_h
  10. #import <sys/mman.h>
  11. #import <dlfcn.h>
  12. typedef int (*command_ptr_t)(int _request, pid_t _pid, caddr_t _addr, int _data);
  13. #if !defined(PT_DENY_ATTACH)
  14. #define PT_DENY_ATTACH 31
  15. #endif
  16. /**
  17. 디버그 메소드 swift 에서 사용시 buildsetting - swift otherflag에 "-DDEBUG"값을 입력후
  18. 전처리문을 통해 입력
  19. ex)
  20. #if DEBUG
  21. #else
  22. //안티디버거
  23. disable_attach()
  24. #endif
  25. */
  26. //Anti-debug method
  27. void disable_attach() {
  28. void* handle = dlopen(0, RTLD_GLOBAL | RTLD_NOW);
  29. command_ptr_t command_ptr = dlsym(handle, "ptrace");
  30. command_ptr(PT_DENY_ATTACH, 0, 0, 0);
  31. dlclose(handle);
  32. }
  33. #endif /* disableAttach_h */