Frida----基本代码

时间:2023-03-09 20:50:29
Frida----基本代码

代码来自官网:https://www.frida.re/docs/examples/android/

import frida, sys

def on_message(message, data):

if message['type'] == 'send':

print("[*] {0}".format(message['payload']))

else:

print(message)

jscode = """

Java.perform(function () {

// Function to hook is defined here

// 加载类文件

var MainActivity = Java.use('类名');

// Whenever button is clicked

// hook函数

MainActivity.onClick.implementation = function (v) {

// Show a message to know that the function got called

// 发送消息,返回到on_message()函数中

send('onClick');

// Call the original onClick handler

// 调用自己

this.onClick(v);

// Set our values after running the original onClick handler

// 修改变量内容

this.m.value = 0;

this.n.value = 1;

this.cnt.value = 999;

// Log to the console that it's done, and we should have the flag!

// 发送消息,返回到on_message()函数中

console.log('Done:' + JSON.stringify(this.cnt));

};

});

"""

process = frida.get_usb_device().attach('包名')

#获取连接到电脑上设备中进程句柄

script = process.create_script(jscode)

#创建代码

script.on('message', on_message)

#监听事件

print('[*] Running CTF')

script.load()

#加载代码

sys.stdin.read()