# Frida

## Attacher un script

```bash
frida -U -l script.js app-name
```

## Attacher un script au lancement  de l'application avec frida-trace avec l'argument -f

```bash
frida-trace -U -m "*[* *ailbr*]" -f Identifier_app
```

## Script changer une valeur&#x20;

```javascript
var targetModule = 'app_name';
var addr = ptr(offset);
var moduleBase = Module.getBaseAddress(targetModule);
var targetAddress = moduleBase.add(addr);
   Interceptor.attach(targetAddress, {
        onEnter: function(args) {
                   console.log('Adresse de x0 ' + addr + 'Valeur  : ' + this.context.name_var);
        },
    });
```

## Script changer valeur retour

```javascript
var targetModule = 'app_name';
var addr = ptr(offset);
var moduleBase = Module.getBaseAddress(targetModule);
var targetAddress = moduleBase.add(addr);
   Interceptor.attach(targetAddress, {
        onLeave: function(retval) {
		   console.log("Valeur retourne par la methode isJailbreak : "+retval);
	           retval.replace(value);
        },
    });
```

## Script qui Hook une native Fonction et qui renvoie sa Backtrace

```javascript
Interceptor.attach(Module.findExportByName(null, "fopen"), {
    onEnter: function(args) {
	console.log("+++++++++++++++Interception de la fonction fopen+++++++++++++\n");
	//console.log(args[0].readCString());
       var backtrace= Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\n'); 
       console.log(backtrace);
    
    },
    //onLeave: function(args) {
	//console.log("+++++++Interception de la fonction fopen++++++++++++");
        //console.log("Interceptor attached onLeave...");
   // }
});

```

## Script qui hook une méthode Objective C

```javascript
var Classe = ObjC.classes.Classe;
Interceptor.attach(Classe['- method_de_classe'].implementation,{
	onEnter:function(args){
		//console.log("Interception Classe);
	}

});
```


---

# 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://ajin-1.gitbook.io/documentation/mobile/ios/outils/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.
