Skip to main content

Frida API

Description

A set of interfaces for dynamic analysis and application instrumentation via Frida in ZennoDroid.

InterfaceDescription
IFridaDeviceAPIManaging Frida Server and connecting to processes
IFridaSessionAPISession for connecting to a specific process
IFridaScriptAPIScript lifecycle and message exchange

IFridaDeviceAPI

Designed for working with the Frida dynamic analysis tool on an Android device. Allows you to manage Frida Server, connect to processes, and inject scripts.

Id

  • string Id { get; }
    Unique device identifier.

    Returns:
    A string with the device ID (e.g. ADB serial).

Name

  • string Name { get; }
    Device name.

    Returns:
    Human-readable name of the device or emulator.


Attach

  • IFridaSessionAPI Attach(uint pid)
    Attaches to an already running process.

    Parameters:

    • pid — process identifier.

    Returns:
    An IFridaSessionAPI object representing the active session.


DetachAllSessions

  • void DetachAllSessions()
    Detaches all active Frida sessions on the device.

DetachSessionByScriptName

  • void DetachSessionByScriptName(string scriptName)
    Detaches the session associated with the specified script.

    Parameters:

    • scriptName — name of the script used to find and detach the session.

InstallAndRunServer

  • void InstallAndRunServer()
    Installs (if necessary) and starts Frida Server on the device.

KillServer

  • void KillServer()
    Stops Frida Server.

LoadScriptToApp

  • void LoadScriptToApp(string packageName, string source)
    Loads and executes a Frida script in the specified application.

    Parameters:

    • packageName — application package name;
    • source — Frida script source code (JavaScript).

LoadScriptToFrontmost

  • void LoadScriptToFrontmost(string source)
    Loads and executes a script in the currently active application.

    Parameters:

    • source — script source code.

Spawn

  • uint Spawn(string packageName)
    Launches an application in a suspended state (until Resume is called).

    Parameters:

    • packageName — application package name.

    Returns:
    The pid of the created process.


Resume

  • void Resume(uint pid)
    Resumes execution of a previously spawned process.

    Parameters:

    • pid — process identifier.

Example

var source = project.Variables["script"].Value;
var device = instance.DroidInstance.FridaDevice;
device.InstallAndRunServer();
var pid = device.Spawn("com.android.settings");
var session = device.Attach(pid);

var script = session.CreateScript(source, "myScript");
script.Message += (o, e) => project.SendInfoToLog(e.Message);
script.Load();

device.Resume(pid);

Contents of the script variable (prints a message to the log):

console.log('hello!')

IFridaSessionAPI

Represents a session connected to a process via Frida. Acts as the intermediate layer between IFridaDeviceAPI (device) and IFridaScriptAPI (scripts).

Pid

  • uint Pid { get; }
    Identifier of the process the session is connected to.

    Returns:
    Process pid.


CreateScript

  • IFridaScriptAPI CreateScript(string source, string name)
    Creates a Frida script with the specified name.

    Parameters:

    • source — script source code (JavaScript);
    • name — script name.

    Returns:
    An IFridaScriptAPI object.

  • IFridaScriptAPI CreateScript(string source)
    Creates a Frida script without an explicit name.

    Parameters:

    • source — script source code.

    Returns:
    An IFridaScriptAPI object.


Detach

  • void Detach()
    Detaches from the process.

    Description:
    Terminates the current Frida session and releases resources.


IFridaScriptAPI

Represents an individual Frida script. Manages the script lifecycle and message exchange between C# code and injected JavaScript.

Message

  • EventHandler<FridaScriptMessageEventArgs> Message
    Event: message from the script.

    Description:
    Messages from the script (via send() or console.log()) are handled in C# through this event.

Name

  • string Name { get; }
    Script name.

    Returns:
    String name identifying the script.


Load

  • void Load()
    Loads and starts the script in the process.

    Description:
    After calling this, the script begins executing.


Unload

  • void Unload()
    Unloads the script.

    Description:
    Stops execution and removes the script from the process.


Eternalize

  • void Eternalize()
    Makes the script "permanent".

    Description:
    The script continues running even after the session ends or the client disconnects.


Post

  • void Post(string message)
    Sends a message to the Frida script.

    Parameters:

    • message — string message.

    Description:
    Used to pass data into JavaScript (handled via recv()).


PostWithData

  • void PostWithData(string message, byte[] data)
    Sends a message with binary data.

    Parameters:

    • message — string message;
    • data — byte array.

    Description:
    Allows passing binary data (e.g. files, buffers).