Skip to content

Instantly share code, notes, and snippets.

@NSEcho
Last active March 19, 2021 14:07
Show Gist options
  • Save NSEcho/6351a132ee121928c9e80d56433afd7e to your computer and use it in GitHub Desktop.
Save NSEcho/6351a132ee121928c9e80d56433afd7e to your computer and use it in GitHub Desktop.
Example that shows how to call sprintf with Frida
from __future__ import print_function
import frida
session = frida.attach("Twitter")
script = session.create_script("""\
var sprintf_ = new NativeFunction(Module.getExportByName(null, 'sprintf'), \
'int', ['pointer', 'pointer', '...', 'pointer']);
console.log("[*] Found sprintf at address", sprintf_.toString())
var output = Memory.alloc(128);
console.log("[*] Output is at", output, "with value", output.readCString() == "" ? "BLANK" : output.readCString())
var format = Memory.allocUtf8String("Hello %s")
var argument = Memory.allocUtf8String("World")
sprintf_(output, format, argument)
console.log("[*] Output is", output.readCString())
""")
script.load()
"""
$ python3 call_native.py
[*] Found sprintf at address 0x7fff20562c19
[*] Output is at 0x133879030 with value BLANK
[*] Output is Hello World
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment