Код: Выделить всё
function main()
{
Interceptor.attach(Module.getExportByName(null, 'open'), {
onEnter(args) {
const originalPath = args[0].readCString();
if (shouldReplace(originalPath)){
args[0].writeUtf8String('/tmp/predefined'); // (1)
//args[0] = Memory.allocUtf8String("/tmp/predefined"); (2)
}
},
});
}
function shouldReplace(path) {
if (!path) return false;
// Do not replace essential system or config files:
if (path.startsWith("/usr/") || path.startsWith("/etc/") || path.startsWith("/lib") ||
path.startsWith("/var/") || path.startsWith("/proc/") || path.startsWith("/sys/") ||
path.startsWith("/dev/") || path.startsWith("/run/") || path.startsWith("/home/user/.config/")
|| path.startsWith("/home/user/.cache") || path.startsWith("/home/user/.local") ) {
return false;
}
// Avoid replacing if it's already the predefined file (prevent infinite loop)
if (path === "/tmp/predefined") {
return false;
}
// Otherwise, assume it's a user-requested file and should be repalced
return true;
}
main()
запустить frida as: ./frida -l patcher.js -f/usr/bin/gnome-text-editor/tmp/originalfile
Это кажется, что это работает:/tmp/redefine
. /TMP/OriginalFile . Но если я хочу выделить новую память для строки "/tmp/adefined" и назначить указатель на эту новую память на аргументы [0], а не переписывание содержимого памяти, на которое указывают Args [0] (некомментирование (2) строка, комментируйте (1) строка), я получаю ошибки:
- editor не открывает/не может открыть/ Не открываю файл, у вас нет разрешений на открытие файла
- В терминале: (Gnome-Text-Editor: 9036): редактор-документ-Warning **: 11: 11: 33.542: не удалось загрузить файл: ошибка File/tmp/Originalfile: No File или Distory , однако/tmp/tmp/orycorefile: no file или ляточный , однако/tmp/tmp/tmp/tmp/orisionf/tmp/tmp/orisionf/tmp/orisionfile , code>, tmp/tmp/tmp/tmp/tmp/tmp/tmp. существует.
Подробнее здесь: https://stackoverflow.com/questions/794 ... n-in-frida