飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 6681|回复: 14

[iOS] 【教程3】iOS7通知中心插件框架从逆向到实现(By飘云)

[复制链接]
  • TA的每日心情
    开心
    2016-6-16 14:07
  • 签到天数: 10 天

    [LV.3]偶尔看看II

    发表于 2014-9-25 17:52:49 | 显示全部楼层 |阅读模式
    iOS7通知中心插件框架从逆向到实现
    By飘云)
    https://www.chinapyg.com


    问题来源
    看到很多消息中心插件非常酷,假设我们现在完全不知道怎么写这样的越狱插件程序,只能通过其他的方法来挖掘他


    参考实例
    通过观察我们看到通知中心有个“股票”插件存在
    通过搜索引擎我们学习到:
    /System/Library/WeeAppPlugins/ 存放的是通知中心的一些插件,并且为*.bundle
    “股票”软件存在于:
    /System/Library/WeeAppPlugins/StocksWeeApp.bundle


    分析过程
    我们将StocksWeeApp 主程序 info.plist 配置文件导出来

    1.png

    现在打开plist来观察下:

    <?xml version="1.0"encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC"-//Apple//DTD PLIST 1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
             <key>AppBundleID</key>
             <string>com.apple.stocks</string>     // 这里用来显示图标,目前只能是系统自带的
             <key>BuildMachineOSBuild</key>
             <string>12C54</string>
             <key>CFBundleDevelopmentRegion</key>
             <string>English</string>
             <key>CFBundleDisplayName</key>
             <string>Stock_Widget</string> // 这里用来显示 设置à通知中心 开关项的名称,股票程序是多国语言的,所以这里默认用了英文
             <key>CFBundleExecutable</key>
             <string>StocksWeeApp</string>
             <key>CFBundleIdentifier</key>
             <string>com.apple.stocksweeapp.bundle</string>
             <key>CFBundleInfoDictionaryVersion</key>
             <string>6.0</string>
             <key>CFBundleName</key>
             <string>StocksWee App</string>
             <key>CFBundlePackageType</key>
             <string>BNDL</string>
             <key>CFBundleShortVersionString</key>
             <string>1.0</string>
             <key>CFBundleSignature</key>
             <string>????</string>
             <key>CFBundleSupportedPlatforms</key>
             <array>
                       <string>iPhoneOS</string>
             </array>
             <key>CFBundleVersion</key>
             <string>1</string>
             <key>DTCompiler</key>
             <string>com.apple.compilers.llvm.clang.1_0</string>
             <key>DTPlatformBuild</key>
             <string>11D201c</string>
             <key>DTPlatformName</key>
             <string>iphoneos</string>
             <key>DTPlatformVersion</key>
             <string>7.1</string>
             <key>DTSDKBuild</key>
             <string>11D201c</string>
             <key>DTSDKName</key>
             <string>iphoneos7.1.internal</string>
             <key>DTXcode</key>
             <string>0501</string>
             <key>DTXcodeBuild</key>
             <string>5A2053</string>
             <key>MinimumOSVersion</key>
             <string>7.1</string>
             <key>SBUIWidgetViewControllers</key>
             <dict>
                       <key>SBUIWidgetIdiomNotificationCenterToday</key>
                       <string>StocksWeeAppController</string>
             </dict>  // 这一段表示显示在“今日”列表下,主类为StocksWeeAppController
             <key>UIDeviceFamily</key>
             <array>
                       <integer>1</integer>
                       <integer>2</integer>
             </array>
    </dict>
    </plist>

    上面关键地方我已经用红色标记了


    OK了,现在我们class-dump来导出StocksWeeApp

    用法:
    Class-dump –a –A -H StocksWeeApp –o Headers

    得到以下文件:

    2.png

    现在我们打开StocksWeeAppController 看个究竟:
    3.png

    OK啦,豁然开朗了,知道消息中心要用到 _SBUIWidgetViewController类。

    而且看到熟悉的初始化方法:
    -(id)initWithNibName:(id)nibNamebundle:(id)bundle;   // 0x2599

    这个属于私有库:SpringBoardUIServices/_SBUIWidgetViewController.h

    国外大神已经导出头文件了,详见:


    OK了,现在我们从私有库里面看到下面几个文件
    4.png

    打开_SBUIWidgetViewController.h
    5.png

    可以看到:
    1. _SBUIWidgetViewController  基于UIViewController
    2.“股票软件都是实现/覆盖上面的某些方法

    然而初级阶段我们要实现的就是:
    @property(readonly, nonatomic) structCGSize preferredViewSize;
    这个从意思来说,应该是控制区域大小的

    梳理流程
    好了,现在为止分析完毕了,我们来梳理一下流程:

    我们要编写一个程序来实现私有库 SpringBoardUIServices/_SBUIWidgetViewController.h
    - (CGSize) preferredViewSize;
    -(id)initWithNibName:(id)nibNamebundle:(id)bundle;   

    从而在消息中心显示www.chinapyg.com” 字样,并且在设置中可控

    编码过程
    现在我们把私用库中下面三个文件保存到一个目录
    _SBUIWidgetViewController.h
    _SBUIWidgetViewController_Host_IPC-Protocol.h
    _SBUIWidgetViewController_Remote_IPC-Protocol.h

    改名为:
    _SBUIWidgetViewController.h
    _SBUIWidgetViewController_Host_IPC.h
    _SBUIWidgetViewController_Remote_IPC.h

    创建工程
    现在Xcode 选择NotificationCenterWidget模板,新建一工程,命名为ShowIP(为下节课做准备啊)
    6.jpg

    删除自动生成的代码、并且删除BBWeeAppController.h文件、导入上面三个头文件到工程

    编写代码
    7.jpg
    并且导入私有SpringBoardUIServices

    私有库提取
    8.jpg


    Plist内容
    9.jpg

    现在build,然后安装到手机测试!怎么真机直接安装可以搜索论坛帖子!

    效果测试
    10.jpg 11.jpg


    ShowIP.zip

    80.93 KB, 下载次数: 6, 下载积分: 飘云币 -2 枚

    源代码

    iOS7消息中心插件从逆向到实现.zip

    632.34 KB, 下载次数: 9, 下载积分: 飘云币 -2 枚

    word文档

    评分

    参与人数 2威望 +12 飘云币 +8 收起 理由
    a74909898 + 4 赞一个!
    Dxer + 8 + 8 飘哥又出新品了。谢谢

    查看全部评分

    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2015-8-23 23:49
  • 签到天数: 27 天

    [LV.4]偶尔看看III

    发表于 2014-9-25 17:58:09 | 显示全部楼层
    沙发。。

    正好,回去用ipad试下

    点评

    沙发又被你抢了。。。GG带我学IOS吧。。  详情 回复 发表于 2014-9-25 18:01
    PYG19周年生日快乐!
  • TA的每日心情
    慵懒
    2015-8-14 00:08
  • 签到天数: 25 天

    [LV.4]偶尔看看III

    发表于 2014-9-25 18:01:39 | 显示全部楼层
    GGLHY 发表于 2014-9-25 17:58
    沙发。。

    正好,回去用ipad试下

    沙发又被你抢了。。。GG带我学IOS吧。。
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2024-3-7 15:25
  • 签到天数: 442 天

    [LV.9]以坛为家II

    发表于 2014-9-25 19:36:55 | 显示全部楼层
    有机会再学习,没环境。
    PYG19周年生日快乐!
  • TA的每日心情
    难过
    2024-3-10 19:49
  • 签到天数: 473 天

    [LV.9]以坛为家II

    发表于 2014-9-25 21:00:23 | 显示全部楼层
    看样子我的黑苹果又要上市了。我擦了
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2020-11-6 16:39
  • 签到天数: 1416 天

    [LV.10]以坛为家III

    发表于 2014-9-26 10:26:44 | 显示全部楼层
    越狱就是好啊,没有越狱,连导出文件都是个问题
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2019-3-5 08:53
  • 签到天数: 87 天

    [LV.6]常住居民II

    发表于 2014-9-26 12:17:10 | 显示全部楼层
    太厉害的 苹果也弄啊
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2022-6-7 19:27
  • 签到天数: 560 天

    [LV.9]以坛为家II

    发表于 2014-9-26 18:11:03 | 显示全部楼层
    向飘老师献上伟大的致敬,呵呵,真是无法想象,飘老师之精华。
    PYG19周年生日快乐!
  • TA的每日心情
    开心
    2021-8-20 22:36
  • 签到天数: 6 天

    [LV.2]偶尔看看I

    发表于 2014-9-27 12:11:47 | 显示全部楼层
    这个要支持下了 不过才开始学 这样还真是看不懂  o(︶︿︶)o 唉
    PYG19周年生日快乐!
  • TA的每日心情
    奋斗
    2015-10-29 08:08
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    发表于 2014-10-8 09:13:18 | 显示全部楼层
    学习了。。正在研究越狱开发。。
    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表