Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

frida-snippets

> 安全
Open source

Hand-crafted Frida examples

2.5K stars0 likes2 views
WebsiteGitHub

About

Hand-crafted Frida examples

& also output examples

Table of Contents

Native
  • Load C/C++ module
  • One time watchpoint
  • Socket activity
  • Intercept open
  • Execute shell command
  • List modules
  • Log SQLite query
  • Log method arguments
  • Intercept entire module
  • Dump memory segments
  • Memory scan
  • Stalker
  • Cpp Demangler
  • Early hook
Android
  • Binder transactions
  • Get system property
  • Reveal manually registered native symbols
  • Enumerate loaded classes
  • Class description
  • Turn WiFi off
  • Set proxy
  • Get IMEI
  • Hook io InputStream
  • Android make Toast
  • Await for specific module to load
  • Webview URLS
  • Print all runtime strings & stacktrace
  • Print shared preferences updates
  • String comparison
  • Hook JNI by address
  • Hook constructor
  • Hook Java reflection
  • Trace class
  • Hooking Unity3d
  • Get Android ID
  • Change location
  • Bypass FLAG_SECURE
  • Shared Preferences update
  • Hook all method overloads
  • Register broadcast receiver
  • Increase step count
  • list classes implements interface with class loaders
  • File system access hook $ frida --codeshare FrenchYeti/android-file-system-access-hook -f com.example.app --no-pause
  • How to remove/disable java hooks ? Assign null to the implementation property.
iOS
  • OS Log
  • iOS alert box
  • File access
  • Observe class
  • Find application UUID
  • Extract cookies
  • Describe class members
  • Class hierarchy
  • Hook refelaction
  • Device properties
  • Take screenshot
  • Log SSH commands
Windows Sublime snippets
{
    "scope": "source.js",
    "completions": [
	{"trigger": "fridainterceptor", "contents": "Interceptor.attach(\n    ptr,\n    {\n        onEnter:function(args) {\n\n        },\n        onLeave: function(retval) {\n\n        }\n    }\n)"},
	{"trigger": "fridaperform", "contents": "function main(){\n    console.log('main()');\n}\n\nconsole.log('script loaded');\nJava.perform(main);"},
	{"trigger": "fridause", "contents": "var kls = Java.use('kls');"},
	{"trigger": "fridahex", "contents": "hexdump(\n    ptr,\n    {\n         offset: 0,\n         length: ptr_size\n     }\n);" },
	{"trigger": "fridabacktrace", "contents": "console.log('called from:\\n' +\n        Thread.backtrace(this.context, Backtracer.ACCURATE)\n        .map(DebugSymbol.fromAddress).join('\\n') + '\\n'\n);"},
	{"trigger": "fridamods", "contents": "var mods = Process.enumerateModules().filter(function(mod){\n    return mod.name.includes(\"<name>\");\n});"},
	{"trigger": "fridaexport", "contents": "Module.findExportByName(null, \"<export_name>\");"},
	{"trigger": "fridabase", "contents": "Module.findBaseAddress(name);"},
	{"trigger": "fridaoverload", "contents": "kls.method_name.overload().implementation=function(){}"}
    ]
}
Vim snippets

To list abbreviations :ab

Expand by writing key and <Space>

  • Add to ~/.vimrc
