[英]Frida: spawn a Windows/Linux process with command-line arguments
啟動 frida 時,您可以提供 frida 應該執行並附加到它的可執行文件的路徑:
frida -l myscript.js process_to_spawn.exe
我有一個可執行文件需要使用附加參數啟動,否則它會直接終止。 有沒有辦法啟動一個新的可執行文件並為新啟動的進程提供命令行參數?
我已經試過了
frida -l myscript.js process_to_spawn.exe --argForProcess
frida -l myscript.js "process_to_spawn.exe --argForProcess"
但兩種變體都不起作用。 Frida 試圖解釋所有參數,因此不能將參數傳遞給生成的進程。 第二個變種也不起作用,因為 frida 無法找到要啟動的可執行文件。
有沒有辦法通過 frida 在本地操作系統(例如 Windows 或 Linux)上生成可執行文件並提供命令行參數?
我無法附加到正在運行的進程,因為我想掛鈎的功能只在啟動后直接執行一次,所以我必須使用 frida 生成進程。
問題似乎是參數以-
開頭。 對於不以-
開頭的常規參數,使用 frida 選項-f
有效:
frida -l myscript.js -f process_to_spawn.exe argForProcess
但是因為我需要參數--argForProcess
我發現的唯一方法是掛鈎處理命令行參數並在調用 main 之前修改參數的 main 方法。
以下代碼適用於 Windows 10,它似乎將參數作為 wchar/"Unicode"/UTF-16 字符串傳遞。 它將main
的argc
和argv
參數從一個參數(可執行文件本身)更改為兩個(可執行文件加上一個參數)。
let mainPointer = DebugSymbol.fromName("main").address;
Interceptor.attach(mainPointer, {
onEnter(args) {
// args[0] = int argc
// args[1] = wchar *argv[]
let myarg1 = Memory.allocUtf16String("Myexecutable.exe");
let myarg2 = Memory.allocUtf16String("--argumentX");
let newArgv = Memory.alloc(2 * Process.pointerSize); // allocate space for the two argument pointers
newArgv.writePointer(myarg1);
newArgv.add(Process.pointerSize).writePointer(myarg2);
// save all created memory blocks so they don't get garbage collected before main method is completed
this.myarg1 = myarg1;
this.myarg2 = myarg2;
this.newArgs = newArgv;
// Overwrite the argument counter and the argument char**
args[0] = ptr(2);
args[1] = newArgs;
console.log("main(" + args[0] + ", " + args[1].readPointer().readUtf16String() + ", " + args[1].add(Process.pointerSize).readPointer().readUtf16String() + ")");
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.