Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.87 KB

hookf.md

File metadata and controls

50 lines (34 loc) · 1.87 KB

How Do You Create a Tweak?

%hookf can be confusing at first, but it is pretty easy to understand once you get into it.

What is %hookf used for?

While %hook is used to hook Objective-C classes, %hookf is used to hook C functions. Its syntax is also different from %hook.

Syntax

%hookf(return_type, symbol_name, arguments...) {...}
  • return_type - The return type of the function.
  • symbol_name - This is the name of the function being hooked.
  • arguments - These are the arguments that are passed into the function.

Example

Let's say we want to hook CGFontRef CGFontCreateWithFontName(CFStringRef name);. This would be done like so:

%hookf(CGFontRef, CGFontCreateWithFontName, CFStringRef name) {
  // code
  return %orig;
}

Below is the Substrate version of the above code, if needed.

static CGFontRef (*CGFontCreateWithFontName_orig)(CFStringRef) = NULL;
static CGFontRef CGFontCreateWithFontName_hook(CFStringRef name) {
  return CGFontCreateWithFontName_orig(name);
}

__attribute__((constructor)) static void initialize() {
  MSHookFunction(dlsym(RTLD_DEFAULT, "CGFontCreateWithFontName"), (void *)CGFontCreateWithFontName_hook, (void **)&CGFontCreateWithFontName_orig);
}

Danger

Due to the previously mentioned Spinlock panics on iOS 15 arm64e devices, %hookf/MSHookFunction should be used with caution. When possible, look into alternative methods of achieving your esired goal in order for a better user experience for users on iOS 15 arm64e devices.

For further information about %hookf, please go here.

Previous Page (Old ABI)

Next Page (%subclass Wrapper)