LilacExample Objective-C & Logos

To demonstrate how to use Substrate to build an extension, we will now walk through the implementation of a concrete example: an extension that modifies the color of numerous interface components to become shades of lilac. This extension is useless, but has the advantage of being immediately noticeable.

This example uses Logos, a preprocessor that accepts a superset of Objective-C and generates code that uses Substrate to hook methods of Objective-C classes. The syntax it provides is declarative, and makes it very easy for developers to write Substrate extensions. Please see its documentation.

Step 1: Filter Configuration

The code for UIColor is in a library called UIKit, which has the bundle identifier

See Also:

Code Deployment: iOS / Darwin
Property Lists

Filter = {
    Bundles = ("");

Step 2: Modify Implementation

Logos provides declarative syntax for specifying hooks. This syntax is very similar to Objective-C, but uses % instead of @ for new keywords.

We call the original code using %orig, modifying the arguments, removing all green from the color and jacking up the red (yielding shades of lilac).

See Also:

Logos Documentation

%hook UIColor

- (id) initWithRed:(CGFloat)red
    return %orig(1, 0, blue, alpha);