Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,24 @@ <H3><A name="Run_Last"></A>Run Last Script <IMG alt="" src="images/play_again.pn
<H3><A name="Script_Quick_Launch"></A>Script Quick Launch</H3>

<BLOCKQUOTE>
<P align="left">This key binding action will show a dialog to allow you to quickly select a
script to be run. You may type any part of the name of the desired script in the dialog's
text field. An asterisc may be used as a globbing character.</P>

<P>You may either use the mouse to choose the desired script from the popup list or press
the Enter key to selected the highlighted list element.</P>
<P align="left">This key binding action shows a dialog to quickly find and run scripts.
The dialog organizes scripts into two sections:</P>

<UL>
<LI>
<B>Recent Scripts</B> - Shows up to 10 of the most recently executed scripts in
most-recently-used (MRU) order. This section only appears if you have run scripts
before.
</LI>
<LI><B>All Scripts</B> - Shows all available scripts in alphabetical order.</LI>
</UL>

<P>Type any part of a script name in the filter field to narrow down the list. The filter
supports wildcard matching using * (any characters) and ? (single character). Use the
up/down arrow keys or mouse to select a script, then press Enter or click OK to run it.</P>

<P>The detail pane on the right displays information about the currently selected script,
including its description, author, category, and assigned keybinding (if any).</P>

<P align="center"><IMG alt="" src="images/ScriptQuickLaunchDialog.png">
</P>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,17 @@ private void createActions() {
private void chooseScript(ActionContext actioncontext1) {

List<ScriptInfo> scriptInfos = provider.getScriptInfos();
ScriptSelectionDialog dialog = new ScriptSelectionDialog(plugin, scriptInfos);

// Get the last run script name to pre-populate the dialog
String initialScript = null;
ResourceFile lastRunScript = provider.getLastRunScript();
if (lastRunScript != null) {
initialScript = lastRunScript.getName();
}

ScriptSelectionDialog dialog =
new ScriptSelectionDialog(plugin, scriptInfos, provider.getRecentScripts(),
initialScript);
dialog.show();

ScriptInfo chosenInfo = dialog.getUserChoice();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
private static final double TOP_PREFERRED_RESIZE_WEIGHT = .80;
private static final String DESCRIPTION_DIVIDER_LOCATION = "DESCRIPTION_DIVIDER_LOCATION";
private static final String FILTER_TEXT = "FILTER_TEXT";
private static final String RECENT_SCRIPTS = "RECENT_SCRIPTS";
private static final int MAX_RECENT_SCRIPTS = 10;

private Map<ResourceFile, GhidraScriptEditorComponentProvider> editorMap = new HashMap<>();
private final GhidraScriptMgrPlugin plugin;
Expand All @@ -88,6 +90,7 @@ public class GhidraScriptComponentProvider extends ComponentProviderAdapter {
private String[] previousCategory;

private ResourceFile lastRunScript;
private LinkedList<String> recentScripts = new LinkedList<>();
private WeakSet<RunScriptTask> runningScriptTaskSet =
WeakDataStructureFactory.createCopyOnReadWeakSet();
private TaskListener cleanupTaskSetListener = new TaskListener() {
Expand Down Expand Up @@ -311,6 +314,12 @@ public void componentResized(ComponentEvent e) {

String filterText = saveState.getString(FILTER_TEXT, "");
tableFilterPanel.setFilterText(filterText);

String[] scripts = saveState.getStrings(RECENT_SCRIPTS, new String[0]);
recentScripts.clear();
for (String script : scripts) {
recentScripts.add(script);
}
}

/**
Expand All @@ -332,6 +341,9 @@ public void writeConfigState(SaveState saveState) {

String filterText = tableFilterPanel.getFilterText();
saveState.putString(FILTER_TEXT, filterText);

String[] scripts = recentScripts.toArray(new String[0]);
saveState.putStrings(RECENT_SCRIPTS, scripts);
}

void dispose() {
Expand Down Expand Up @@ -364,6 +376,10 @@ Map<ResourceFile, GhidraScriptEditorComponentProvider> getEditorMap() {
return editorMap;
}

LinkedList<String> getRecentScripts() {
return recentScripts;
}

void assignKeyBinding() {
ResourceFile script = getSelectedScript();
ScriptAction action = actionManager.createAction(script);
Expand Down Expand Up @@ -664,6 +680,16 @@ void runScript(ResourceFile scriptFile) {

void runScript(ResourceFile scriptFile, TaskListener listener) {
lastRunScript = scriptFile;

// Update recent scripts list
String scriptName = scriptFile.getName();
recentScripts.remove(scriptName);
recentScripts.addFirst(scriptName); // Add to front (most recent)

while (recentScripts.size() > MAX_RECENT_SCRIPTS) {
recentScripts.removeLast();
}

GhidraScript script = doGetScriptInstance(scriptFile);
if (script != null) {
doRunScript(script, listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -16,17 +16,28 @@
package ghidra.app.plugin.core.script;

/**
* A simple listener to know when users have chosen a script in the {@link ScriptSelectionDialog}
* Categories for organizing scripts in the Script Quick Launch dialog.
*/
public interface ScriptEditorListener {
public enum ScriptGroup {
RECENT_SCRIPTS("Recent Scripts"),
ALL_SCRIPTS("All Scripts");

private String displayName;

private ScriptGroup(String displayName) {
this.displayName = displayName;
}

/**
* Called when the user makes a selection.
*/
public void editingStopped();
public String getDisplayName() {
return displayName;
}

/**
* Called when the user cancels the script selection process.
*/
public void editingCancelled();
public static ScriptGroup getGroupByDisplayName(String name) {
for (ScriptGroup group : values()) {
if (group.getDisplayName().equals(name)) {
return group;
}
}
return null;
}
}
Loading