Use Theos to make a simple mobile substrate Tweak

Source: Internet
Author: User

January 2014Mobile substrate and Theos

Mobile substrate is the work of Cydia's author Jay Freeman (@saurik), also known as Cydia substrate, whose main function is to hook an app, modify the code such as replace the implementation of the method, The tweak on Cydia are based on the mobile substrate. Currently supports iOS and Android platforms.

According to the introduction on GitHub, Theos is a cross-platform iphone makefile system. Its main function is to generate the iphone jailbreak app, tweak and other programs framework structure, and provide makefile to compile, package and install.

Required Preparation:

# # # #Mac * Install Theos, clone down from Theos's GitHub and put it in a directory where I put it /opt/ down. * Install Xcode command line Tools, which can be installed at the command prompt to install xcode-select --install or reference so to install, and then proceed to the next step. * Install dpkg, first install MacPorts, can be selected through its official website, according to its own system version. After installation, restart Terminal, execute port version , display the version number indicating the installation was successful. If prompted command not found , try to /etc/paths add the following two paths to the file: you /opt/local/bin /opt/local/sbin need to use root permissions to edit, such as with vim:. Restart the sudo vi /etc/paths terminal, enter the port version version number again, and then execute sudo port selfupdate To update, then execute sudo port install dpkg to install dpkg. The purpose of installing dpkg is to make the tweak we write into a deb bag.

jailbreaked IPhone IOS 5/6
    • Install OPENSSH, open the main interface of Cydia can see OpenSSH Access How-To as well as Root Password How-To the options, you can follow its instructions step by step installation, here do not repeat, need to remind is sure to get rid of root password, prevent others to connect to your phone via ssh. This step is for the later we connect to the phone via SSH, the Deb package installed on the phone ready.
      The mobile substrate on the iOS7 and the bug,32-bit system need to reinstall the mobile substrate after each reboot to work properly, and 64-bit seems to be available today. Recommended for temporary testing on IOS5/6 machines [2014-01-01].
    • Apt. Search for apt check in Cydia is installed, install it without installation.
    • Ldid. The full name is the link Identify Editor, and you can search for the full name installation directly in Cydia.
Create a tweak and install it on your phone

First I create a folder on the desktop mytweaks and save the tweak program that we want to create.

?  ~        cd ~/Desktop?  Desktop  mkdir mytweaks?  Desktop  cd mytweaks

Then execute the theos we just obtained to generate a tweak template:

