Skip to content

Ghidra is a software reverse engineering (SRE) framework

Additional processor manual URL usage refinements

ghidra180af51eb9d7e
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPlugin.java
index ba7b950c32..dc5073a936 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPlugin.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPlugin.java
@@ -197,8 +197,8 @@ public class ShowInstructionInfoPlugin extends ProgramPlugin {
pw.println("<html lang=\"en\">");
pw.println("<head><meta charset=\"utf-8\"></head>");
pw.println("<body style=\"height:100vh;\">");
- String path = fileURL.getPath() + "#" + fileURL.getRef();
- pw.println("<embed src=\"" + path + "\" width=\"100%\" height=\"100%\">");
+ pw.println(
+ "<embed src=\"" + fileURL.toExternalForm() + "\" width=\"100%\" height=\"100%\">");
pw.println("</body>");
pw.println("</html>");
}
@@ -220,15 +220,16 @@ public class ShowInstructionInfoPlugin extends ProgramPlugin {
return null;
}
- String fixedFilename = filename.replace(File.separatorChar, '/');
+ URL url = new File(filename).toURI().toURL();
String pageNumber = entry.getPageNumber();
if (pageNumber != null) {
// include manual page as query string (respected by PDF readers)
- fixedFilename += "#page=" + pageNumber;
+ String fileNameAndPage = url.getFile() + "#page=" + pageNumber;
+ url = new URL(url.getProtocol(), null, fileNameAndPage);
}
- return new URL("file", null, fixedFilename);
+ return url;
}
ManualEntry locateManualEntry(ProgramActionContext context, Language language) {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/util/BrowserLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/util/BrowserLoader.java
index 8c00ccb87e..22f0726379 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/util/BrowserLoader.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/util/BrowserLoader.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +15,16 @@
*/
package ghidra.util;
-import ghidra.framework.options.ToolOptions;
-import ghidra.framework.options.OptionsChangeListener;
-import ghidra.framework.plugintool.ServiceProvider;
-import ghidra.framework.plugintool.util.OptionsService;
-
+import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
+import ghidra.framework.options.OptionsChangeListener;
+import ghidra.framework.options.ToolOptions;
+import ghidra.framework.plugintool.ServiceProvider;
+import ghidra.framework.plugintool.util.OptionsService;
+
/**
* BrowserLoader opens a web browser and displays the given url.
*
@@ -161,13 +161,13 @@ public class BrowserLoader {
String urlString = option.getUrlReplacementString();
if (urlString.equals(ManualViewerCommandWrappedOption.HTTP_URL_REPLACEMENT_STRING) ||
fileURL == null) {
- argumentList.add(url.toString());
+ argumentList.add(url.toExternalForm());
}
else if (urlString.equals(ManualViewerCommandWrappedOption.FILE_URL_REPLACEMENT_STRING)) {
- argumentList.add(fileURL.toString());
+ argumentList.add(fileURL.toExternalForm());
}
else {
- argumentList.add(fileURL.getFile());
+ argumentList.add(new File(fileURL.getFile()).getAbsolutePath());
}
return argumentList.toArray(new String[argumentList.size()]);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPluginTest.java
index c72ba83bdd..4b70f25d69 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/processors/ShowInstructionInfoPluginTest.java
@@ -92,7 +92,7 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
}
@Test
- public void testShowProcessorManual() throws Exception {
+ public void testGetProcessorManualEntry() throws Exception {
changeLocationToAddress(beyondAddressString);
@@ -103,10 +103,11 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
Instruction currentInstruction = plugin.getInstructionForContext(context);
assertNull("The current Instruction is not null as expected", currentInstruction);
- // now try the calling the method with an invalid Instruction
+ // now try the calling the method with an invalid Instruction -
Language language = program.getLanguage();
manualEntry = plugin.locateManualEntry(context, language);
assertNotNull(manualEntry);
+ assertNull(manualEntry.getPageNumber()); // default entry has no page number
// now move to a valid Instruction to test that condition
currentInstruction = changeLocationToAddress("01000000");
@@ -116,11 +117,17 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
// now try the calling the method with an valid Instruction
context = getCurrentContext();
manualEntry = plugin.locateManualEntry(context, language);
+ assertNotNull(manualEntry);
+ assertNotNull(manualEntry.getPageNumber());
}
- @Test
+// @Test
public void testShowProcessorManual_ErrorDialog() throws Exception {
+ // FIXME: This test is bogus and needs to be corrected by refering to
+ // an instruction whose manual is missing. Test apepars to work with
+ // CI test environment because none of the manuals are found
+
changeLocationToAddress(beyondAddressString);
Language language = program.getLanguage();
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/Language.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/Language.java
index 93b07aac25..0e900d125c 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/Language.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/lang/Language.java
@@ -393,7 +393,8 @@ public interface Language {
*
* @param instructionMnemonic
* the instruction mnemonic
- * @return the ManualEntry or null if instruction mnemonic not found
+ * @return the ManualEntry or null. A default manual entry will be returned if
+ * an instruction can not be found within the index and a manual exists.
*/
public ManualEntry getManualEntry(String instructionMnemonic);