iphoneobjective-cjailbreaktheoslogos

Calling a function from another class in theos(logos) Jailbreak


I'm trying to run a function from another Class in another Class.

I want to call -(void)updateClock from the Class SBAwayView

Ive tried [[%c(SBAwayDateView) sharedInstance] updateClock];

Ive also tried [%c(SBAwayDateView) updateClock]; but I can't get it to work. (the SpringBoard crashes and I'm in safemode)

Below is the SBAwayDateView Class

    %hook SBAwayDateView
    -(void)updateClock
    {
    //do some stuff

   //run %orig;
      %orig;
    }
    %end

How can I run -(void)updateClock in SBAwayView Class below?

    %hook SBAwayView
    -(void)updateInterface
    {
    //do some stuff

    //How can I run -(void)updateClock here?

   //run %orig;
      %orig;
    }
    %end

Thanks in advance.


Solution

  • SBAwayDateView doesn't have sharedInstance nor updateClock class methods.

    In cases when you are working with class that is not a singleton you need to either find valid instance of this class in some other class - it might contain it in instance variable or return from some method. Or you can hook init method and save somewhere instances yourself. Depends on what you want to do.

    In your case SBAwayView has instance variable SBAwayDateView *_dateHeaderView - problem solved

    %hook SBAwayView
    -(void)updateInterface
    {
        //do some stuff
    
        SBAwayDateView* dateView = MSHookIvar<SBAwayDateView*>(self, "_dateHeaderView");
        [dateView updateClock];
    
        //run %orig;
        %orig;
    }
    %end