From f94e451d6b1780ef7d2445d572ed1f9f990ed92d Mon Sep 17 00:00:00 2001
From: dragonmacher <48328597+dragonmacher@users.noreply.github.com>
Date: Fri, 5 Jul 2019 08:31:17 -0400
Subject: [PATCH] GT-2949 - Scripting - removed old deprecated methods
---
.../java/ghidra/app/script/GhidraScript.java | 303 +-----------------
.../app/script/GhidraScriptProperties.java | 9 +-
2 files changed, 21 insertions(+), 291 deletions(-)
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScript.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScript.java
index 328e9c8479..0bf7597429 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScript.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/GhidraScript.java
@@ -17,11 +17,9 @@ package ghidra.app.script;
import java.awt.Color;
import java.io.*;
-import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.rmi.ConnectException;
import java.util.*;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;
@@ -262,15 +260,12 @@ public abstract class GhidraScript extends FlatProgramAPI {
}
private void doCleanup(boolean success) {
-
- // TODO transient cleanup
-
cleanup(success);
}
/**
- * Will ye, nill ye?
- * @param success
+ * A callback for scripts to perform any needed cleanup after the script is finished
+ * @param success true if the script was successful
*/
public void cleanup(boolean success) {
// for users to override
@@ -296,7 +291,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
*
* @param dirLocation String representation of the path to the .properties file
* @param basename base name of the file
- * @throws IOException
+ * @throws IOException if there is an exception loading the new properties file
*/
public void setPropertiesFileLocation(String dirLocation, String basename) throws IOException {
File testIfDir = new File(dirLocation);
@@ -407,23 +402,6 @@ public abstract class GhidraScript extends FlatProgramAPI {
return false;
}
- /**
- * Starts auto-analysis on the specified program and performs complete analysis
- * of the entire program. This is usually only necessary if full analysis was never
- * performed. This method blocks until analysis completes.
- *
- * @param program the program to analyze
- * @deprecated the method {@link #analyzeAll} or {@link #analyzeChanges} should be invoked.
- * These separate methods were created to clarify their true behavior since many times it is
- * only necessary to analyze changes and not the entire program which can take much
- * longer and affect more of the program than is necessary.
- */
- @Deprecated
- @Override
- public void analyze(Program program) {
- analyzeAll(program);
- }
-
@Override
public void analyzeAll(Program program) {
if (program == null) {
@@ -508,7 +486,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
/**
* Set associated source file
- * @param sourceFile
+ * @param sourceFile the source file
*/
public final void setSourceFile(ResourceFile sourceFile) {
this.sourceFile = sourceFile;
@@ -617,19 +595,6 @@ public abstract class GhidraScript extends FlatProgramAPI {
return null;
}
- /**
- * This method is no longer supported.
- * Calling it will result in an UnsupportedOperationException being thrown.
- * @param name the name of the script
- *
- * @deprecated you can no longer change a script's name
- * @throws UnsupportedOperationException
- */
- @Deprecated
- public void setName(String name) {
- throw new UnsupportedOperationException("You cannot change a script's name.");
- }
-
/**
* Returns the username of the user running the script.
* @return the username of the user running the script
@@ -1099,22 +1064,6 @@ public abstract class GhidraScript extends FlatProgramAPI {
}
}
- /**
- * Returns a list of valid choices, given an analysis option name (if they exist for this
- * option). If the analysis option is unconstrained (does not have to be one of a list
- * of specific options), returns an empty array.
- *
- * @param program the program to get analysis option choices from
- * @param analysisOption the analysis option to get choices for
- * @return an String array of the only valid choices for this analysis option (array is empty if
- * choices are unconstrained)
- * @deprecated
- */
- @Deprecated
- public String[] getAnalysisOptionChoices(Program program, String analysisOption) {
- return new String[0];
- }
-
/**
* Returns the description of an analysis option name, as provided by the analyzer. This
* method returns an empty string if no description is available.
@@ -2086,7 +2035,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
chooser.setFileSelectionMode(GhidraFileChooserMode.FILES_ONLY);
ref.set(chooser.getSelectedFile());
};
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (chooser.wasCancelled()) {
throw new CancelledException();
@@ -2169,7 +2118,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
chooser.setFileSelectionMode(GhidraFileChooserMode.DIRECTORIES_ONLY);
ref.set(chooser.getSelectedFile());
};
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (chooser.wasCancelled()) {
throw new CancelledException();
@@ -2276,7 +2225,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
dialog.setSelectedLanguage(lastValue);
ref.set(dialog.getSelectedLanguage());
};
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dialog.wasCancelled()) {
throw new CancelledException();
@@ -2358,7 +2307,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
});
Runnable r = () -> dtd.showComponent();
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dtd.wasCancelled()) {
throw new CancelledException();
@@ -2726,7 +2675,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
});
Runnable r = () -> dtd.showComponent();
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dtd.wasCancelled()) {
throw new CancelledException();
@@ -2818,7 +2767,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
});
Runnable r = () -> dtd.showComponent();
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dtd.wasCancelled()) {
throw new CancelledException();
@@ -3218,7 +3167,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
new MultipleOptionsDialog<>(title, message, choices, true);
Runnable r = () -> reference.set(dialog.getUserChoices());
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dialog.isCanceled()) {
throw new CancelledException();
@@ -3295,7 +3244,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
new MultipleOptionsDialog<>(title, message, choices, choiceLabels, true);
Runnable r = () -> reference.set(dialog.getUserChoices());
- SystemUtilities.runSwingNow(r);
+ Swing.runNow(r);
if (dialog.isCanceled()) {
throw new CancelledException();
@@ -3366,16 +3315,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
return existingValue;
}
- AtomicBoolean yesno = new AtomicBoolean();
-
- Runnable r = () -> {
- int choice = OptionDialog.showYesNoDialog(null, title, question);
- yesno.set(choice == OptionDialog.OPTION_ONE);
- };
-
- SystemUtilities.runSwingNow(r);
-
- return yesno.get();
+ return OptionDialog.showYesNoDialog(null, title, question) == OptionDialog.OPTION_ONE;
}
/**
@@ -3772,7 +3712,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
Color.GREEN, null, "Script Results", null);
tableProvider.installRemoveItemsAction();
};
- SystemUtilities.runSwingLater(runnable);
+ Swing.runLater(runnable);
}
private void show(final String title, final TableService table,
@@ -3790,7 +3730,7 @@ public abstract class GhidraScript extends FlatProgramAPI {
"GhidraScript", model, Color.GREEN, null, "Script Results", null);
tableProvider.installRemoveItemsAction();
};
- SystemUtilities.runSwingLater(runnable);
+ Swing.runLater(runnable);
}
private Map
- * If the console is cleared, this number is reset.
- *
- * @return the text in the console, in a String of length >= 0
- * @deprecated deemed not worth supporting due to lack of value
- */
- @Deprecated
- public int getConsoleTextLength() {
- PluginTool tool = state.getTool();
- if (tool == null) {
- return 0;
- }
-
- ConsoleService console = tool.getService(ConsoleService.class);
- if (console == null) {
- return 0;
- }
-
- return console.getTextLength();
- }
-
-//==================================================================================================
-// Deprecated Methods - version 3 - Nov 30 - Ghidra 7.5
-//==================================================================================================
-
- /**
- * Returns an array of Objects representing one or more choices from the given list. The actual
- * behavior of the method depends on your environment, which can be GUI or headless.
- *
- * Regardless of environment -- if script arguments have been set, this method will use the
- * next argument in the array and advance the array index so the next call to an ask method
- * will get the next argument. If there are no script arguments and a .properties file
- * sharing the same base name as the Ghidra Script exists (i.e., Script1.properties for
- * Script1.java), then this method will then look there for the String value to return.
- * The method will look in the .properties file by searching for a property name that is a
- * space-separated concatenation of the input String parameters (title + " " + message).
- * If that property name exists and its value represents valid choices, then the
- * .properties value will be used in the following way:
- *
- * Regardless of environment -- if script arguments have been set, this method will use the
- * next argument in the array and advance the array index so the next call to an ask method
- * will get the next argument. If there are no script arguments and a .properties file
- * sharing the same base name as the Ghidra Script exists (i.e., Script1.properties for
- * Script1.java), then this method will then look there for the String value to return.
- * The method will look in the .properties file by searching for a property name that is a
- * space-separated concatenation of the input String parameters (title + " " + message).
- * If that property name exists and its value represents a valid choice, then the
- * .properties value will be used in the following way:
- *
- *
- *
- * @param title the title of the dialog (in GUI mode) or the first part of the variable name
- * (in headless mode or when using .properties file)
- * @param message the message to display with the choices (in GUI mode) or the second
- * part of the variable name (in headless mode or when using .properties file)
- * @param choices set of choices (toString() value of each object will be displayed in the dialog)
- * @return the user-selected value(s); null if no selection was made
- *
- * @throws CancelledException if the user hits the 'cancel' button
- * @throws IllegalArgumentException if in headless mode, there was a missing or invalid set of
- * choices specified in the .properties file
- * @deprecated use {@link #askChoices(String, String, List)} instead.
- * Deprecated in 7.5
- */
- @Deprecated
- @SuppressWarnings("unchecked")
- public
- *
- *
- * Regardless of environment -- if script arguments have been set, this method will use the - * next argument in the array and advance the array index so the next call to an ask method - * will get the next argument. If there are no script arguments and a .properties file - * sharing the same base name as the Ghidra Script exists (i.e., Script1.properties for - * Script1.java), then this method will then look there for the String value to return. - * The method will look in the .properties file by searching for a property name that is a - * space-separated concatenation of the input String parameters (title + " " + message). - * If that property name exists and its value represents valid choices, then the - * .properties value will be used in the following way: - *