iHabrTweak git:(master) theos/bin/nic.pl NIC 2.0 - New Instance Creator ------------------------------ [1.] iphone/application [2.] iphone/library [3.] iphone/preference_bundle [4.] iphone/tool [5.] iphone/tweak Choose a Template (required): 5 Project Name (required): iHabrTweak Package Name [com.yourcompany.ihabrtweak]: com.silvansky.ihabr Author/Maintainer Name [Valentine Silvansky]: silvansky [iphone/tweak] MobileSubstrate Bundle filter [com.apple.springboard]: Instantiating iphone/tweak in ihabrtweak/... Done.
iHabrTweak git:(master) ✗ cd ihabrtweak ihabrtweak git:(master) ✗ ls Makefile Tweak.xm control iHabrTweak.plist theos
export ARCHS=armv7 export TARGET=iphone:latest:4.3 export THEOS="`pwd`/theos" export SDKVERSION=6.0 export THEOS_DEVICE_IP=192.168.2.2
ARCHS
indicates to us that we will only collect for armv7, and on armv6 we will score. TARGET
tells us what we will build for iOS using the latest (in the system) SDK and with compatibility from version 4.3. The remaining three are self-evident. ihabrtweak git:(master) ✗ make Making all for tweak iHabrTweak... Preprocessing Tweak.xm... Compiling Tweak.xm... Linking tweak iHabrTweak... Stripping iHabrTweak... Signing iHabrTweak... ihabrtweak git:(master) ✗ ls .theos/obj Tweak.xm.o iHabrTweak.dylib
ihabrtweak git:(master) ✗ make package Making all for tweak iHabrTweak... make[2]: Nothing to be done for `internal-library-compile'. Making stage for tweak iHabrTweak... dpkg-deb: building package `com.silvansky.ihabr' in `./com.silvansky.ihabr_0.0.1-1_iphoneos-arm.deb'. ihabrtweak git:(master) ✗ make package install Making all for tweak iHabrTweak... make[2]: Nothing to be done for `internal-library-compile'. Making stage for tweak iHabrTweak... dpkg-deb: building package `com.silvansky.ihabr' in `./com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb'. install.copyFile "./com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb" "com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb" root@192.168.2.2's password: com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb 100% 1454 1.4KB/s 00:00 install.exec "dpkg -i com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb" root@192.168.2.2's password: Selecting previously deselected package com.silvansky.ihabr. (Reading database ... 2516 files and directories currently installed.) Unpacking com.silvansky.ihabr (from com.silvansky.ihabr_0.0.1-2_iphoneos-arm.deb) ... Setting up com.silvansky.ihabr (0.0.1-2) ... install.exec "timeout 10s sbreload || ( ( respring || killall -9 SpringBoard ) && launchctl load /System/Library/LaunchDaemons/com.apple.SpringBoard.plist )" root@192.168.2.2's password: launchctl unload SpringBoard.plist waiting for kill(29) != 0...
%hook SomeClass -(void)someMethod { // some code goes here } %end
%hook SomeClass - (id)initWithFrame:(CGRect)frame { id result = %orig; // some custom code return result; } - (id)initWithName:(NSString *)name { id result = %orig(@"customName"); // some custom code return result; } %end
%hook SomeClass - (void)someOldMethod { // some code here } %new - (void)someNewMethod { // some more code here } %end
@interface SomeClass(NewMethods) - (void)someNewMethod; @end;
theos/include
. If they do not lie, do not forget to do this: cd theos git submodule init git submodule update
#import <SpringBoard/SBAwayView.h> #import <UIKit/UIKit.h> %hook SBAwayView -(id)initWithFrame:(CGRect)frame { id result = %orig; if (result) { // here goes the code... } return result; } %end
UIImageView *_backgroundView
for the SBSlidingAlertDisplay
class, from which SBAwayView
is inherited, we also find the method -(CGRect)middleFrame;
. But how do we get the ivar value? Let's google Find the MSHookIvar function that will do everything: #import <SpringBoard/SBAwayView.h> #import <UIKit/UIKit.h> #import <substrate.h> %hook SBAwayView -(id)initWithFrame:(CGRect)frame { id result = %orig; if (result) { CGRect labelRect = [self middleFrame]; labelRect.origin.y = labelRect.origin.y + 20.f; labelRect.size.height = 50.f; UILabel *habrLabel = [[[UILabel alloc] initWithFrame:labelRect] autorelease]; habrLabel.text = @"Hello, Habr!"; habrLabel.textColor = [UIColor colorWithRed:155.f/255.f green:182.f/255.f blue:206.f/255.f alpha:1.f]; habrLabel.opaque = NO; habrLabel.textAlignment = UITextAlignmentCenter; habrLabel.font = [UIFont boldSystemFontOfSize:36]; habrLabel.backgroundColor = [UIColor clearColor]; UIImageView *backgroundView = MSHookIvar<UIImageView *>(self, "_backgroundView"); [backgroundView addSubview:habrLabel]; } return result; } %end
SpringBoard.app git:(master) pwd /Users/silvansky/Projects/iHabrTweak/ihabrtweak/Layout/System/Library/CoreServices/SpringBoard.app SpringBoard.app git:(master) ls habr_logo_hat.png
#import <SpringBoard/SBAwayView.h> #import <UIKit/UIKit.h> #import <substrate.h> #define IMG_WIDTH 150.f #define IMG_HEIGHT 186.f %hook SBAwayView -(id)initWithFrame:(CGRect)frame { id result = %orig; if (result) { CGRect imageRect = [self middleFrame]; imageRect.origin.y = imageRect.origin.y + 20.f; imageRect.origin.x = (imageRect.size.width - IMG_WIDTH) / 2.f; imageRect.size.width = IMG_WIDTH; imageRect.size.height = IMG_HEIGHT; UIImageView *habrLogoView = [[[UIImageView alloc] initWithFrame:imageRect] autorelease]; habrLogoView.image = [UIImage imageNamed:@"habr_logo_hat"]; UIImageView *backgroundView = MSHookIvar<UIImageView *>(self, "_backgroundView"); [backgroundView addSubview:habrLogoView]; } return result; } %end
Source: https://habr.com/ru/post/164341/
All Articles