iOS App Hook(微信) 之 JSPatch

2016-12-06  本文已影响641人  洪哥

打开Xcode, 新建Project, 选择 iOSOpenDev 中 CaptainHook Tweak,
JSPatchPlatform 添加到项目中, 然后添加依赖框架:JavaScriptCore.framework, libz.1.2.8.tbd


jsPatch.mm

#import <JSPatchPlatform/JSPatch.h>

//需要hook的方法
CHDeclareClass(MicroMessengerAppDelegate);
//JSPatch初始化
CHMethod2(BOOL, MicroMessengerAppDelegate, application, id, arg1, didFinishLaunchingWithOptions, id, arg2)
{
    BOOL supBool = CHSuper(2, MicroMessengerAppDelegate, application, arg1, didFinishLaunchingWithOptions, arg2);
    
    [JSPatch startWithAppKey:@"xxx"];
    [JSPatch sync];
    
    return supBool;
}

//所有被hook的类和函数放在这里的构造函数中
CHConstructor
{
    @autoreleasepool
    {
        CHLoadLateClass(MicroMessengerAppDelegate);
        CHHook2(MicroMessengerAppDelegate, application, didFinishLaunchingWithOptions);
    }
}

选择 Generic iOS Device 然后 Build , Products 中 xxx.dylib即为最终dynamic lib文件


main.js

require('MMTableViewSectionInfo, MMTableViewCellInfo, MMTableViewInfo')

//打印所有 ViewController
defineClass('UIViewController', {
viewDidAppear:function(animated) {
            console.log(self)
        }
})    

//给 “我” 这个界面添加一个 cell
defineClass('MoreViewController', {
        addSettingSection:function() {
            self.ORIGaddSettingSection()
            var section = MMTableViewSectionInfo.sectionInfoDefaut()
            var cell = MMTableViewCellInfo.switchCellForSel_target_title_on(null, self, "Hello JSPatch", false)
            section.addCell(cell)
            var info = self.valueForKey("m_tableViewInfo")
            info.addSection(section)
    }   
})

修改 dskcpp.github.io by DSKcpp

上一篇下一篇

猜你喜欢

热点阅读