1323 words
7 minutes
how to compile frida and patch it with stronger frida version

install or upgrade nodejs to verion 20 +#

https://nodejs.org/en/download

# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"

# Download and install Node.js:
nvm install 22

# Verify the Node.js version:
node -v # Should print "v22.17.0".
nvm current # Should print "v22.17.0".

# Verify npm version:
npm -v # Should print "10.9.2".

reopen terminal to make it take effect.

to execute bash file in ubuntu:

chmod u+x ./xxx.sh
bash ./xxx.sh

clone related repo#

git clone https://github.com/frida/frida-core.git
git clone https://github.com/Ylarod/Florida.git

make sure they are the same version. i use 16.5.2 in both frida-core and Florida

git checkout 16.5.2

create a new folder named patch in frida-core folder.

move Florida/patches/frida-core to frida-core/patch

to patch file:

git am patch/frida-core/*.patch

there shouldn’t have any error

start to build#

./configure --host=android-arm64

if you encounter error

def load(mfile: Path) -> dict[str, Union[str, list[str]]]: TypeError: 'type' object is not subscriptable

upgrade your python to at least 3.9.

my ubuntu system version is 20.04 default python version is 3.8.

upgrade python(not necessary)#

Crucial Warning: Do NOT uninstall Python 3.8 from Ubuntu 20.04 unless you absolutely know what you’re doing and are prepared for potential system instability.

Ubuntu 20.04 (Focal Fossa) relies heavily on Python 3.8 for many of its core system components, including the desktop environment, package manager (apt), and various utilities. Completely removing Python 3.8 can break your system and make it unusable.

Instead of uninstalling Python 3.8, the recommended and safer approach is to:

  1. Install Python 3.9 alongside Python 3.8.
  2. Use Python 3.9 for your specific projects by employing virtual environments.
  3. Adjust your python3 alias (if desired, with caution).

Here’s how to do it:


Step 1: Install Python 3.9 using the Deadsnakes PPA#

The deadsnakes PPA (Personal Package Archive) is a well-maintained and common way to install newer Python versions on Ubuntu without interfering with the system’s default Python.

  1. Update package lists and install prerequisites:

    sudo apt update
    sudo apt install software-properties-common
    
  2. Add the deadsnakes PPA:

    sudo add-apt-repository ppa:deadsnakes/ppa
    

    Press Enter when prompted to confirm adding the PPA.

  3. Update package lists again to include the new PPA:

    sudo apt update
    
  4. Install Python 3.9:

    sudo apt install python3.9 python3.9-venv python3.9-dev
    
    • python3.9: The Python 3.9 interpreter.
    • python3.9-venv: Essential for creating isolated virtual environments.
    • python3.9-dev: Includes header files and static libraries needed for compiling Python extensions.
  5. Verify the installation:

    python3.9 --version
    

    You should see Python 3.9.x (where x is the latest minor version available in the PPA).


Step 2: Set Python 3.9 as the default (Optional, Use with Caution)#

By default, python3 will still point to Python 3.8. You can change this using update-alternatives, but be aware that this might affect system scripts that explicitly rely on the default Python 3.8 path.

If you want python3 to point to Python 3.9:

  1. Configure alternatives for python3:

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
    

    (The numbers 1 and 2 are priorities. A higher number means higher priority. Here, 3.9 is given higher priority.)

  2. Select Python 3.9 as the default:

    sudo update-alternatives --config python3
    

    You will see a list of available Python versions. Enter the number corresponding to python3.9 to select it as the default.

    Example output:

      Selection    Path                Priority   Status
    ------------------------------------------------------------
    * 0            /usr/bin/python3.8   1         auto mode
      1            /usr/bin/python3.8   1         manual mode
      2            /usr/bin/python3.9   2         manual mode
    
    Press <enter> to keep the current choice[*], or type selection number:
    

    Enter 2 and press Enter.

  3. Verify the change:

    python3 --version
    

    It should now show Python 3.9.x.

Important Note on Default Python: Even if you change the python3 symlink, many system scripts still use absolute paths like /usr/bin/python3.8 to ensure they run with the expected version. This is a good thing for system stability.


This is the safest and most recommended way to manage different Python versions for your projects. Virtual environments create isolated Python installations, so your project’s dependencies don’t conflict with other projects or with your system’s Python.

  1. Navigate to your project directory:

    cd /path/to/my/project
    
  2. Create a virtual environment using Python 3.9:

    python3.9 -m venv .venv
    

    This creates a folder named .venv (you can choose any name) within your project directory, containing a Python 3.9 interpreter and its own pip.

  3. Activate the virtual environment:

    source .venv/bin/activate
    

    Your terminal prompt will change to indicate that the virtual environment is active (e.g., (.venv) user@host:~/my/project$).

  4. Now, python and pip commands will refer to Python 3.9 within this environment:

    python --version # Should show Python 3.9.x
    pip --version    # Should show pip for Python 3.9.x
    
  5. Install project dependencies:

    pip install your-package-name
    

    These packages will be installed only in this virtual environment.

  6. Deactivate the virtual environment when you’re done:

    deactivate
    

By following these steps, you’ll have Python 3.9 available for your development needs without risking the stability of your Ubuntu 20.04 system. Always prefer virtual environments for project-specific Python versions.

ANDROID_NDK_ROOT must be set to the location of your r25 NDK#

you may also encounter this error

Downloading toolchain 20240913...
Extracting toolchain...
Downloading SDK 20240913 for linux-x86_64...
Extracting SDK...
Downloading SDK 20240913 for android-arm64...
Extracting SDK...
ANDROID_NDK_ROOT must be set to the location of your r25 NDK

the downloaded SDK located at frida-core/dps.

go to here to download ndk munally

https://github.com/android/ndk/wiki/Unsupported-Downloads

Here’s how to set the ANDROID_NDK_ROOT environment variable on Ubuntu, both temporarily and persistently. Setting it persistently is generally recommended for development.

1. Identify Your Android NDK Path#

First, you need to know the exact path where your Android NDK is installed.

  • If you’ve downloaded and extracted it, it will be the top-level directory of the extracted NDK.
  • Example Paths:
    • /home/yourusername/Android/Sdk/ndk/25.2.9519653 (if installed via Android Studio’s SDK Manager)
    • /home/yourusername/Android/ndk/android-ndk-r25b (if you manually downloaded and extracted it to ~/Android/ndk/)
    • /opt/android-ndk-r25b (if you put it in a system-wide location)

Crucial: Replace /path/to/your/android-ndk in the examples below with your actual NDK path.

2. Temporary Setting (for the current terminal session only)#

This is useful for quick tests or if you only need the variable set for a single command. The variable will be gone when you close the terminal.

  1. Open your terminal.

  2. Type the export command followed by the variable name and its value:

    export ANDROID_NDK_ROOT="/path/to/your/android-ndk"
    

    Example:

    export ANDROID_NDK_ROOT="/home/yourusername/Android/Sdk/ndk/25.2.9519653"
    
  3. Press Enter.

  4. Verify it’s set:

    echo $ANDROID_NDK_ROOT
    

    You should see the path you just set printed.

This method ensures that ANDROID_NDK_ROOT is automatically set every time you open a new terminal session. You’ll add the export command to your shell’s configuration file.

For most Ubuntu users, the shell is bash, and the primary configuration file is ~/.bashrc.

  1. Open your ~/.bashrc file in a text editor:

    nano ~/.bashrc   # nano is a simple terminal text editor
    # OR
    gedit ~/.bashrc  # gedit is a GUI text editor (if you have a desktop environment)
    # OR
    vim ~/.bashrc    # vim is a powerful terminal editor (for experienced users)
    
  2. Add the export line to the end of the file: Scroll to the very bottom of the file and add the following line. Again, replace /path/to/your/android-ndk with your actual NDK path.

    # Set Android NDK Root
    export ANDROID_NDK_ROOT="/path/to/your/android-ndk"
    

    It’s good practice to add a comment (starting with #) to explain what the line does.

    Example (assuming your NDK is at /home/yourusername/Android/Sdk/ndk/25.2.9519653):

    # Set Android NDK Root
    export ANDROID_NDK_ROOT="/home/yourusername/Android/Sdk/ndk/25.2.9519653"
    
  3. Save the file and exit the text editor:

    • For nano: Press Ctrl + O (to write out/save), then Enter, then Ctrl + X (to exit).
    • For gedit: Click “Save” or press Ctrl + S, then close the window.
    • For vim: Press Esc, then type :wq and press Enter.
  4. Apply the changes to your current terminal session: The changes you made to ~/.bashrc will automatically apply to any new terminal sessions you open. To apply them to your current session without closing and reopening the terminal, use the source command:

    source ~/.bashrc
    
  5. Verify it’s set persistently:

    echo $ANDROID_NDK_ROOT
    

    You should see the NDK path. Now, if you close this terminal and open a new one, echo $ANDROID_NDK_ROOT should still show the correct path.

Important Considerations:#

  • Android Studio’s NDK Location: If you installed the NDK via Android Studio’s SDK Manager, the path is typically within your Android SDK directory (e.g., ~/Android/Sdk/ndk/<version_number>).
  • Permissions: Ensure the user you’re logged in as has read/execute permissions to the NDK directory and its contents.
  • Other Shells: If you use a different shell (like zsh), you would edit ~/.zshrc instead of ~/.bashrc.
  • ANDROID_HOME / ANDROID_SDK_ROOT: While not directly for NDK, you might also need ANDROID_HOME or ANDROID_SDK_ROOT set for Android development, pointing to the parent Android SDK directory. This is separate from ANDROID_NDK_ROOT.

reopen terminal and continue to execute the last command.

make#

make

frida-server is located in frida-core/build/server/

anti anti frida#

go to frida-server folder move anti-anti-frida.py to it.

 python anti-anti-frida.py frida-server

pixel6 android15 encounters error on this version

how to compile frida and patch it with stronger frida version
https://zycreverse.netlify.app/posts/compile_frida/
Author
会写点代码的本子画手
Published at
2025-02-13