title: Is it possible to change the arguments of a hooked function in Frida and forward them?
body: <p>I've been playing with Frida for a couple days, but I cannot figure it out if what I'm asking is possible. Basically, I want to hook up to a function (on an Android app), change the value of the arguments and then execute the original function with the values of the arguments changed. So far, I'm able to hook up to the function, and print the values of the arg; but I cannot change their values.</p>
  
  <p>For instance, my Java function look like this:</p>
  
  <pre><code>public void myFunction(Sometype foo) {
      ...
  }
  </code></pre>
  
  <p><code>Sometype</code> is an interface, which provides a few methods to access the values (e.g. <code>getA(), getB()</code>).</p>
  
  <p>This is the Frida JS script that I'm using to hookup to the function:</p>
  
  <pre><code>    setImmediate(function () {
          console.log("[*] Starting script");
  
          // Call:
          // frida -U -l scripts/myscript.js com.somepackage
          Java.perform(function () {
  
              var target = Java.use("com.somepackage.clazz");
              target.myFunction.implementation = function(var1) {
  
                  // print: getA()
                  console.log("a:" + var1.a());
                  // print: getB()
                  console.log("b:" + var1.b());
  
                  // I tried this, but it didn't work.
                  var1.a = function () {
                      return "xxx";
                  }
  
                  // print: getA() again, but got the same value as before
                  console.log("a:" + var1.a());
  
                  this.onMessageReceived(var1);
              }
  
          });        
      });
  </code></pre>