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.
The code for UIColor is in a library called UIKit, which has the bundle identifier com.apple.UIKit.
Filter = { Bundles = ("com.apple.UIKit"); };
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).
%hook UIColor - (id) initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { return %orig(1, 0, blue, alpha); } %end