# Frida

## Java

Hooking de función.

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.<function-name>.implementation = function() {
        return this.<function-name>();
    }
});
```

Cambiar el valor de retorno de una función.

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.<function-name>.implementation = function() {
        let ret_val = this.<function-name>();
        console.log("[*] Original return value", ret_val);
        let new_ret_val = <new-value>;
        console.log("[*] New return value", new_ret_val);
        return new_ret_val;
    }
});
```

Cambiar el valor booleano de retorno de una función a `false`.

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.<function-name>.implementation = function() {
        let ret_val = this.<function-name>();
        console.log("[*] Original return value " + ret_val);        
        // Alternative 1
        let new_ret_val = false;
        // Alternative 2        
        let new_ret_val = Java.use("java.lang.Boolean").$new(false);
        console.log("[*] New return value " + new_ret_val);
        return new_ret_val;
    }
});
```

Ejecutar método estático (static method).

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.<method-name>();
});
```

Cambiar el valor de una variable.

```javascript
Java.perform(function (){
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.<variable-name>.value = <new-value>;
});
```

Ejecutar método de una clase no estática.

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    var classInstance = classRef.$new();
    classInstance.<method-name>();
});
```

Hooking de constructor.

```javascript
Java.perform(function() {
    var classRef = Java.use("<package-name>.<class-name>");
    classRef.$init.implementation = function() {
        this.$init();
    }
});
```

Ejecutar método en una instancia existente.

```javascript
Java.performNow(function() {
    Java.choose("<package-name>.<class-name>", {
        onMatch: function(instance) {
        instance.<method-name>();
    },
    onComplete: function() {}
    });
});
```

Proporcionar un objeto como argumento a un método y ejecutarlo en una instancia existente.

```javascript
Java.performNow(function() {
    Java.choose("<package-name>.<class-name>", {
        onMatch: function(instance) {
            var classRef = Java.use("<package-name>.<class-name>");
            var obj = classRef.$new();
            obj.<variable-name>.value = <value>;
            instance.<method-name>(obj);
        },
        onComplete: function() {}
    });
});
```

## Native libraries


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mobile.mrw0l05zyn.cl/android/analisis-dinamico/hooking/frida.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
