Master Frida: Step-by-Step Guide to Hook Android Apps with Python

This tutorial walks you through setting up a Python virtual environment, installing Frida and frida‑server on a rooted Android device, configuring the server, verifying the connection, and writing JavaScript hooks to intercept login functions, complete with code snippets, command examples, and troubleshooting tips.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Master Frida: Step-by-Step Guide to Hook Android Apps with Python

What is Frida?

Frida is a hooking framework for native Android apps (also supports iOS and Windows). It works with apps developed in Java on Android.

What is a hook?

A hook is like digging a hole in a water pipe to intercept or modify the flow, allowing you to observe or change behavior.

Create Python virtual environment

You can quickly create a virtual environment using a simple Python environment manager. The environment name used in this guide is frida_env.

My environment

pixel 2 Android 8 (rooted) via USB
Magisk 23.0
Xposed 3.1.5
Python 3.8.6

Frida version and Android/Python compatibility

frida12.3.6  Android5-6   Python3.7
frida12.8.0  Android7-8   Python3.8
frida14+     Android9+    Python3.8

These tables are for reference only; verify against your own setup.

Frida installation

When installing Frida, use a reliable internet connection because it may download large files.

Dependencies

Install the following packages inside the virtual environment:

frida==14.2.18
frida-tools==9.2.5

Verification

After installation, run: frida --version and frida. If no errors appear, the installation succeeded.

frida‑server installation

Download frida‑server from the official releases page .

Notes

frida‑server version must match the pip‑installed Frida version.

Choose the correct platform (Android vs iOS, arm32 vs arm64, emulator, etc.).

In this guide the device is arm64, so the corresponding server is downloaded.

Push frida‑server to the phone

adb push <path>/frida-server-14.2.18-android-arm64 /data/local/tmp

Check the phone

List /data/local/tmp on the device; you should see the frida‑server file.

File exists – good.

Give frida‑server execution permission

chmod 777 frida-server-14.2.18-android-arm64

Run frida‑server

./frida-server-14.2.18-android-arm64

Keep this terminal window open; the server will wait silently.

Verification

Activate the virtual environment and run: frida-ps -U If device information appears, the connection is successful.

In summary, the workflow is:

Install Frida on the PC (virtual environment).

Push and run frida‑server on the phone.

Old version note

For Frida ≤12, you may need port forwarding:

adb forward tcp:27042 tcp:27042

Summary of Frida and frida‑server

On the PC, create a virtual environment and install Frida. On the phone, copy frida‑server to /data/local/tmp, grant execution permission, and run it.

WebStorm installation

Because Frida scripts are JavaScript, install WebStorm for code completion. Download from the official site and follow the installer.

WebStorm Frida configuration

Create an empty project, open the terminal, and run: npm i @types/frida-gum This installs type definitions for Frida, enabling auto‑completion in WebStorm (or other JetBrains IDEs).

Small test: hooking a login flow

APK

xx牛.apk

Packet capture

Using Charles or Postman, capture the login request to http://api.dodovip.com/api/user/login. The payload contains {"Encrypt":"xxx"}.

APK decompilation

The APK is not protected; search for user/login in the decompiled code and locate the login function.

Frida assisted analysis

Code

Java.perform(function () {
    console.log("开始hook");
    let loginActivity = Java.use("com.dodonew.online.ui.LoginActivity");
    loginActivity.login.implementation = function (userName, pwd) {
        console.log("login函数执行");
        console.log("userName:", userName);
        console.log("pwd:", pwd);
        return this.login(userName, pwd);
    };
});

Interpretation

Start Frida

Command

frida -U -F -l xx牛.js
    -U  connect USB device
    -F  attach to the frontmost app
    -l  inject the js script

Verify hook

Tap the login button on the phone and observe console output on the PC. The logs confirm the hook is active.

Final summary

To master hooking with Frida, follow these steps:

Create a Python virtual environment on the PC and install Frida.

Push the matching frida‑server to the Android device, grant execution rights, and run it.

Write JavaScript hook scripts and inject them with Frida.

Good luck, and feel free to leave comments for any issues.

PythonAndroidsecurityReverse engineeringHookingFrida
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.