ab fridaintercept Interceptor.attach(ptr, {<CR><Tab>onEnter: function(args) {<CR><CR>},<CR>onLeave: function(retval) {<CR><CR>}<CR><BS>})
ab fridabacktrace console.warn(Thread.backtrace(this.context, Backtracer.ACCURATE).map(DebugSymbol.fromAddress).join('\n'));<ESC>F(3;
ab fridadescribe console.log(Object.getOwnPropertyNames(Java.use('$').__proto__).join('\n\t'))<Esc>F$
JEB

Java method hook generator using keyboard shortcut

  1. curl -o ~/$JEB$/scripts/FridaCodeGenerator.py https://raw.githubusercontent.com/iddoeldor/frida-snippets/master/scripts/FridaCodeGenerator.py
  2. Place cursor at Java method's signature
  3. Press Ctrl+Shift+Z
  4. Code is copied to system clipboard (using xclip)

Fetch SSL keys

…


⬆ Back to top

Load CPP module

cpp
#include <iostream>
#include <string>

extern "C" {
  void* create_stdstr(char *data, int size) {
    std::string* s = new std::string();
    (*s).assign(data, size);		  
    return s;
  }
}
bash
$ ./android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ a.cpp -o a -shared -static-libstdc++ && adb push a /data/local/tmp/a
…

Load C module

  • https://frida.re/docs/javascript-api/#cmodule
  • https://frida.re/news/2019/09/18/frida-12-7-released/
bash
$ ./aarch64-linux-android21-clang /tmp/b.c -o /tmp/a -shared ../sysroot/usr/lib/aarch64-linux-android/21/liblog.so && adb push /tmp/a /data/local/tmp/a
c
#include <stdio.h>
#include <stdlib.h>
#include <android/log.h>    

#define TAG "TEST1"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)

void test(void) {
  FILE* fp = popen("ls -l /sdcard 2>&1", "r");
  if (fp == NULL)
    LOGE("executing cmd failed");
  char b[256];
  while (fgets(b, sizeof(b), fp) != NULL) {
    LOGI("%s", b);
  }
  pclose(fp);
}
bash
$ frida -Uf com.app --no-pause --enable-jit -e "Module.load('/data/local/tmp/a')"
[ ] -> new NativeFunction(Module.findExportByName('a', 'test'), 'void', [])()


⬆ Back to top

One time watchpoint

Intercept funcPtr & log who read/write to x2 via removing permissions w/ mprotect.

…
Output example
…


⬆ Back to top

Socket activity

…
Output example

Android example

bash
# wrap the script above inside Java.perform
$ frida -Uf com.example.app -l script.js --no-pause
[Android Model-X::com.example.app]-> 117 write 5.0.2.1:5242
117 read 5.0.2.1:5242
135 write 5.0.2.1:4244
135 read 5.0.2.1:4244
135 read 5.0.2.1:4244


⬆ Back to top

Intercept Open

An example for intercepting libc#open & logging backtrace if specific file was opened.

…
…
Output example Intecepting `com.android.chrome`


⬆ Back to top

Execute shell command

…
Usage example

List directory contents:

python
def ls(folder):
    cmd = Shell(['/bin/sh', '-c', 'ls -la ' + folder], None)
    cmd.exec()
    for chunk in cmd.output:
        print(chunk.strip().decode())

Pull binary from iOS

python
cmd = Shell(['/bin/sh', '-c', 'cat /System/Library/PrivateFrameworks/Example.framework/example'], None)
cmd.exec()
with open('/tmp/example', 'wb+') as f:
    f.writelines(cmd.output)
 # $ file /tmp/example
 # /tmp/example: Mach-O 64-bit 64-bit architecture=12 executable


⬆ Back to top

List modules

javascript
Process.enumerateModulesSync()
    .filter(function(m){ return m['path'].toLowerCase().indexOf('app') !=-1 ; })
    .forEach(function(m) {
        console.log(JSON.stringify(m, null, '  '));
        // to list exports use Module.enumerateExportsSync(m.name)
    });

List modules & exports

javascript
sudo frida Process --no-pause --eval 'var x={};Process.enumerateModulesSync().forEach(function(m){x[m.name] = Module.enumerateExportsSync(m.name)});x' -q | less +F
Output example
…


⬆ Back to top

Log SQLite query

javascript
Interceptor.attach(Module.findExportByName('libsqlite.so', 'sqlite3_prepare16_v2'), {
      onEnter: function(args) {
          console.log('DB: ' + Memory.readUtf16String(args[0]) + '\tSQL: ' + Memory.readUtf16String(args[1]));
      }
});
Output example TODO


⬆ Back to top

system property get

javascript
Interceptor.attach(Module.findExportByName(null, '__system_property_get'), {
	onEnter: function (args) {
		this._name = args[0].readCString();
		this._value = args[1];
	},
	onLeave: function (retval) {
		console.log(JSON.stringify({
			result_length: retval,
			name: this._name,
			val: this._value.readCString()
		}));
	}
});
Output example
…


⬆ Back to top

Binder transactions

…
Output example
…


⬆ Back to top

Reveal native methods

registerNativeMethods can be used as anti reversing technique to the native .so libraries, e.g. hiding the symbols as much as possible, obfuscating the exported symbols and eventually adding some protection over the JNI bridge. source

…

@OldVersion

…
Output example
bash
$ frida -Uf com.google.android.apps.photos --no-pause -l script.js
bash
{"class":"org/chromium/net/GURLUtils","method":"nativeGetOrigin","signature":"(Ljava/lang/String;)Ljava/lang/String;","address":"0x..da910"}
..


⬆ Back to top

Log method arguments

…
Symbol Type Table
    "A" The symbol's value is absolute, and will not be changed by further linking.
    "B" The symbol is in the uninitialized data section (known as BSS).
    "C" The symbol is common.  Common symbols are uninitialized data.
       When linking, multiple common symbols may appear	with the same name.  
       If the symbol is defined anywhere, the common symbols are treated as undefined	references.
    "D" The symbol is in the initialized data section.
    "G" The symbol is in an initialized data section for small objects.
       Some object file formats permit more efficient access to small data objects, such as a global int variable as 
       opposed to a large global array.
    "I" The symbol is an indirect reference to another symbol.
       This is a GNU extension to the a.out object file format which is rarely used.
    "N" The symbol is a debugging symbol.
    "R" The symbol is in a read only data section.
    "S" The symbol is in an uninitialized data section for small objects.
    "T" The symbol is in the text (code) section.
    "U" The symbol is undefined.
    "V" The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, 
        the normal defined symbol is used with no error.  
        When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes 
        zero with no error.
    "W" The symbol is a weak symbol that has not been specifically

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptaarch64androidarm64dynamic-analysis

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category安全
PricingOpen source

> Related tools

O
OWASP ZAP
开源 Web 应用安全扫描器
O
owasp-wstg-tracker
Simple web app to track OWASP WSTG security testing progress
H
homebridge-mi-gateway-security
XiaoMi Gateway Security plugin for HomeBridge.