Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1.5 KB

hookf.md

File metadata and controls

47 lines (32 loc) · 1.5 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.

CGFontRef (*orig_CGFontCreateWithFontName)(CFStringRef);
CGFontRef new_CGFontCreateWithFontName(CFStringRef name) {
  return orig_CGFontCreateWithFontName(name);
}

__attribute__((constructor)) static void initialize() {
  MSHookFunction(((void *)MSFindSymbol(NULL, "CGFontCreateWithFontName")), (void *)new_CGFontCreateWithFontName, (void **)&orig_CGFontCreateWithFontName);
}

For further information about %hookf, please go here.

Previous Page (Old ABI)

Next Page (%subclass Wrapper)