Guest User

Untitled

a guest
Jan 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #ifndef SUBSTRATE_H_
  2. #define SUBSTRATE_H_
  3.  
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.     #include <mach-o/nlist.h>
  8. #ifdef __cplusplus
  9. }
  10. #endif
  11.  
  12. #include <objc/runtime.h>
  13. //#include <objc/message.h>
  14. #include <dlfcn.h>
  15.  
  16. #ifdef __cplusplus
  17. #define _default(value) = value
  18. #else
  19. #define _default(value)
  20. #endif
  21.  
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25.  
  26. void MSHookFunction(void *symbol, void *replace, void **result);
  27. IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL));
  28.  
  29. #ifdef __cplusplus
  30. }
  31. #endif
  32.  
  33. #ifdef __cplusplus
  34.  
  35. template <typename Type_>
  36. static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) {
  37.     return reinterpret_cast<Type_ *>(MSHookMessage(_class, sel, reinterpret_cast<IMP>(imp), prefix));
  38. }
  39.  
  40. template <typename Type_>
  41. static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) {
  42.     return MSHookFunction(
  43.         reinterpret_cast<void *>(symbol),
  44.         reinterpret_cast<void *>(replace),
  45.         reinterpret_cast<void **>(result)
  46.     );
  47. }
  48.  
  49. template <typename Type_>
  50.  
  51. static inline void MSHookSymbol(Type_ *&value, const char *name, void *handle) {
  52.     value = reinterpret_cast<Type_ *>(dlsym(handle, name));
  53. }
  54.  
  55. template <typename Type_>
  56. static inline Type_ &MSHookIvar(id self, const char *name) {
  57.     Ivar ivar(class_getInstanceVariable(object_getClass(self), name));
  58.     void *pointer(ivar == NULL ? NULL : reinterpret_cast<char *>(self) + ivar_getOffset(ivar));
  59.     return *reinterpret_cast<Type_ *>(pointer);
  60. }
  61.  
  62. #endif
  63.  
  64. #define MSHook(type, name, args...) \
  65.     static type (*_ ## name)(args); \
  66.     static type $ ## name(args) \
  67.  
  68. #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation"
  69. #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit"
  70. #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore"
  71. #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit"
  72.  
  73. #endif//SUBSTRATE_H_
Add Comment
Please, Sign In to add comment