Skip to content

Instantly share code, notes, and snippets.

@mmkhitaryan
Created August 30, 2022 10:13
Show Gist options
  • Save mmkhitaryan/0e4461316e7f9c320cbcd828e7d26ae7 to your computer and use it in GitHub Desktop.
Save mmkhitaryan/0e4461316e7f9c320cbcd828e7d26ae7 to your computer and use it in GitHub Desktop.
In original article you need to specify the function address manually. I made it detect the function address automatically.
#include <stdio.h>
#include <unistd.h>
void
f (int n)
{
printf ("Number: %d\n", n);
}
int
main (int argc,
char * argv[])
{
int i = 0;
while (1)
{
f (i++);
sleep (1);
}
}
# from https://frida.re/docs/installation/
import frida
session = frida.attach("hello")
script = session.create_script("""
// Find the module for the program itself, always at index 0:
const m = Process.enumerateModules()[0];
rpc.exports.enumerateModules = function () {
return Process.enumerateModules()[0].enumerateSymbols();
};
""")
script.load()
data = script.exports.enumerate_modules()
function_f = [x for x in data if x['name']=='f'][0]
function_f_address = function_f['address']
script = session.create_script("""
// Find the module for the program itself, always at index 0:
const m = Process.enumerateModules()[0];
Interceptor.attach(ptr("%s"), {
onEnter: function(args) {
send(args[0].toInt32());
}
});
""" % int(function_f_address, 16))
def on_message(message, data):
print(message)
script.on('message', on_message)
script.load()
input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment