Developing Mobile Substrate tweaks
Asked Answered
C

2

9

I have a few questions about developing mobile substrate tweaks.
First of all, how do you make them?

Do you have to use XCode?

What kind of files are needed and where do you place your code?

How do you hook into an app?

For example if I want to change something in the Messages app, how could I program it to hook into Messages.app?

I am pretty familiar with developing regular apps for the app store, and I am very interested in mobile substrate. I would really like to know how to do it and where to start. Thanks!

Cowpea answered 18/8, 2011 at 4:23 Comment(0)
R
12

By far, the easiest way to develop MS tweaks is to use Theos

Follow the instructions given on the link above to install theos, navigate to the folder you want to store the project in and run $THEOS/bin/nic.pl to generate a template for your tweak.

The generated Tweak.xm file is where you put your code. To build the project just navigate to the project directory in Terminal and run make. If have dpkg on your system, then you can package up and install the project easily. Make sure OpenSSH is installed on your iDevice and add this line to your project's makefile:

THEOS_DEVICE_IP = [INSERTDEVICESIPHERE]

Then run make package install to build your project, package it in a .deb, transfer it over to your device and install it.

The code that actually goes in the Tweak.xm file is objective-C with a language that simplifies Mobile Substrate tasks called Logos, which is explained here: http://iphonedevwiki.net/index.php/Logos. Generally though, the code follows this format:

%hook classname //declares the class from your application you're going to override

-(void)functionyouwanttooveride {

    dosomethingnew(); //put all your new code for the method here
    return %orig;     //this calls the original definition of the method and returns the result
}
%end //end hooking classname

To find out what classes and methods you need to override to do whatever you want to do, install class-dump from cydia, ssh into your device and run class-dump -H path/to/your/binary -o /path/where/you/want/your/classheaders. Then you just have to look through the resulting headers to find classes and methods that have names that seem relevant to what you're doing, and experiment with them.

Good luck!

Retaliate answered 27/8, 2011 at 12:31 Comment(5)
Thank you dude! But how can i find out any functionyouwanttooverride ? How can I get the original code for the function, so that i can modify it?Cowpea
No worries! That's the tough bit, you don't have the source code so you can't ever see the implementation of any of the functions, so it takes a lot of guesswork. If you install the "syslogd to /var/log/syslog" package from cydia then if you can use %log in your code and it will write to the syslog (located at /var/log/syslog) that the method had been called, and record what arguments it was called with to give you a better idea of what's going on. Also install gdb from cydia and you can set breakpoints on interesting methods to find out what's happening. It's tough, just keep experimenting!Retaliate
Also note though, once writing to syslog is enabled, lots of other processes will also write to it and it fills up fairly quick and might eat up a bit of space, so you may want to delete it every now and then or disable logging when you don't need it, you can see more about that at theiphonewikiRetaliate
ok, and what if i wanted to change something in a specific app, like add a button to the photos app or something like that?Cowpea
Not entirely sure, but I guess you just have to hook the view you're wanting to add a button to, override the method that draws it and and add the code to draw your own new button. For example, see how DarkMalloc adds a button to a UIActionSheet in his Glue tweak by calling addButtonWithTitleRetaliate
B
7

I wrote a MobileSubstrate tweak tutorial on my blog If you follow it, I hope you find it useful!

Biquadrate answered 6/7, 2012 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.