Additional processor manual URL usage refinements

This commit is contained in:
ghidra1 2020-09-10 17:36:17 -04:00
parent 90f6b5c7e5
commit 80af51eb9d
4 changed files with 27 additions and 18 deletions

View file

@ -197,8 +197,8 @@ public class ShowInstructionInfoPlugin extends ProgramPlugin {
pw.println("<html lang=\"en\">"); pw.println("<html lang=\"en\">");
pw.println("<head><meta charset=\"utf-8\"></head>"); pw.println("<head><meta charset=\"utf-8\"></head>");
pw.println("<body style=\"height:100vh;\">"); pw.println("<body style=\"height:100vh;\">");
String path = fileURL.getPath() + "#" + fileURL.getRef(); pw.println(
pw.println("<embed src=\"" + path + "\" width=\"100%\" height=\"100%\">"); "<embed src=\"" + fileURL.toExternalForm() + "\" width=\"100%\" height=\"100%\">");
pw.println("</body>"); pw.println("</body>");
pw.println("</html>"); pw.println("</html>");
} }
@ -220,15 +220,16 @@ public class ShowInstructionInfoPlugin extends ProgramPlugin {
return null; return null;
} }
String fixedFilename = filename.replace(File.separatorChar, '/'); URL url = new File(filename).toURI().toURL();
String pageNumber = entry.getPageNumber(); String pageNumber = entry.getPageNumber();
if (pageNumber != null) { if (pageNumber != null) {
// include manual page as query string (respected by PDF readers) // 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) { ManualEntry locateManualEntry(ProgramActionContext context, Language language) {

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,15 +15,16 @@
*/ */
package ghidra.util; package ghidra.util;
import ghidra.framework.options.ToolOptions; import java.io.File;
import ghidra.framework.options.OptionsChangeListener;
import ghidra.framework.plugintool.ServiceProvider;
import ghidra.framework.plugintool.util.OptionsService;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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. * BrowserLoader opens a web browser and displays the given url.
* *
@ -161,13 +161,13 @@ public class BrowserLoader {
String urlString = option.getUrlReplacementString(); String urlString = option.getUrlReplacementString();
if (urlString.equals(ManualViewerCommandWrappedOption.HTTP_URL_REPLACEMENT_STRING) || if (urlString.equals(ManualViewerCommandWrappedOption.HTTP_URL_REPLACEMENT_STRING) ||
fileURL == null) { fileURL == null) {
argumentList.add(url.toString()); argumentList.add(url.toExternalForm());
} }
else if (urlString.equals(ManualViewerCommandWrappedOption.FILE_URL_REPLACEMENT_STRING)) { else if (urlString.equals(ManualViewerCommandWrappedOption.FILE_URL_REPLACEMENT_STRING)) {
argumentList.add(fileURL.toString()); argumentList.add(fileURL.toExternalForm());
} }
else { else {
argumentList.add(fileURL.getFile()); argumentList.add(new File(fileURL.getFile()).getAbsolutePath());
} }
return argumentList.toArray(new String[argumentList.size()]); return argumentList.toArray(new String[argumentList.size()]);

View file

@ -92,7 +92,7 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
} }
@Test @Test
public void testShowProcessorManual() throws Exception { public void testGetProcessorManualEntry() throws Exception {
changeLocationToAddress(beyondAddressString); changeLocationToAddress(beyondAddressString);
@ -103,10 +103,11 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
Instruction currentInstruction = plugin.getInstructionForContext(context); Instruction currentInstruction = plugin.getInstructionForContext(context);
assertNull("The current Instruction is not null as expected", currentInstruction); 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(); Language language = program.getLanguage();
manualEntry = plugin.locateManualEntry(context, language); manualEntry = plugin.locateManualEntry(context, language);
assertNotNull(manualEntry); assertNotNull(manualEntry);
assertNull(manualEntry.getPageNumber()); // default entry has no page number
// now move to a valid Instruction to test that condition // now move to a valid Instruction to test that condition
currentInstruction = changeLocationToAddress("01000000"); currentInstruction = changeLocationToAddress("01000000");
@ -116,11 +117,17 @@ public class ShowInstructionInfoPluginTest extends AbstractGhidraHeadedIntegrati
// now try the calling the method with an valid Instruction // now try the calling the method with an valid Instruction
context = getCurrentContext(); context = getCurrentContext();
manualEntry = plugin.locateManualEntry(context, language); manualEntry = plugin.locateManualEntry(context, language);
assertNotNull(manualEntry);
assertNotNull(manualEntry.getPageNumber());
} }
@Test // @Test
public void testShowProcessorManual_ErrorDialog() throws Exception { 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); changeLocationToAddress(beyondAddressString);
Language language = program.getLanguage(); Language language = program.getLanguage();

View file

@ -393,7 +393,8 @@ public interface Language {
* *
* @param instructionMnemonic * @param instructionMnemonic
* the instruction mnemonic * 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); public ManualEntry getManualEntry(String instructionMnemonic);