Search code examples
javascriptiosdebuggingfrida

How to call methods in Frida Gadget (JavaScript API iOS)?


i have class [ClassName] and method [- setSomething].

How can i call with JS API withount Interceptor this method?


Solution

  • Function:

    function modify_implementation(class_name, method_name, functions) {
        try {
          var methodObj = ObjC.classes[class_name][method_name]
          var old_implementation = methodObj.implementation;
    
          methodObj.implementation = ObjC.implement(methodObj, function () {
            var args = [].slice.call(arguments); // modifying Arguments object into array
    
            if(typeof functions['arguments'] === 'function') {
              functions['arguments'](args);
            }
    
            var result = old_implementation.apply(null, args);
    
            if(typeof functions['result'] === 'function') {
              result = functions['result'](result);
            }
    
            return result;
          });
        } catch (err) {
          console.log('[!] Error while hooking ' + class_name + ' [' + method_name + ']', err);
        }
    }