美文网首页
iOS App Hook(微信) 之 JSPatch

iOS App Hook(微信) 之 JSPatch

作者: 洪哥 | 来源:发表于2016-12-06 16:16 被阅读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

    相关文章

      网友评论

          本文标题:iOS App Hook(微信) 之 JSPatch

          本文链接:https://www.haomeiwen.com/subject/thsrmttx.html