小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。
引言
昨天讲解了如何搭建私有Cydia源来批量部署插件,今天就来聊一聊如何讲将功能独立的tweak 合并到同一个deb 包。
I、功能独立的tweak合并到同一个deb 包
搭建私有Cydia源时,发现deb 包的目录结构很简单,于是乎就产生了合并多个tweak的想法。
deb包本质是一个压缩包文件,里面包含一些特定的目录和文件.
dpkg打包时会复制当前目录下layout下所有文件和目录,layout相当于设备的根目录。
- 将tweak合并到同一个deb 包,只需将
dylib
和对应的plist
文件放到layout目录。
5 files changed, 3 insertions(+), 1 deletion(-)
create mode 100755 Layout/Library/MobileSubstrate/DynamicLibraries/SBLockScreenViewController.dylib
create mode 100644 Layout/Library/MobileSubstrate/DynamicLibraries/SBLockScreenViewController.plist
复制代码
- 在%ctor 中根据 processName 进行%init group
%ctor
必须放置于最后,否则找不到group
%ctor
{
if ([[[NSProcessInfo processInfo] processName] isEqualToString:@"knWeChat"])
%init(wxHook);
if ([[[NSProcessInfo processInfo] processName] isEqualToString:@"SpringBoard"])
%init(sbHook);
}
复制代码
II、基础知识储备:logos 语法
2.1 %ctor
-
tweak的constructor,完成初始化工作;如果不显示定义,Theos会自动生成一个%ctor,并在其中调用%init(_ungrouped)。
-
%ctor一般可以用来初始化%group,以及进行MSHookFunction等操作
2.2 %group
-
该指令用于将%hook分组,便于代码管理及按条件初始化分组,必须以%end结尾。
-
一个%group可以包含多个%hook,所有不属于某个自定义group的%hook会被隐式归类到%group_ungrouped中。
2.3 %init
该指令用于初始化某个%group,必须在%hook或%ctor内调用;如果带参数,则初始化指定的group,如果不带参数,则初始化_ungrouped.
只有调用了%init,对应的%group才能起作用!
2.4 %property
如果你想使用全局变量,推荐你尝试应用下这个熟悉。
-
Add a property to a %subclass just like you would with @property to a normal Objective-C subclass as well as adding new properties to existing classes within %hook.
-
%property (nonatomic|assign|retain|copy|weak|strong|getter|setter) Type name;
2.5 %subclass
-
Subclass block - the class is created at runtime and populated with methods. ivars are not yet supported (use associated objects).
-
The %new specifier is needed for a method that doesn't exist in the superclass. To instantiate an object of the new class, you can use the %c operator.
-
Can be inside a %group block.
see also
更多内容请关注 #小程序:iOS逆向
,只为你呈现有价值的信息,专注于移动端技术研究领域。