Last active
March 19, 2021 14:07
-
-
Save NSEcho/6351a132ee121928c9e80d56433afd7e to your computer and use it in GitHub Desktop.
Example that shows how to call sprintf with Frida
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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