9.Deb包介紹
官網(wǎng):http://www.debian.org/doc/debian-policy/
deb包本質是一個壓縮包文件。里面包含一些特定的目錄和文件会涎。安裝過程就是dpkg程序按照指定的規(guī)則去拷貝文件和執(zhí)行腳本裹匙。
dpkg -c xxxx.deb //查看deb包的目錄結構
-
DEBIAN目錄
存放control文件、及安裝和卸載時需要執(zhí)行的腳本等- control文件導出末秃。概页。
//deb包的名字,卸載和查詢包信息都用這個名字 Package: com.iosre.myfirstreproject //工程名字(產(chǎn)品名字) Name: MyFirstReProject //依賴包(可以指定多個练慕,用','分割) Depends: mobilesubstrate, firmware (>=8.0) //deb包版本號 Version: 1.0.1 //描述軟件所支持的平臺架構 Architecture: iphoneos-arm //deb包簡介 Description: My first reproject! //deb包維護人和聯(lián)系方式 Maintainer: luz<1048056374@qq.com> //軟件作者 Author: luz //deb包歸屬類別 Section: Tweaks //軟件主頁 Homepage: https://www.baidu.com
- 腳本文件
preinst 在Deb包文件解包之前惰匙,將會運行該腳本。許多“preinst”腳本的任務是停止作用于待升級軟件包的服務铃将,直到軟件包安裝或升級完成项鬼。 postinst 該腳本的主要任務是完成安裝包時的配置工作。許多“postinst”腳本負責執(zhí)行有關命令為新安裝或升級的軟件重啟服務劲阎。 prerm 該腳本負責停止與軟件包相關聯(lián)的daemon服務绘盟。它在刪除軟件包關聯(lián)文件之前執(zhí)行。 postrm 該腳本負責修改軟件包鏈接或文件關聯(lián)悯仙,或刪除由它創(chuàng)建的文件龄毡。
-
dpkg打包時會復制當前目錄下layout目錄下的所有文件和目錄
這些文件和目錄會鏡像到目標設備上(layout相對于設備的根目錄)//發(fā)布時的Makefile DEBUG = 0 THEOS_DEVICE_IP = 10.171.4.22 ARCHS = armv7 arm64 TARGET = iphone:latest:8.0 include $(THEOS)/makefiles/common.mk TWEAK_NAME = MyFirstReProject MyFirstReProject_FILES = Tweak.xm MyFirstReProject_FRAMEWORKS = UIKit include $(THEOS_MAKE_PATH)/tweak.mk clean:: rm -rf ./packages/* before-package:: cp ./script/postinst ./.theos/_/DEBIAN/ cp ./script/postrm ./.theos/_/DEBIAN/
10. 常見Logos語法介紹
維基百科:http://iphonedevwiki.net/index.php/Logos
10.1 Block-level
-
%hook
指定需要hook的class,必須以%end結尾∥ⅲ可以被%group包含%hook SBApplicationController -(void)uninstallApplication:(SBApplication *)application { NSLog(@"Hey, we're hooking uninstallApplication:!"); %orig; // Call the original implementation of this method return; } %end
-
%group
該指令用于將%hook分組沦零,便于代碼管理及按條件初始化分組价认,必須以%end結尾峡眶。
一個%group可以包含多個%hook,所有不屬于某個自定義group的%hook會被隱式歸類到%group_ungrouped中端衰。%group iOS8 %hook IOS8_SPECIFIC_CLASS // your code here %end // end hook %end // end group ios8 %group iOS9 %hook IOS9_SPECIFIC_CLASS // your code here %end // end hook %end // end group ios9 %ctor { if (kCFCoreFoundationVersionNumber > 1200) { %init(iOS9); } else { %init(iOS8); } }
-
%new
在%hook內(nèi)部使用蹋砚,給一個現(xiàn)有class添加新函數(shù),功能與class_addMethod相同珊膜。
注: Objective-C的category與class_addMethod的區(qū)別: 前者是靜態(tài)的而后者是動態(tài)的瓶佳。%hook SBApplicationController -(void)uninstallApplication:(SBApplication *)application { NSLog(@"Hey, we're hooking uninstallApplication:!"); %orig; // Call the original implementation of this method return; } %new - (void)namespaceNewMethod { NSLog(@"We've added a new method to SpringBoard."); } %end
10.2 Top level
%ctor
tweak的構造函數(shù),完成初始化工作逢艘;如果不顯示定義丈牢,Theos會自動生成一個%ctor,并在其中調用%init(_ungrouped)。%dtor
tweak的構造函數(shù),完成收尾瞄沙。如果不顯示定義己沛,Theos會自動生成一個%dtor。
10.3 Function level
%init
該指令用于初始化某個%group距境,必須在%hook或%ctor內(nèi)調用申尼;如果帶參數(shù),則初始化指定的group垫桂,如果不帶參數(shù)师幕,則初始化_ungrouped.
注: 切記,只有調用了%ini,對應的%group才能起作用!
···
%ctor {
if (kCFCoreFoundationVersionNumber > 1200) %init(iOS9);
else %init(iOS8);
}
···-
%c
該指令的作用等同于objc_getClass或NSClassFromString,即動態(tài)獲取一個類的定義霹粥,在%hook或%ctor內(nèi)使用 灭将。%hook SpringBoard - (void)_menuButtonDown:(id)down { %orig; SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance]; [shotter saveScreenshot:YES]; } %end@
%log
該指令在%hook內(nèi)部使用,將函數(shù)的類名后控、參數(shù)等信息寫入syslog,可以%log([(),…..])的格式追加其他打印信息庙曙。%orig
該指令在%hook內(nèi)部使用,執(zhí)行被hook的函數(shù)的原始代碼浩淘;也可以用%orig更改原始函數(shù)的參數(shù)捌朴。
//練習
@interface SBScreenshotter: NSObject
+ (id)sharedInstance;
- (void)saveScreenshot: (BOOL)arg1;
@end
@interface SpringBoard
+ (void)_AutoScreenSave2;
- (void)_AutoScreenSave;
@end
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)application
{
%orig;
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Hello,Tanzhou!"
message:nil
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
%new
- (void)_AutoScreenSave
{
NSLog(@"instance method");
SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
[shotter saveScreenshot:YES];
}
%new
+ (void)_AutoScreenSave2
{
NSLog(@"class method");
SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
[shotter saveScreenshot:YES];
}
- (void)_menuButtonDown:(id)down
{
//SBScreenShotter *shotter = [%c(SBScreenShotter) sharedInstance];
//[shotter saveScreenshot:YES];
//[self _AutoScreenSave];
[%c(SpringBoard) _AutoScreenSave2];
NSLog(@"x=%d, y=%d", 10, 20);
%log((NSString *)@"iOSRE", (NSString *)@"Debug");
%orig; // call the original _menuButtonDown:
}
%end
%hook SBLockScreenDateViewController
- (void)setCustomSubtitleText:(id)arg1 withColor:(id)arg2
{
/*
NSDate *date=[NSDate date];
NSDateFormatter *format1=[[NSDateFormatter alloc]init];
[format1 setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSString *str1=[format1 stringFromDate:date];
*/
struct tm *loctime;
char timeBuf[1024] = {0};
time_t now = time(NULL);
loctime = localtime(&now);
strftime(timeBuf, 30, "[%Y/%m/%d %H:%M:%S]", loctime);
%orig([NSString stringWithUTF8String:timeBuf],arg2);
}
%end
/*
%group HookTest
%hook SpringBoard
- (void)_lockButtonDown:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2
{
NSLog(@"_lockButtonDown");
}
- (void)_lockButtonUp:(struct __IOHIDEvent *)arg1 fromSource:(int)arg2
{
NSLog(@"_lockButtonUp");
}
- (void)powerDownCanceled:(id)arg1
{
NSLog(@"powerDownCanceled");
%orig;
}
- (void)powerDown
{
NSLog(@"powerDown");
}
- (void)powerDownRequested:(id)arg1
{
NSLog(@"powerDownRequested");
}
%end
%end
*/
%ctor
{
%init(_ungrouped);
//%init(HookTest);
}