GT-2949 - Scripting - removed old deprecated methods

This commit is contained in:
dragonmacher 2019-07-18 11:42:21 -04:00
parent f94e451d6b
commit d4bb3e945d
8 changed files with 101 additions and 149 deletions

View file

@ -220,9 +220,9 @@ public class BuildResultState extends GhidraScript {
// } // }
// //
Register[] regs = currentProgram.getLanguage().getRegisters(); Register[] regs = currentProgram.getLanguage().getRegisters();
List<Register> registers = Arrays.asList(regs);
try { try {
Register reg = Register reg = askChoice("Results Query", "Select Register:", registers, null);
askChoice("Results Query", "Select Register:", Arrays.asList(regs), null);
while (reg != null) { while (reg != null) {
boolean first = true; boolean first = true;
boolean preserved = true; boolean preserved = true;
@ -242,7 +242,7 @@ public class BuildResultState extends GhidraScript {
System.out.println(reg.getName() + " value is preserved."); System.out.println(reg.getName() + " value is preserved.");
} }
reg = askChoice("Results Query", "Select Register:", regs, null); reg = askChoice("Results Query", "Select Register:", registers, null);
} }
} }
catch (CancelledException e) { catch (CancelledException e) {

View file

@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -83,8 +82,8 @@ public class FixLangId extends GhidraScript {
dbh.close(); dbh.close();
} }
private boolean modifyLanguage(DomainFile df, DBHandle dbh) throws IOException, private boolean modifyLanguage(DomainFile df, DBHandle dbh)
ImproperUseException { throws IOException, ImproperUseException {
// TODO: Check for address map and overlay entries which could break from // TODO: Check for address map and overlay entries which could break from
// changing the memory model !! // changing the memory model !!
@ -104,9 +103,9 @@ public class FixLangId extends GhidraScript {
LanguageDescription desc = null; LanguageDescription desc = null;
List<LanguageDescription> descriptions = List<LanguageDescription> descriptions =
DefaultLanguageService.getLanguageService().getLanguageDescriptions(true); DefaultLanguageService.getLanguageService().getLanguageDescriptions(true);
String[] choices = new String[descriptions.size()]; List<String> choices = new ArrayList<>(descriptions.size());
for (int i = 0; i < choices.length; i++) { for (int i = 0; i < choices.size(); i++) {
choices[i] = descriptions.get(i).getLanguageID().getIdAsString(); choices.add(descriptions.get(i).getLanguageID().getIdAsString());
} }
try { try {
@ -114,9 +113,8 @@ public class FixLangId extends GhidraScript {
if (langId != null) { if (langId != null) {
Msg.warn(this, "Changing language ID from '" + record.getString(0) + "' to '" + Msg.warn(this, "Changing language ID from '" + record.getString(0) + "' to '" +
langId + "' for program: " + df.getName()); langId + "' for program: " + df.getName());
desc = desc = DefaultLanguageService.getLanguageService().getLanguageDescription(
DefaultLanguageService.getLanguageService().getLanguageDescription( new LanguageID(langId));
new LanguageID(langId));
long txId = dbh.startTransaction(); long txId = dbh.startTransaction();
try { try {
record.setString(0, langId); record.setString(0, langId);
@ -140,20 +138,12 @@ public class FixLangId extends GhidraScript {
public DomainFile askProgramFile(String title) { public DomainFile askProgramFile(String title) {
final DomainFile[] domainFile = new DomainFile[] { null }; final DomainFile[] domainFile = new DomainFile[] { null };
final DataTreeDialog dtd = new DataTreeDialog(null, title, DataTreeDialog.OPEN); final DataTreeDialog dtd = new DataTreeDialog(null, title, DataTreeDialog.OPEN);
dtd.addOkActionListener(new ActionListener() { dtd.addOkActionListener(e -> {
@Override dtd.close();
public void actionPerformed(ActionEvent e) { domainFile[0] = dtd.getDomainFile();
dtd.close();
domainFile[0] = dtd.getDomainFile();
}
}); });
try { try {
SwingUtilities.invokeAndWait(new Runnable() { SwingUtilities.invokeAndWait(() -> dtd.showComponent());
@Override
public void run() {
dtd.showComponent();
}
});
} }
catch (Exception e) { catch (Exception e) {
return null; return null;

View file

@ -89,7 +89,8 @@ public class AskScript extends GhidraScript {
println("You typed: " + myStr + " and " + myOtherStr); println("You typed: " + myStr + " and " + myOtherStr);
String choice = askChoice("Choice", "Please choose one", String choice = askChoice("Choice", "Please choose one",
new String[] { "grumpy", "dopey", "sleepy", "doc", "bashful" }, "bashful"); Arrays.asList(new String[] { "grumpy", "dopey", "sleepy", "doc", "bashful" }),
"bashful");
println("Choice? " + choice); println("Choice? " + choice);
List<Integer> choices1 = askChoices("Choices 1", "Please choose one or more numbers.", List<Integer> choices1 = askChoices("Choices 1", "Please choose one or more numbers.",

View file

@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import java.io.*;
import java.util.*;
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.framework.*; import ghidra.framework.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* *
* Asks user for a single .pdb file or a directory that contains .pdb files (search for * Asks user for a single .pdb file or a directory that contains .pdb files (search for
@ -46,10 +45,10 @@ public class CreatePdbXmlFilesScript extends GhidraScript {
// Get appropriate pdb.exe file // Get appropriate pdb.exe file
String pdbExeLocation = Application.getOSFile("pdb.exe").getAbsolutePath(); String pdbExeLocation = Application.getOSFile("pdb.exe").getAbsolutePath();
String[] choices = new String[] { "single file", "directory of files" }; List<String> choices = Arrays.asList("single file", "directory of files");
String fileOrDir = String fileOrDir = askChoice("PDB file or directory",
askChoice("PDB file or directory", "Would you like to operate on a single " "Would you like to operate on a single " + ".pdb file or a directory of .pdb files?",
+ ".pdb file or a directory of .pdb files?", choices, choices[1]); choices, choices.get(1));
File pdbParentDir; File pdbParentDir;
String pdbName; String pdbName;
@ -57,7 +56,7 @@ public class CreatePdbXmlFilesScript extends GhidraScript {
int filesCreated = 0; int filesCreated = 0;
try { try {
if (fileOrDir.equals(choices[0])) { if (fileOrDir.equals(choices.get(0))) {
File pdbFile = askFile("Choose a PDB file", "OK"); File pdbFile = askFile("Choose a PDB file", "OK");
if (!pdbFile.exists()) { if (!pdbFile.exists()) {
@ -82,12 +81,11 @@ public class CreatePdbXmlFilesScript extends GhidraScript {
} }
else { else {
// Do recursive processing // Do recursive processing
File pdbDir = File pdbDir = askDirectory(
askDirectory( "Choose PDB root folder (performs recursive search for .pdb files)", "OK");
"Choose PDB root folder (performs recursive search for .pdb files)", "OK");
// Get list of files to process // Get list of files to process
List<File> pdbFiles = new ArrayList<File>(); List<File> pdbFiles = new ArrayList<>();
getPDBFiles(pdbDir, pdbFiles); getPDBFiles(pdbDir, pdbFiles);
int createdFilesCounter = 0; int createdFilesCounter = 0;
@ -157,8 +155,8 @@ public class CreatePdbXmlFilesScript extends GhidraScript {
createdFile.delete(); createdFile.delete();
} }
throw new IOException("At file '" + pdbName + throw new IOException(
"':\nAbnormal termination of 'pdb.exe' process."); "At file '" + pdbName + "':\nAbnormal termination of 'pdb.exe' process.");
} }
} }

View file

@ -19,8 +19,7 @@ import static org.junit.Assert.*;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.*;
import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
@ -30,7 +29,7 @@ import org.junit.*;
import docking.DialogComponentProvider; import docking.DialogComponentProvider;
import docking.widgets.filechooser.GhidraFileChooser; import docking.widgets.filechooser.GhidraFileChooser;
import generic.test.AbstractGenericTest; import generic.test.AbstractGTest;
import generic.test.TestUtils; import generic.test.TestUtils;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin; import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.script.GhidraScriptMgrPlugin; import ghidra.app.plugin.core.script.GhidraScriptMgrPlugin;
@ -43,7 +42,7 @@ import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation; import ghidra.program.util.ProgramLocation;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv; import ghidra.test.TestEnv;
import ghidra.util.task.TaskMonitorAdapter; import ghidra.util.task.TaskMonitor;
import utilities.util.FileUtilities; import utilities.util.FileUtilities;
public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationTest { public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationTest {
@ -123,7 +122,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
assertByteArrayEquals(expectedBytes, myBytes); assertByteArrayEquals(expectedBytes, myBytes);
} }
/** /*
* Calling askProgram() would stacktrace if the user 1) didn't select a program in the * Calling askProgram() would stacktrace if the user 1) didn't select a program in the
* tree and then 2) pressed the OK button. * tree and then 2) pressed the OK button.
*/ */
@ -141,7 +140,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
DataTreeDialog dtd = waitForDialogComponent(null, DataTreeDialog.class, 2000); DataTreeDialog dtd = waitForDialogComponent(DataTreeDialog.class);
JButton okButton = (JButton) getInstanceField("okButton", dtd); JButton okButton = (JButton) getInstanceField("okButton", dtd);
runSwing(() -> okButton.doClick()); runSwing(() -> okButton.doClick());
@ -152,7 +151,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
runSwing(() -> dtd.close()); runSwing(() -> dtd.close());
} }
/** /*
* For scripts with properties files in a different location (could be the case with subscripts), * For scripts with properties files in a different location (could be the case with subscripts),
* tests that the .properties file is found in the default location and that the default value * tests that the .properties file is found in the default location and that the default value
* for the input field is provided by the .properties file in the alternate location. * for the input field is provided by the .properties file in the alternate location.
@ -164,7 +163,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
// Create a temporary .properties file and set the potentialPropertiesFileLocs to look // Create a temporary .properties file and set the potentialPropertiesFileLocs to look
// in that location // in that location
String tempDirPath = AbstractGenericTest.getTestDirectoryPath(); String tempDirPath = AbstractGTest.getTestDirectoryPath();
File tempDir = new File(tempDirPath); File tempDir = new File(tempDirPath);
File tempPropertiesFile = new File(tempDir, "GhidraScriptTest.properties"); File tempPropertiesFile = new File(tempDir, "GhidraScriptTest.properties");
tempPropertiesFile.delete(); tempPropertiesFile.delete();
@ -200,8 +199,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
AskDialog askDialog = AskDialog<?> askDialog = waitForDialogComponent(AskDialog.class);
waitForDialogComponent(env.getTool().getToolFrame(), AskDialog.class, TIMEOUT_MILLIS);
assertNotNull(askDialog); assertNotNull(askDialog);
pressButtonByText(askDialog, "OK"); pressButtonByText(askDialog, "OK");
waitForSwing(); waitForSwing();
@ -216,7 +214,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
// Create a temporary files, then create a temporary .properties file that contains // Create a temporary files, then create a temporary .properties file that contains
// the path to one of the temporary file. // the path to one of the temporary file.
String tempDirPath = AbstractGenericTest.getTestDirectoryPath(); String tempDirPath = AbstractGTest.getTestDirectoryPath();
File tempDir = new File(tempDirPath); File tempDir = new File(tempDirPath);
File tempFile = new File(tempDir, "tempFile.exe"); File tempFile = new File(tempDir, "tempFile.exe");
File anotherTempFile = new File(tempDir, "MyTempFile.txt"); File anotherTempFile = new File(tempDir, "MyTempFile.txt");
@ -258,8 +256,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
GhidraFileChooser fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser fileChooser = waitForDialogComponent(GhidraFileChooser.class);
GhidraFileChooser.class, TIMEOUT_MILLIS * 2);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
@ -281,8 +278,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser.class, fileChooser = waitForDialogComponent(GhidraFileChooser.class);
TIMEOUT_MILLIS * 2);
fileChooser.setSelectedFile(anotherTempFile); fileChooser.setSelectedFile(anotherTempFile);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
@ -300,8 +296,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser.class, fileChooser = waitForDialogComponent(GhidraFileChooser.class);
TIMEOUT_MILLIS * 2);
fileChooser.setSelectedFile(anotherTempFile); fileChooser.setSelectedFile(anotherTempFile);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
@ -324,7 +319,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
// Create temporary directories, then create a temporary .properties file that contains // Create temporary directories, then create a temporary .properties file that contains
// the path to one of the temporary directory. // the path to one of the temporary directory.
String tempDirPath = AbstractGenericTest.getTestDirectoryPath(); String tempDirPath = AbstractGTest.getTestDirectoryPath();
File tempDir = new File(tempDirPath); File tempDir = new File(tempDirPath);
File tempSubDir = new File(tempDir, TEMP_SUB_DIR); File tempSubDir = new File(tempDir, TEMP_SUB_DIR);
File anotherTempSubDir = new File(tempDir, "anotherTempDir"); File anotherTempSubDir = new File(tempDir, "anotherTempDir");
@ -368,8 +363,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
GhidraFileChooser fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser fileChooser = waitForDialogComponent(GhidraFileChooser.class);
GhidraFileChooser.class, TIMEOUT_MILLIS * 2);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
assertNotNull(fileChooser); assertNotNull(fileChooser);
@ -390,8 +384,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser.class, fileChooser = waitForDialogComponent(GhidraFileChooser.class);
TIMEOUT_MILLIS * 2);
fileChooser.setSelectedFile(anotherTempSubDir); fileChooser.setSelectedFile(anotherTempSubDir);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
@ -409,8 +402,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}); });
fileChooser = waitForDialogComponent(env.getTool().getToolFrame(), GhidraFileChooser.class, fileChooser = waitForDialogComponent(GhidraFileChooser.class);
TIMEOUT_MILLIS * 2);
waitForUpdateOnDirectory(fileChooser); waitForUpdateOnDirectory(fileChooser);
pressButtonByText(fileChooser, "Choose!"); pressButtonByText(fileChooser, "Choose!");
@ -444,8 +436,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
SelectLanguageDialog langDialog = waitForDialogComponent(env.getTool().getToolFrame(), SelectLanguageDialog langDialog = waitForDialogComponent(SelectLanguageDialog.class);
SelectLanguageDialog.class, TIMEOUT_MILLIS);
assertNotNull(langDialog); assertNotNull(langDialog);
pressButtonByText(langDialog, "Give me a language:"); pressButtonByText(langDialog, "Give me a language:");
waitForSwing(); waitForSwing();
@ -463,8 +454,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
langDialog = waitForDialogComponent(env.getTool().getToolFrame(), langDialog = waitForDialogComponent(SelectLanguageDialog.class);
SelectLanguageDialog.class, TIMEOUT_MILLIS);
LanguageCompilerSpecPair chosenLang = LanguageCompilerSpecPair chosenLang =
new LanguageCompilerSpecPair("68000:BE:32:Coldfire", "default"); new LanguageCompilerSpecPair("68000:BE:32:Coldfire", "default");
@ -484,8 +474,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
langDialog = waitForDialogComponent(env.getTool().getToolFrame(), langDialog = waitForDialogComponent(SelectLanguageDialog.class);
SelectLanguageDialog.class, TIMEOUT_MILLIS);
pressButtonByText(langDialog, "Give me a language:"); pressButtonByText(langDialog, "Give me a language:");
waitForSwing(); waitForSwing();
@ -510,7 +499,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
assertEquals(10101, chosenInt); assertEquals(10101, chosenInt);
// Now set int to some other value // Now set int to some other value
Integer newInt = new Integer(123456); Integer newInt = 123456;
chosenInt = ask_TextInput(Integer.toString(newInt), () -> { chosenInt = ask_TextInput(Integer.toString(newInt), () -> {
return script.askInt("Ask Test", "Enter an integer:"); return script.askInt("Ask Test", "Enter an integer:");
}); });
@ -539,7 +528,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
assertEquals((long) Math.pow(2, 18), chosenLong); assertEquals((long) Math.pow(2, 18), chosenLong);
// Now set the long value to a different value // Now set the long value to a different value
Long newLong = new Long((long) Math.pow(4, 28)); Long newLong = (long) Math.pow(4, 28);
chosenLong = ask_TextInput(Long.toString(newLong), () -> { chosenLong = ask_TextInput(Long.toString(newLong), () -> {
return script.askLong("Ask Test", "Enter a long:"); return script.askLong("Ask Test", "Enter a long:");
}); });
@ -649,21 +638,21 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
createScript(); createScript();
// Compare default value to expected properties value // Compare default value to expected properties value
String[] choices = new String[] { "eenie", "meanie", "miney", "mo" }; List<String> choices = Arrays.asList("eenie", "meanie", "miney", "mo");
String chosen = ask_ComboInput(() -> { String chosen = ask_ComboInput(() -> {
return script.askChoice("Ask Test", "Choose one:", choices, "mo"); return script.askChoice("Ask Test", "Choose one:", choices, "mo");
}); });
assertEquals("meanie", chosen); assertEquals("meanie", chosen);
// Set choice to a different value // Set choice to a different value
String choice_eenie = choices[0]; String choice_eenie = choices.get(0);
chosen = ask_ComboInput(choice_eenie, () -> { chosen = ask_ComboInput(choice_eenie, () -> {
return script.askChoice("Ask Test", "Choose one:", choices, "mo"); return script.askChoice("Ask Test", "Choose one:", choices, "mo");
}); });
assertEquals(choice_eenie, chosen); assertEquals(choice_eenie, chosen);
// See if the last-set value is auto-populated // See if the last-set value is auto-populated
String choice_miney = choices[2]; String choice_miney = choices.get(2);
chosen = ask_ComboInput(() -> { chosen = ask_ComboInput(() -> {
// Note: we are passing a default of 'miney', but expect the last choice of 'eenie' // Note: we are passing a default of 'miney', but expect the last choice of 'eenie'
return script.askChoice("Ask Test", "Choose one:", choices, choice_miney); return script.askChoice("Ask Test", "Choose one:", choices, choice_miney);
@ -681,13 +670,13 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
public void testAskChoiceDefaultValue() throws Exception { public void testAskChoiceDefaultValue() throws Exception {
createScript(); createScript();
String[] choices = new String[] { "one fish", "two fish", "red fish", "blue fish" }; List<String> choices = Arrays.asList("one fish", "two fish", "red fish", "blue fish");
int choiceIndex = 2; int choiceIndex = 2;
String chosen = ask_ComboInput(() -> { String chosen = ask_ComboInput(() -> {
return script.askChoice("Ask Default Choice Test", return script.askChoice("Ask Default Choice Test",
"Which choice would you like to pick?", choices, choices[choiceIndex]); "Which choice would you like to pick?", choices, choices.get(choiceIndex));
}); });
assertEquals(choices[choiceIndex], chosen); assertEquals(choices.get(choiceIndex), chosen);
} }
// TODO test for askChoices() // TODO test for askChoices()
@ -739,8 +728,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
DialogComponentProvider askDialog = waitForDialogComponent(env.getTool().getToolFrame(), DialogComponentProvider askDialog = waitForDialogComponent(DialogComponentProvider.class);
DialogComponentProvider.class, TIMEOUT_MILLIS);
assertNotNull(askDialog); assertNotNull(askDialog);
if (optionalValue != null) { if (optionalValue != null) {
@ -774,8 +762,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
DialogComponentProvider askDialog = waitForDialogComponent(env.getTool().getToolFrame(), DialogComponentProvider askDialog = waitForDialogComponent(DialogComponentProvider.class);
DialogComponentProvider.class, TIMEOUT_MILLIS);
assertNotNull(askDialog); assertNotNull(askDialog);
if (optionalValue != null) { if (optionalValue != null) {
@ -808,8 +795,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
} }
}, false); }, false);
AskDialog askDialog = AskDialog<?> askDialog = waitForDialogComponent(AskDialog.class);
waitForDialogComponent(env.getTool().getToolFrame(), AskDialog.class, TIMEOUT_MILLIS);
assertNotNull(askDialog); assertNotNull(askDialog);
if (optionalValue != null) { if (optionalValue != null) {
@ -890,7 +876,7 @@ public class GhidraScriptAskMethodsTest extends AbstractGhidraHeadedIntegrationT
// test stub // test stub
} }
}; };
script.set(state, TaskMonitorAdapter.DUMMY_MONITOR, null); script.set(state, TaskMonitor.DUMMY, null);
URL url = GhidraScriptTest.class.getResource("GhidraScriptAsk.properties"); URL url = GhidraScriptTest.class.getResource("GhidraScriptAsk.properties");
assertNotNull("Test cannot run without properties file!", url); assertNotNull("Test cannot run without properties file!", url);

View file

@ -44,7 +44,7 @@ import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv; import ghidra.test.TestEnv;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.exception.AssertException; import ghidra.util.exception.AssertException;
import ghidra.util.task.TaskMonitorAdapter; import ghidra.util.task.TaskMonitor;
public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest { public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest {
@ -666,7 +666,6 @@ public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest {
assertEquals(values.size(), userChoices.size()); assertEquals(values.size(), userChoices.size());
} }
@SuppressWarnings("deprecation")
@Test @Test
public void testAskChoices_NoSharedInterface_ChooseMultiple_Deprecated() throws Exception { public void testAskChoices_NoSharedInterface_ChooseMultiple_Deprecated() throws Exception {
@ -674,13 +673,13 @@ public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest {
final GhidraScript script = getScript(); final GhidraScript script = getScript();
Object[] values = { new JPanel(), new String() }; List<Object> values = Arrays.asList(new JPanel(), new String());
String[] labels = { "Panel", "String" }; List<String> labels = Arrays.asList("Panel", "String");
AtomicReference<Object[]> ref = new AtomicReference<>(); AtomicReference<List<Object>> ref = new AtomicReference<>();
runSwing(() -> { runSwing(() -> {
try { try {
Object[] userChoices = List<Object> userChoices =
script.askChoices("Ask Choices Test", "Pick", values, labels); script.askChoices("Ask Choices Test", "Pick", values, labels);
ref.set(userChoices); ref.set(userChoices);
} }
@ -689,16 +688,15 @@ public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest {
} }
}, false); }, false);
MultipleOptionsDialog<?> dialog = waitForDialogComponent(env.getTool().getToolFrame(), MultipleOptionsDialog<?> dialog = waitForDialogComponent(MultipleOptionsDialog.class);
MultipleOptionsDialog.class, DEFAULT_WINDOW_TIMEOUT);
assertNotNull(dialog); assertNotNull(dialog);
pressSelectAll(dialog); pressSelectAll(dialog);
pressButtonByText(dialog, "OK"); pressButtonByText(dialog, "OK");
waitForSwing(); waitForSwing();
Object[] userChoices = ref.get(); List<Object> userChoices = ref.get();
assertEquals(values.length, userChoices.length); assertEquals(values.size(), userChoices.size());
} }
@Test @Test
@ -777,7 +775,7 @@ public class GhidraScriptTest extends AbstractGhidraHeadedIntegrationTest {
// test stub // test stub
} }
}; };
script.set(state, TaskMonitorAdapter.DUMMY_MONITOR, null); script.set(state, TaskMonitor.DUMMY, null);
return script; return script;
} }

View file

@ -18,42 +18,21 @@
// Subfolders at a specific depth from this root form the roots of individual libraries // Subfolders at a specific depth from this root form the roots of individual libraries
// Library Name, Version, and Variant are created from the directory path elements // Library Name, Version, and Variant are created from the directory path elements
//@category FunctionID //@category FunctionID
import java.io.BufferedReader; import java.io.*;
import java.io.File; import java.util.*;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.TreeSet;
import generic.hash.FNV1a64MessageDigest; import generic.hash.FNV1a64MessageDigest;
import generic.hash.MessageDigest; import generic.hash.MessageDigest;
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.feature.fid.db.FidDB; import ghidra.feature.fid.db.*;
import ghidra.feature.fid.db.FidFile;
import ghidra.feature.fid.db.FidFileManager;
import ghidra.feature.fid.db.LibraryRecord;
import ghidra.feature.fid.hash.FidHashQuad; import ghidra.feature.fid.hash.FidHashQuad;
import ghidra.feature.fid.service.FidPopulateResult; import ghidra.feature.fid.service.*;
import ghidra.feature.fid.service.FidPopulateResult.Disposition; import ghidra.feature.fid.service.FidPopulateResult.Disposition;
import ghidra.feature.fid.service.FidPopulateResultReporter; import ghidra.framework.model.*;
import ghidra.feature.fid.service.FidService;
import ghidra.feature.fid.service.Location;
import ghidra.framework.model.DomainFile;
import ghidra.framework.model.DomainFolder;
import ghidra.framework.model.DomainObject;
import ghidra.program.database.ProgramContentHandler; import ghidra.program.database.ProgramContentHandler;
import ghidra.program.model.lang.LanguageID; import ghidra.program.model.lang.LanguageID;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.*;
import ghidra.program.model.listing.FunctionIterator;
import ghidra.program.model.listing.FunctionManager;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.MemoryAccessException; import ghidra.program.model.mem.MemoryAccessException;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
@ -122,7 +101,7 @@ public class CreateMultipleLibraries extends GhidraScript {
} }
} }
outputLine("List of unresolved symbols:"); outputLine("List of unresolved symbols:");
TreeSet<String> symbols = new TreeSet<String>(); TreeSet<String> symbols = new TreeSet<>();
for (Location location : result.getUnresolvedSymbols()) { for (Location location : result.getUnresolvedSymbols()) {
symbols.add(location.getFunctionName()); symbols.add(location.getFunctionName());
} }
@ -183,7 +162,7 @@ public class CreateMultipleLibraries extends GhidraScript {
private boolean checkForDuplicate(ArrayList<DomainFile> programs) throws CancelledException { private boolean checkForDuplicate(ArrayList<DomainFile> programs) throws CancelledException {
String fullName = String fullName =
currentLibraryName + ':' + currentLibraryVersion + ':' + currentLibraryVariant; currentLibraryName + ':' + currentLibraryVersion + ':' + currentLibraryVariant;
ArrayList<Long> hashList = new ArrayList<Long>(); ArrayList<Long> hashList = new ArrayList<>();
for (int i = 0; i < programs.size(); ++i) { for (int i = 0; i < programs.size(); ++i) {
monitor.checkCanceled(); monitor.checkCanceled();
try { try {
@ -216,7 +195,7 @@ public class CreateMultipleLibraries extends GhidraScript {
private boolean detectDups(DomainFolder folder) { private boolean detectDups(DomainFolder folder) {
boolean isDuplicate = false; boolean isDuplicate = false;
try { try {
ArrayList<DomainFile> programs = new ArrayList<DomainFile>(); ArrayList<DomainFile> programs = new ArrayList<>();
findPrograms(programs, folder); findPrograms(programs, folder);
isDuplicate = checkForDuplicate(programs); isDuplicate = checkForDuplicate(programs);
@ -241,7 +220,7 @@ public class CreateMultipleLibraries extends GhidraScript {
return; return;
} }
BufferedReader reader = new BufferedReader(new FileReader(commonSymbolsFile)); BufferedReader reader = new BufferedReader(new FileReader(commonSymbolsFile));
commonSymbols = new LinkedList<String>(); commonSymbols = new LinkedList<>();
String line = reader.readLine(); String line = reader.readLine();
while (line != null) { while (line != null) {
monitor.checkCanceled(); monitor.checkCanceled();
@ -291,7 +270,7 @@ public class CreateMultipleLibraries extends GhidraScript {
} }
private void populateLibrary(DomainFolder folder) { private void populateLibrary(DomainFolder folder) {
ArrayList<DomainFile> programs = new ArrayList<DomainFile>(); ArrayList<DomainFile> programs = new ArrayList<>();
try { try {
findPrograms(programs, folder); findPrograms(programs, folder);
@ -363,16 +342,16 @@ public class CreateMultipleLibraries extends GhidraScript {
// ignore, means we use console // ignore, means we use console
} }
if (askYesNo("Do Duplication Detection", "Do you want to detect duplicates")) { if (askYesNo("Do Duplication Detection", "Do you want to detect duplicates")) {
duplicatemap = new TreeMap<Long, String>(); duplicatemap = new TreeMap<>();
} }
List<FidFile> nonInstallationFidFiles = FidFileManager.getInstance().getUserAddedFiles(); List<FidFile> nonInstallationFidFiles = FidFileManager.getInstance().getUserAddedFiles();
Object[] FidFile = nonInstallationFidFiles.toArray();
if (nonInstallationFidFiles.isEmpty()) { if (nonInstallationFidFiles.isEmpty()) {
throw new FileNotFoundException("Could not find any fidb files that can be populated"); throw new FileNotFoundException("Could not find any fidb files that can be populated");
} }
fidFile = (FidFile) askChoice("Choose destination FidDB", fidFile = askChoice("Choose destination FidDB",
"Please choose the destination FidDB for population", FidFile, FidFile[0]); "Please choose the destination FidDB for population", nonInstallationFidFiles,
nonInstallationFidFiles.get(0));
rootFolder = rootFolder =
askProjectFolder("Select root folder containing all libraries (at a depth of " + askProjectFolder("Select root folder containing all libraries (at a depth of " +

View file

@ -16,6 +16,9 @@
// Opens all programs under a chosen domain folder, scans them for functions // Opens all programs under a chosen domain folder, scans them for functions
// that match a user supplied FID hash and prints info about the matching function // that match a user supplied FID hash and prints info about the matching function
//@category FunctionID //@category FunctionID
import java.io.IOException;
import java.util.*;
import ghidra.app.script.GhidraScript; import ghidra.app.script.GhidraScript;
import ghidra.feature.fid.hash.FidHashQuad; import ghidra.feature.fid.hash.FidHashQuad;
import ghidra.feature.fid.plugin.HashLookupListMode; import ghidra.feature.fid.plugin.HashLookupListMode;
@ -29,9 +32,6 @@ import ghidra.util.NumericUtilities;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.exception.VersionException; import ghidra.util.exception.VersionException;
import java.io.IOException;
import java.util.ArrayList;
public class FindFunctionByHash extends GhidraScript { public class FindFunctionByHash extends GhidraScript {
FidService service; FidService service;
@ -40,24 +40,23 @@ public class FindFunctionByHash extends GhidraScript {
protected void run() throws Exception { protected void run() throws Exception {
service = new FidService(); service = new FidService();
DomainFolder folder = DomainFolder folder = askProjectFolder(
askProjectFolder("Please select a project folder to RECURSIVELY look for a named function:"); "Please select a project folder to RECURSIVELY look for a named function:");
String hashString = String hashString = askString("Please enter function hash",
askString("Please enter function hash", "Please enter the (hex) function hash you're looking for:");
"Please enter the (hex) function hash you're looking for:");
long hash = NumericUtilities.parseHexLong(hashString); long hash = NumericUtilities.parseHexLong(hashString);
HashLookupListMode[] choices = List<HashLookupListMode> choices =
new HashLookupListMode[] { HashLookupListMode.FULL, HashLookupListMode.SPECIFIC }; Arrays.asList(HashLookupListMode.FULL, HashLookupListMode.SPECIFIC);
HashLookupListMode hashType = HashLookupListMode hashType = askChoice("Please choose hash type",
askChoice("Please choose hash type", "Please select the type of hash", choices, "Please select the type of hash", choices, choices.get(1));
choices[1]);
ArrayList<DomainFile> programs = new ArrayList<DomainFile>(); ArrayList<DomainFile> programs = new ArrayList<>();
findPrograms(programs, folder); findPrograms(programs, folder);
findFunction(programs, hash, hashType); findFunction(programs, hash, hashType);
} }
private void findFunction(ArrayList<DomainFile> programs, long hash, HashLookupListMode hashType) { private void findFunction(ArrayList<DomainFile> programs, long hash,
HashLookupListMode hashType) {
for (DomainFile domainFile : programs) { for (DomainFile domainFile : programs) {
if (monitor.isCancelled()) { if (monitor.isCancelled()) {
return; return;
@ -76,7 +75,8 @@ public class FindFunctionByHash extends GhidraScript {
continue; continue;
} }
if ((hashType == HashLookupListMode.FULL && hashQuad.getFullHash() == hash) || if ((hashType == HashLookupListMode.FULL && hashQuad.getFullHash() == hash) ||
(hashType == HashLookupListMode.SPECIFIC && hashQuad.getSpecificHash() == hash)) { (hashType == HashLookupListMode.SPECIFIC &&
hashQuad.getSpecificHash() == hash)) {
println("found " + function.getName() + " at " + function.getEntryPoint() + println("found " + function.getName() + " at " + function.getEntryPoint() +
" in " + domainFile.getPathname()); " in " + domainFile.getPathname());
} }