Я пробую Frida для инъекции библиотеки и переопределения функции в процессе Linux.
Цель: у меня есть процесс, у которого есть target_func , который я хочу заменить с помощью Target_func in override .
Код: Выделить всё
import frida
import os
import sys
override_path = os.path.abspath("./override.so")
func_name = "target_func"
def on_message(message, data):
if message["type"] == "send":
print("[JS]", message["payload"])
elif message["type"] == "error":
print("[JS ERROR]", message["stack"])
pid = int(sys.argv[1]) if len(sys.argv) > 1 else int(input("Enter PID: "))
session = frida.attach(pid)
js_code = f"""
(function() {{
var libPath = "{override_path}";
send("Attempting to load library: " + libPath);
var customLib = null;
try {{
customLib = Module.load(libPath);
send("Library loaded.");
}} catch (e) {{
send("ERROR: Failed to load library: " + e.message);
return;
}}
var replacement = null;
try {{
send("Finding replacement symbol in the loaded library..");
replacement = Module.findExportByName(libPath, "{func_name}");
if (!replacement) {{
send("ERROR: replacement symbol not found.");
return;
}}
send("Replacement function found at " + replacement);
}} catch (e) {{
send("ERROR: getExportByName failed: " + e.message);
return;
}}
var original = Module.findExportByName(null, "{func_name}");
if (!original) {{
send("ERROR: Could not find original '{func_name}' in target process.");
return;
}}
send("Original function located at: " + original);
try {{
Interceptor.replace(original, replacement);
send("Interceptor.replace succeeded!");
}} catch (e) {{
send("ERROR: Interceptor.replace failed: " + e.message);
}}
}})();
"""
script = session.create_script(js_code)
script.on("message", on_message)
script.load()
input("Press Enter to detach...\n")
session.detach()
< /code>
Я вижу, что библиотека целей загружается. Проверил его с помощью вывода/proc // maps.
После этого я вижу эту ошибку:
[JS] Attempting to load library: .../override.so
[JS] Library loaded.
[JS] Finding replacement symbol in the loaded library..
[JS] ERROR: getExportByName failed: not a function```
Код: Выделить всё
nm -D ./override.so
w __cxa_finalize@GLIBC_2.2.5
w __gmon_start__
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
U printf@GLIBC_2.2.5
0000000000001109 T target_func
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/796 ... a-function