如果需要使用插件图形化管理软件,请点击macOS的SIMBL插件管理器mySIMBL。
一、EasySIMBL简介
- 存在问题:某些应用只能提供90%我要用的功能。
- 解决方法:自己重新开发一个应用。
- 更好的解决方法:给应用编写插件打补丁。
EasySIMBL(Easy SIMple Bundle Loader)是Mac上的一个工具,能够很方便地把插件注入到目标应用里,从而使应用能按我们想要的方式运行。
二、安装EasySIMBL
EasySIMBL需要安装到/System/Library/ScriptingAdditions/
路径,但是由于Mac OS X 10.11 启用了SIP,没有权限修改该路径下的文件,因此安装之前要先关闭SIP。
安装步骤为:
1、关闭SIP:重启系统,开机时按住 command + R 不放,直到进入恢复模式。
点击实用工具菜单,打开终端,执行csrutil disable
命令,再重启系统。
2、点击SIMBL-0.9.9.zip下载文件并解压。
3、打开终端,cd到SIMBL-0.9.9
目录,执行以下命令:
sudo installer -verbose -pkg SIMBL-0.9.9.pkg -target /
sudo rm -rf /System/Library/ScriptingAdditions/SIMBL.osax
sudo mv /Library/ScriptingAdditions/SIMBL.osax /System/Library/ScriptingAdditions/
sudo cp -p /System/Library/ScriptingAdditions/SIMBL.osax/Contents/Resources/SIMBL\ Agent.app/Contents/Resources/net.culater.SIMBL.Agent.plist /System/Library/LaunchAgents/
sudo sed -e "s/Library/System\/Library/" -i "" /System/Library/LaunchAgents/net.culater.SIMBL.Agent.plist
4、启用SIP:进入恢复模式,执行csrutil enable --without debug
,并重启系统。
加上--without debug
参数,才可以让lldb附加进程进行调试。
三、安装插件
可以把下载的插件放在/Library/Application Support/SIMBL/Plugins
目录里。
app启动时会自动加载插件。
四、插件开发
以系统自带的计算器Calculator.app
为例编写一个插件。
1、安装插件模板,地址为https://github.com/poboke/EasySIMBL-Bundle-Template。
2、使用Xcode创建一个Project,选择SIMBL Bundle
模板。
3、设置工程名字为CalculatorPlugin
。
打开/Applications/Calculator.app/Contents/Info.plist
,可以看到计算器的bundle identifier
为com.apple.calculator
:
下图里的Target App Bundle Id
就是我们要注入的app的包标识符,当app启动时,SIMBL就会把填有该app包标识符的插件注入到该app中。
填写后的工程信息为:
4、工程默认的初始化代码为:
#import "CalculatorPlugin.h"
@interface CalculatorPlugin()
@end
@implementation CalculatorPlugin
/**
* @return the single static instance of the plugin object
*/
+ (instancetype)sharedInstance
{
static CalculatorPlugin *plugin = nil;
@synchronized(self) {
if (!plugin) {
plugin = [[self alloc] init];
}
}
return plugin;
}
/**
* A special method called by SIMBL once the application has started and all classes are initialized.
*/
+ (void)load
{
CalculatorPlugin *plugin = [CalculatorPlugin sharedInstance];
NSLog(@"++++++++ %@ plugin loaded ++++++++", plugin);
}
加载插件时会先执行类方法load
的代码,因此可以在该方法里编写初始化的代码。
5、编辑插件的Info.plist
文件,可以看到里面有一个SIMBLTargetApplications
数组:
BundleIdentifier
: 要注入的app的包标识符MaxBundleVersion
: 要注入的app的版本号最大值,默认为99999MinBundleVersion
: 要注入的app的版本号最小值,默认为0
版本号是指CFBundleVersion
的值:
由计算器的信息可知,目前计算器的版本号是123
,而非10.8
。
处于MinBundleVersion
和MaxBundleVersion
版本号之间的app才能够加载插件。
因为app升级后可能导致插件失效,严重的话可能会导致app闪退。所以为了保证插件能够正常工作,可以使用app当前版本号的值,也就是最大值和最小值都填上123
。
不过这种情况是很少出现的,一般来说使用模板默认的0 ~ 99999
就可以了。
6、按 command + B 编译工程,编译成功后会自动在/Library/Application Support/SIMBL/Plugins
目录下生成一个CalculatorPlugin.bundle
插件。
7、先运行控制台Console.app
,再运行计算器Calculator.app
。
如果在控制台里能看到++++++++ <CalculatorPlugin: 0x7f980488e970> plugin loaded ++++++++
等字样,就说明我们的插件已经成功注入到计算器里了。
8、接下来就可以使用逆向工程的方法来修改app的逻辑了。
五、示例工程
插件模板https://github.com/poboke/EasySIMBL-Bundle-Template的Samples
目录里有一个CalculatorPlugin
示例工程。
编译该工程后,点击计算器菜单栏的 计算器 --> 关于计算器 时,会出现一个Hello world
的弹出框。
感兴趣的话可以去看工程里的代码,由于代码比较简单,这里就不多费笔墨了。
2016/08/26 15:44:43
请教下楼主,这样配置后可以单步调试插件的代码吗?????
2016/08/28 15:47:46
可以的,需要在工程的`Edit scheme`里选择要运行的应用
2016/03/22 17:28:49
环境 10.11.3
关闭 sip后,安装 simbl0.9.9 ,没有再次开启sip。
2016/03/22 17:27:17
环境 10.11.3
2016/03/02 11:33:04
Hi,我直接将编译后的bundle文件夹里面的文件拷贝到/Applications/Calculator.app/Contents/PlugIns/下是可以正常使用的!!!
目前猜测可能是bundle文件没有被引用的关系?!
2016/03/02 12:43:20
EasySIMBL的安装过程比较复杂,你可以检查一下步骤是否有错,如果没错的话,可以把插件放在 /Library/Application\ Support/SIMBL/Plugins/ 这个路径试试(注意前面没有~)。
2016/09/12 18:38:33
2016/09/13 00:13:06
在终端执行命令:open /Applications/Calculator.app/Contents/PlugIns 就可以打开目录了,再把插件复制进去。
2016/03/01 15:11:27
Hi,请问控制台没有打印需要怎么处理,都按照流程走下来的了;
2016/09/12 18:33:44
遇到同样的问题,路径也没放错,请问解决了吗?
2016/09/12 18:35:37
请问你的系统是什么版本
2016/03/01 17:38:07
你可以运行一下计算器那个例子,看有没有log
2016/03/02 09:30:21
并没有log,使用git上面的CalculatorPlugin项目也没有,编译之后~/Library/Application\ Support/SIMBL/Plugins/CalculatorPlugin.bundle是有的
2016/06/01 13:13:11
之前文章的路径有问题,需要把插件放在 /Library/Application Support/SIMBL/Plugins/(注意前面没有~)。
2016/09/18 11:51:10
是没有写权限,也不能改权限。应该是最新系统的保护
2016/09/19 08:33:34
要先关闭SIP