我正在尝试在执行 Ghidra 进程的 Rust 程序和作为 Ghidra 进程的一部分运行的 Java 程序之间创建一个命名管道。我目前很难获得正确的访问权限(权限位)。
java.io.FileNotFoundException: /home/.../ghidra_rust_pipe/pipe/.tmpkOE0zg/pcode.pipe (Permission denied)
我的 Rust 程序看起来像这样(我尝试设置权限位以对其他用户进行写访问。)
...
let tmp_dir = TempDir::new_in("pipe").unwrap();
let fifo_path = tmp_dir.path().join("pcode.pipe");
// create new fifo and set permission bits
match unistd::mkfifo(&fifo_path, stat::Mode::S_IWOTH) {
Ok(_) => println!("created {:?}", fifo_path),
Err(err) => println!("Error creating fifo: {}", err),
}
// Execute Ghidra
let output = Command::new(&headless_path)
.arg(tmp_ghidra_project)
.arg("PcodeExtractor")
.arg("-import")
.arg(file_path)
.arg("-postScript")
.arg("PcodeExtractor.java")
.arg(fifo_path.clone()) // Path to the named pipe
.arg("-scriptPath")
.arg(script_path)
.arg("-deleteProject")
.output()
.unwrap();
...
if let Ok(mut file) = File::open(fifo_path) {
let mut contents = String::new();
match file.read_to_string(&mut contents) {
Ok(_) => println!("{}", contents),
Err(err) => panic!("Failed to write contents {}", err),
}
}
在 Java 程序中,我尝试像这样访问管道(路径是 Rust 程序给出的管道参数):
...
Gson gson = new GsonBuilder().setPrettyPrinting().addSerializationExclusionStrategy(strategy).create();
try {
FileOutputStream pcodeStream = new FileOutputStream(path);
String jsonString = gson.toJson(project);
pcodeStream.write(jsonString.getBytes());
pcodeStream.flush();
pcodeStream.close();
} catch (JsonIOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
...
我已经尝试了其中一些代码:https ://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html 。有谁知道如何正确设置权限?
这是 Java 异常的完整跟踪:
java.io.FileNotFoundException: /home/.../ghidra_rust_pipe/pipe/.tmpmazu66/pcode.pipe (Permission denied)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:126)
at serializer.Serializer.serializeProject(Serializer.java:66)
at PcodeExtractor.run(PcodeExtractor.java:61)
at ghidra.app.script.GhidraScript.executeNormal(GhidraScript.java:379)
at ghidra.app.script.GhidraScript.doExecute(GhidraScript.java:234)
at ghidra.app.script.GhidraScript.execute(GhidraScript.java:212)
at ghidra.app.util.headless.HeadlessAnalyzer.runScript(HeadlessAnalyzer.java:574)
at ghidra.app.util.headless.HeadlessAnalyzer.runScriptsList(HeadlessAnalyzer.java:891)
at ghidra.app.util.headless.HeadlessAnalyzer.analyzeProgram(HeadlessAnalyzer.java:1039)
at ghidra.app.util.headless.HeadlessAnalyzer.processFileWithImport(HeadlessAnalyzer.java:1532)
at ghidra.app.util.headless.HeadlessAnalyzer.processWithImport(HeadlessAnalyzer.java:1670)
at ghidra.app.util.headless.HeadlessAnalyzer.processWithImport(HeadlessAnalyzer.java:1735)
at ghidra.app.util.headless.HeadlessAnalyzer.processLocal(HeadlessAnalyzer.java:443)
at ghidra.app.util.headless.AnalyzeHeadless.launch(AnalyzeHeadless.java:121)
at ghidra.GhidraLauncher.main(GhidraLauncher.java:82)