What is FRIDA ? Why Every Android Developer should it?

Sandeep Kella
4 min readMar 17, 2024

--

What is Frida?

  • The Swiss Army Knife of Dynamic Instrumentation: Frida is a dynamic instrumentation toolkit. Imagine it as a set of tools that let you inject custom code into running applications on the fly. This means you can modify an app’s behavior, peek into its inner workings, and even change how it functions without directly altering the app’s original code.
  • Cross-Platform Power: Frida works its magic on various platforms, including Windows, macOS, Linux, iOS, and of course, Android.

Why Frida for Android?

Frida is a popular choice for Android enthusiasts, security researchers, and those who just like to tinker because it lets you:

  • Reverse Engineer Apps: Uncover the hidden mechanisms of Android apps, even if you don’t have their source code. This is great for understanding how an app works or finding potential security vulnerabilities.
  • Bypass Restrictions: Modify an app’s behavior to disable in-app purchases, remove ads, or unlock hidden features.
  • Automate Actions: Write scripts to interact with an app automatically, perfect for testing or repetitive tasks.
  • Debug Live: Identify bugs within a running app by monitoring function calls and variable values.

Setting Up Frida on Android

  1. Root Privileges: Most Frida magic requires a rooted Android device. There are ways to get some features working without root, but you’ll have more flexibility with root access.
  2. Frida Server: Download the appropriate Frida server binary for your Android device’s architecture from Frida’s release page (https://github.com/frida/frida/releases). Push this file to your Android device (usually in /data/local/tmp/).
  3. Frida on Your Computer: Install Frida on your computer using pip: pip install frida-tools

A Simple Frida Example

Let’s say you want to intercept all network requests made by an Android app:

  1. Connect: Use adb shell to get into your Android device and start the Frida server.
  2. Identify the Target: Find the process name or ID of the app you want to work with (frida-ps -U).
  3. Write a Script: Create a JavaScript file to hook into network functions:
Java.perform(function() {
var okhttp3 = Java.use("okhttp3.OkHttpClient");
okhttp3.newCall.overload("okhttp3.Request").implementation = function(request) {
console.log("Request URL: " + request.url().toString());
var result = this.newCall(request);
return result;
}
});

4. Engage!: Attach Frida to the process: frida -U -f com.example.yourapp -l your_script.js

Now, as the app makes network requests, you’ll see the URLs logged in your console!

Just the Beginning

This is a tiny taste of Frida’s power. You can hook into functions, change variables, dump memory, and so much more.

Important Notes:

  • Frida is a powerful tool, especially on rooted devices. Use it responsibly.
  • Tampering with apps can violate terms of service — tread carefully.

Core Techniques

  1. Function Hooking:
  • The Art of Interception: Frida lets you ‘hook’ into specific functions within a running app. This means you can replace the original function with your own code to:
  • Monitor the function’s input (arguments passed to it).
  • Modify the function’s return value.
  • Log information about how a function is used.

2. Class Modification

  • Object-Oriented Manipulation: Frida lets you dynamically modify the properties and methods of Java or Kotlin classes. You can:
  • Change the values of variables within objects.
  • Call hidden or private methods.
  • Completely redefine how a class behaves.

3. Native Code Manipulation

  • Beyond Java: Frida can even dig into native code (C/C++) used in many Android apps. This is useful for:
  • Hooking into functions within the Android framework or third-party libraries.
  • Tampering with game logic or anti-debugging mechanisms (often implemented in native code).

Example Techniques

  • Bypassing SSL Pinning: Apps often use SSL pinning to prevent tools like proxies from intercepting secure traffic. With Frida, you can hook into the SSL validation functions and disable the pinning check.
  • Unlocking Premium Features: Find the function responsible for checking if a premium feature is enabled and force it to always return true.
  • Automating In-Game Actions: If a game has repetitive tasks, write a Frida script to automate them, carefully considering the game’s terms of service, of course.
  • Detailed Logging: Hook into relevant functions or classes to produce far more detailed logs than the app normally provides, useful for debugging complex issues.

Frida Scripting

Most of your interaction with Frida is through writing JavaScript code. Frida provides a rich API to interact with the target process. Key concepts:

  • Java.perform(): The workhorse for getting things done. Use it to execute code in the app’s context.
  • Java.use(): Get access to Java classes within the app you’re targeting.
  • Java.choose(): Find specific instances of classes when there are multiple possibilities.
  • Overloads: Handle functions with the same name but different argument types.

Important Notes

  • Finding What to Hook: This is the trickiest part. Use tools like decompilers (e.g., JADX) to inspect the app’s code and identify the right functions or classes to target.
  • Obfuscation: Apps may have obfuscated code to make reverse engineering harder. Frida can still be effective, but it might require more analysis.

Resources

--

--

Sandeep Kella

Android developer @PhonePe, writes about Android development and productivity.