Skip to content
kabiroberai edited this page Dec 26, 2016 · 14 revisions

General usage

Make sure that you have installed Theos Jailed before following this guide.

  1. Extract and decrypt your target app. Save as a .ipa
  • Change to the base directory for your tweak (eg. cd ~/Desktop)
  • Run nic.pl and choose the jailed template
  • Enter a name and bundle ID for your tweak
  • Enter an absolute or relative path to your decrypted .ipa file
  • Change into your new tweak directory (eg. cd ~/Desktop/mytweak)
  • Edit Tweak.xm as necessary
  • Run make info and follow the instructions to create a Provisioning Profile
  • Run make package install [PROFILE=<your.bundle.id | file.mobileprovision>]. Omit PROFILE=… to use Xcode's Wildcard App ID

Note: Unless specified otherwise, the rest of this page requires that you cd into your tweak's root directory before running any commands.

Adding Resources

If you want to add custom resources to your project, you can create a Resources folder, and add any files to it. If you add an Info.plist file to Resources, its keys will be merged with the app's Info.plist. However, since the most common use of merging an Info.plist is setting a custom display name and bundle ID, you can also do that using the DISPLAY_NAME and BUNDLE_ID variables.

Since Theos Jailed merges the Resources folder with the app's root directory, it will override any existing files with a clashing name. Due to this, it is highly recommended that you create a <tweak name>.bundle folder in Resources to add custom files. To access your tweak's bundle, add the following to the top of Tweak.xm:

NSBundle* const kTweakBundle = [NSBundle bundleWithPath: [[NSBundle mainBundle] pathForResource: @"tweak name" ofType: @"bundle"]];

And to access files inside the bundle, use:

[kTweakBundle pathForResource: @"name" ofType: @"extension"]

Using builtin addons

The following variables can be set either in Makefile or when running the make command (make [...] VARIABLE=value). Replace TWEAK_NAME with your tweak's name, spelled exactly the way it is in Makefile. Run grep TWEAK_NAME Makefile to see the tweak name.

Cycript

Set TWEAK_NAME_USE_CYCRIPT=1 to be able to remotely attach to Cycript using cycript -r hostname:31337.

Fishhook

Set TWEAK_NAME_USE_FISHHOOK=1 to use fishhook. Remember to #import <fishhook.h> as well.

FLEX

Set TWEAK_NAME_USE_FLEX=1 to use FLEX.

Extensify Exo

Set PACKAGE_FORMAT=exo to package your project as an Extensify Exo instead of a .ipa.

Note: The FLEX and Cycript addons are themselves Theos Jailed tweaks that are automatically triggered. If you want to modify them, you may do so by editing the respective tweak in the addons directory in the root of this repository, and then running make.

Injecting a Cydia tweak

  1. Download the tweak as a .deb file. To find a website that lets you do this, search Google for something like "Cydia Updates"
  • Unpack the .deb file, using the command dpkg-deb -x file.deb destination
  • Extract and decrypt the app targeted by the Cydia tweak. Save as a .ipa
  • Create a new Theos project with the jailed template, using the decrypted .ipa
  • Copy the unpacked tweak at destination/Library/MobileSubstrate/DynamicLibraries/tweak-name.dylib to the root folder of your project, replacing tweak-name with the name of the tweak you downloaded
  • Add TWEAK_NAME_INJECT_DYLIBS = tweak-name.dylib to the top of Makefile. Doing this still compiles Tweak.xm, so you can add your own changes too
  • Follow step 9 and 10 of General usage

Changing the install path of the the dylib

You may want to change the install location of tweak-name.dylib in the app directory (eg. Foo.app/MyFrameworks instead of Foo.app/Frameworks). To do this, set the COPY_PATH variable to the path you want in your Makefile. The default value for this is Frameworks. If you do this, you will also need to update any dependency's location respectively. In this example, you'd need to replace Frameworks with MyFrameworks in steps 3 and 4 of Adding dependencies.

Adding dependencies

Many tweaks require external dependencies. To use one, you must first fix the install name of the dependency and the libraries it links against.

  1. Download and extract the dependency .deb, similar to how you downloaded the tweak
  • Create a Resources directory inside your project's root directory
  • Create a Frameworks directory inside the Resources directory, and add the dependency to that
  • Run install_name_tool -id @rpath/dependency.dylib Resources/Frameworks/dependency.dylib
  • Run otool -L tweak-name.dylib to see the current linked path to the dependency
  • Run install_name_tool -change /linked/path/to/dependency.dylib @rpath/dependency.dylib tweak-name.dylib

Note: Some dependencies (such as rocketbootstrap and uasharedtools) do not work on jailed devices, and thus tweaks that require them will not work. If you want to inject a ++ tweak, your best option is using ppsideloader, which is specifically made for that purpose.

Using frameworks

External frameworks may be of two types: static and dynamic. To find out which your framework is, run the following command:

file Foo.framework/Foo | grep -q "Mach-O dynamically linked shared library" && echo "Dynamic" || echo "Static"

Static frameworks

  1. Copy the .framework into your project's root directory
  • Open Makefile in your favourite text editor
  • Add TWEAK_NAME_FRAMEWORKS = Foo, replacing Foo with the name of your framework. If any additional frameworks are required, add them here too
  • Add any required libraries to TWEAK_NAME_LIBRARIES below the FRAMEWORKS line. For example, if I wanted to add libxyz.tbd to my project, I would add the line TWEAK_NAME_LIBRARIES = xyz
  • Import your framework in Tweak.xm using #import <Foo/Foo.h>

Dynamic frameworks

  1. Dynamic frameworks are only supported in iOS 8 and above. Add TARGET_IPHONEOS_DEPLOYMENT_VERSION = 8.0 to the beginning of your makefile
  • Follow all the steps in Static frameworks, but replace TWEAK_NAME_FRAMEWORKS with TWEAK_NAME_EMBED_FRAMEWORKS in step 3, and use the framework's path instead of its name (Foo.framework instead of Foo)

Dylib files

  1. Follow steps 1 to 4 of Static frameworks, but replace TWEAK_NAME_FRAMEWORKS with TWEAK_NAME_EMBED_LIBRARIES in step 3, and use the dylib's path instead of its name (libfoo.dylib)
  • Import your framework in Tweak.xm, using #import <foo.h>

Note: To add a framework to a subdirectory inside your project folder, you must add -Fpath/to/subdirectory to TWEAK_NAME_CFLAGS and TWEAK_NAME_LDFLAGS, and for a dylib add -Lpath/to/subdirectory to TWEAK_NAME_LDFLAGS. You need not do this if you place the framework/dylib in the project's root directory because that is already added by default.

Clone this wiki locally