參考資訊:
https://github.com/frida/frida
https://frida.re/docs/functions/
https://frida.re/docs/installation/
main.c
#include <stdio.h>
#include <unistd.h>
static void test(int v)
{
printf("%d\n", v);
}
int main(int argc, char *argv[])
{
printf("test()=%p\n", test);
while (1) {
usleep(1000000);
}
return 0;
}
hook.py
import sys
import frida
session = frida.attach("main")
script = session.create_script("""
const f = new NativeFunction(ptr("%s"), 'void', ['int']);
f(1111);
f(2222);
f(3333);
""" % int(sys.argv[1], 16))
script.load()
編譯、執行
$ gcc main.c -o main
$ ./main&
test()=0x555841a18149
$ python3 ./hook.py 0x555841a18149
1111
2222
3333