zoukankan      html  css  js  c++  java
  • IOS Hook 类成员变量

    It seems that in your case you are trying to use an instance variable of the class you are hooking. Modifying the instance variable does not work that way in tweaks. You have to use MSHookIvar to 'hook' an instance variable (aka ivar). Example:

    [Tweak.xm/mm]

    #import <substrate.h> // necessary
    #import <Foundation/Foundation.h>
    
    @interface TheClassYouAreHooking : NSObject {
        NSString *_exampleVariable;
    }
    - (void)doSomething;
    @end
    
    NSString *_exampleVariableHooked;
    
    %hook TheClassYouAreHooking
    - (void)doSomething 
    {
        // 'Hook' the variable
    
        exampleVariableHooked = MSHookIvar<NSString *>(self, "_exampleVariable");
    
        // The name of the hooked variable does not need to be the same
    
        exampleVariableHooked = @"Hello World";
    
        // You can do ANYTHING with the object Eg. [exampleVariableHooked release];
    
    }
    %end
    

      

    MSHookIvar can also hook stuff like BOOLs and floats etc.

    exampleVariableHooked = MSHookIvar<BOOL>(self, "_someBOOL");
    

      

    Its declared in substrate.h so you need to import that otherwise you will not be able to compile your tweak. Also as a bonus tip, I'm just reminding you that you have to put the identifier of the app/framework you're hooking in your tweakname.plist.

    So after you 'hook' the variable you can change it to suit your needs. Happy coding!

  • 相关阅读:
    Bash 小问题【待更新】
    进程动态优先级调度
    密码
    [Noi2016]优秀的拆分
    [Tjoi2016&Heoi2016]字符串
    [BZOJ 1901]Dynamic Rankings
    [HDU 2665]Kth number
    [BZOJ 4310]跳蚤
    [Sdoi2008]Sandy的卡片
    [Usaco2007 Dec]队列变换
  • 原文地址:https://www.cnblogs.com/dependence/p/4468150.html
Copyright © 2011-2022 走看看