? Mytweaks/opt/theos/bin/nic.plnic 2.0-new Instance Creator------------------------------[1.] Iphone/application[2.] Iphone/library[3.] Iphone/preference_bundle[4. Iphone/tool [5. Iphone/tweakchoose a Template  (required (required[com.yourcompany.firsttweak: com.joeyio.firsttweakauthor/ Maintainer Name [joey]:[iphone/tweak MobileSubstrate Bundle filter [com.apple.springboard]:[iphone/ Tweak List of applications to terminate upon installation  (space-separated,  '-' for none [springboard]:instantiating Iphone/tweak in firsttweak/... Done.                 

When creating the template, we chose 5 to create an iphone tweak. The other 4 options can be searched by themselves. Name Input Firsttweak, package name I enter Com.joeyio.firsttweak, the following three options are directly return to use the default value.
MobileSubstrate Bundle filterThis is a program to hook, by default, is com.apple.springboard hook Spring Board, if you want to hook other apps, here to change the app Bundleid.

OK, then our first tweak was created, as if it were not difficult at all. Go to the Firsttweak directory, use make compile, and the result may be:

?  firsttweak  while building for 6.0 will generate armv7-only binaries.Making all for tweak FirstTweak... Preprocessing Tweak.xm...Name "Data::Dumper::Purity" used only once: possible typo at /Users/qiaoxueshi/Desktop/mytweaks/firsttweak/theos/bin/logos.pl line 615. Compiling Tweak.xm... Linking tweak FirstTweak... Stripping FirstTweak... Signing FirstTweak... /bin/sh: ldid: command not found

We see there are 2 warnings, the first I did not search for what results, the second is as long as the phone installed Ldid on the line, there is no need to control it. I tried it myself, it can be installed on the phone, you can temporarily ignore, if any small partner know what reason, welcome to inform.

Before deploying to your phone, confirm that your phone and computer are in a WiFi environment and can connect to your phone via ssh by connecting to your phone via SSH under terminal, and then prompting you to enter the root password (mentioned in the SSH step above) to make sure the connection is successful and down. The phone's IP address can be seen in the WiFi settings.

ssh [email protected]手机IP地址

Then put the phone IP address in the THEOS_DEVICE_IP environment variable, so that Theos know where to install, as follows:

export THEOS_DEVICE_IP=手机IP地址

Then make package install package and install to the phone (if Cydia in the foreground, back it to the background, or the installation will fail):

? Firsttweak Make Package install/users/qiaoxueshi/desktop/mytweaks/firsttweak/theos/makefiles/targets/darwin/ Iphone.mk:41:deploying to IOS 3.0While buildingFor 6.0 'll generate armv7-only binaries. Making AllFor Tweak Firsttweak...make[2]: Nothing to beingDoneFor' Internal-library-compilemaking stage for tweak firsttweak ... dpkg-deb: A new package "Com.joeyio.firsttweak" is being created and the package file is "./com.joeyio.firsttweak_0.0.1-2_iphoneos-arm.deb ”。 install.exec "Cat >/tmp/_theos_install.deb; Dpkg-i/tmp/_theos_install.deb && Rm/tmp/_theos_install.deb "<"./com.joeyio.firsttweak_0.0.1-2_ Iphoneos-arm.deb "[email protected" ' s password:selecting previously deselected package Com.joeyio.firsttweak.  (Reading database ... 6250 files and directories currently installed.  unpacking com.joeyio.firsttweak  (from/tmp/_theos_install.deb (0.0.1-2 " killall-9 Springboard "[Email protected] ' s password:      

Installation process need to enter two phone root password, one is to the package after the Deb file to the phone, another time is kill Springboard, so that springboard restart.

After the completion of the "change" in the Cydia, turn upside down, you can see a name for the "Firsttweak" plug-in, think of the next CEO, marry mating, to the pinnacle of life, there is a little bit excited wood?

Complete a small function

So far, we haven't written a single line of code yet. Below we want to complete a small function: Add a uilabel on the lock screen display a line of text, can be your motto or other, here we show Hello, MobileSubstate!! .

Open the file under the Firsttweak directory we just created Makefile , FirstTweak_FILES = Tweak.xm add a line below FirstTweak_FRAMEWORKS = UIKit and save the file, the prefix is TWEAK_NAME the value, that is FirstTweak , pay attention to your own situation to modify. The reason for this increase is clear that the Uikit Framework is needed to increase uilabel. The entire file looks like this:

include theos/makefiles/common.mkTWEAK_NAME = FirstTweakFirstTweak_FILES = Tweak.xmFirstTweak_FRAMEWORKS = UIKitinclude $(THEOS_MAKE_PATH)/tweak.mkafter-install:: install.exec "killall -9 SpringBoard"

After this step is completed, we will find the lock screen corresponding to the Viewcontroller, and then replace it with a method, the Uilabel added to its view. The name of this Viewcontroller SBAwayController is called, SB is SpringBoard the abbreviation, do not want to be biased:). We're going to replace it with a - (void)activate method. The SBAwayController header file of the class can be found in the header file of the IOS6 private class. There is a call in the _awayView Sbawaycontroller ivar , get this Ivar need a theos in the non-existent method, well, it called MSHookIvar , this method in the default Theos substrate.h header file does not, You can get the header file that contains this method on GitHub. Download to local, overwrite the same name file under Theos/include (it is recommended to rename the original substrate.h header file).

OK, here everything has, only owe coding.

Open the file in the Firsttweak directory Tweak.xm and empty it and add the following code:

%HookSbawaycontroller-(void)Activate{%Orig();Invoke the Orignal method to do, should to do.NSLog(@"=========================================================");NSLog(@ "Hello mobilesubstrate!!");NSLog(@"=========================================================");Get _awayview via Mshookivar methodUIView*_awayview=Mshookivar<*>(Self,"_awayview");Create a lable whose width = $ and height = + and add to _awayviewFloatW=200;FloatH=100;UILabel*Label=[[UILabelAlloc]initWithFrame:CGRectMake((_awayview.Frame.Size.Width-W)/2,100,W,H)];Label.Text= @ "Hello, mobilesubstate!!" label. TextAlignment = nstextalignmentcenterlabel. BackgroundColor = [uicolor clearcolor ; label. TextColor = [uicolor whitecolor ; [_awayview addsubview:label< Span class= "P" >; }%end           

Probably explain, %hook SBAwayController and the inside of the - (void)activate method, in fact, is similar to the SBAwayController method of Swizzling activate . The method in tweak is executed when the system executes SBAwayController the activate method activate . In this method we execute first, that %orig() is, to execute the original method, to ensure that activate the original method executes first, and then executes our own code.

This activate method will be executed the first time when the lock screen is entered, and then the shutdown key will be executed in each subsequent non-lock screen.

The next step is to MSHookIvar obtain _awayView . Then we are very familiar with, create a uilabel, add to the _awayView . It's over by here. make package install(you need to do it first export THEOS_DEVICE_IP=手机IP地址 ), install it on your phone, and wait for springboard to restart, you'll see a similar interface:

Connect the phone to the computer, open Xcode, in the Organizer console can see the program using NSLog printing information, for debugging is very convenient.

Summarize

This article is mainly about the role of mobile substrate and how to use Theos to develop a simple tweak. With these introductory basics, you can write your favorite tweak according to your own ideas. If you are iOS7 under the prison, you can try to hide the control center airdrop and music player, so that the control center looks more concise. Then can be improved, such as when the Bluetooth is turned off when the airdrop is not displayed, when the opening is still displayed, the music is playing when the music player is displayed, otherwise it is not displayed.

This small demo is written two weeks ago, has no time to tidy up, today took time to tidy up a bit of text sent out, is a gift for their New year!

Thanks,have fun!

More about substrate and Theos
    • Iphonedevwiki
    • Theos/getting Started
    • Cydia substrate (Mobile substrate also known as Cydia substrate)

Use Theos to make a simple mobile substrate Tweak

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.