mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GT-2927 - Fixed Listing cursor not restoring correctly at startup
This commit is contained in:
parent
b047d8430e
commit
12fffa922e
2 changed files with 54 additions and 57 deletions
|
@ -450,7 +450,7 @@ public abstract class ByteViewerComponentProvider extends ComponentProviderAdapt
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStatusMessage(String message) {
|
void setStatusMessage(String message) {
|
||||||
plugin.setStatusMessage(message, this);
|
plugin.setStatusMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setEditMode(boolean isEditable) {
|
void setEditMode(boolean isEditable) {
|
||||||
|
|
|
@ -15,6 +15,13 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.core.byteviewer;
|
package ghidra.app.plugin.core.byteviewer;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.jdom.Element;
|
||||||
|
|
||||||
|
import docking.ActionContext;
|
||||||
|
import docking.action.DockingAction;
|
||||||
|
import docking.action.ToolBarData;
|
||||||
import ghidra.app.CorePluginPackage;
|
import ghidra.app.CorePluginPackage;
|
||||||
import ghidra.app.events.*;
|
import ghidra.app.events.*;
|
||||||
import ghidra.app.plugin.PluginCategoryNames;
|
import ghidra.app.plugin.PluginCategoryNames;
|
||||||
|
@ -24,20 +31,12 @@ import ghidra.framework.model.DomainObject;
|
||||||
import ghidra.framework.options.SaveState;
|
import ghidra.framework.options.SaveState;
|
||||||
import ghidra.framework.plugintool.*;
|
import ghidra.framework.plugintool.*;
|
||||||
import ghidra.framework.plugintool.util.PluginStatus;
|
import ghidra.framework.plugintool.util.PluginStatus;
|
||||||
|
import ghidra.generic.function.Callback;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.util.ProgramLocation;
|
import ghidra.program.util.ProgramLocation;
|
||||||
import ghidra.program.util.ProgramSelection;
|
import ghidra.program.util.ProgramSelection;
|
||||||
import ghidra.util.SystemUtilities;
|
import ghidra.util.SystemUtilities;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.jdom.Element;
|
|
||||||
|
|
||||||
import resources.ResourceManager;
|
import resources.ResourceManager;
|
||||||
import docking.ActionContext;
|
|
||||||
import docking.ComponentProvider;
|
|
||||||
import docking.action.DockingAction;
|
|
||||||
import docking.action.ToolBarData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visible Plugin to show ByteBlock data in various formats.
|
* Visible Plugin to show ByteBlock data in various formats.
|
||||||
|
@ -63,7 +62,7 @@ import docking.action.ToolBarData;
|
||||||
public class ByteViewerPlugin extends Plugin {
|
public class ByteViewerPlugin extends Plugin {
|
||||||
|
|
||||||
private Program currentProgram;
|
private Program currentProgram;
|
||||||
private boolean restoringTransientState;
|
private boolean isRestoringState;
|
||||||
private ProgramLocation currentLocation;
|
private ProgramLocation currentLocation;
|
||||||
|
|
||||||
private ProgramByteViewerComponentProvider connectedProvider;
|
private ProgramByteViewerComponentProvider connectedProvider;
|
||||||
|
@ -86,8 +85,8 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
showConnectedProvider();
|
showConnectedProvider();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
action.setToolBarData(new ToolBarData(ResourceManager.loadImage("images/binaryData.gif"),
|
action.setToolBarData(
|
||||||
"View"));
|
new ToolBarData(ResourceManager.loadImage("images/binaryData.gif"), "View"));
|
||||||
|
|
||||||
action.setDescription("Display Bytes");
|
action.setDescription("Display Bytes");
|
||||||
action.setEnabled(true);
|
action.setEnabled(true);
|
||||||
|
@ -157,11 +156,12 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
|
|
||||||
public void fireProgramLocationPluginEvent(ProgramByteViewerComponentProvider provider,
|
public void fireProgramLocationPluginEvent(ProgramByteViewerComponentProvider provider,
|
||||||
ProgramLocationPluginEvent event) {
|
ProgramLocationPluginEvent event) {
|
||||||
|
|
||||||
if (SystemUtilities.isEqual(event.getLocation(), currentLocation)) {
|
if (SystemUtilities.isEqual(event.getLocation(), currentLocation)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentLocation = event.getLocation();
|
|
||||||
|
|
||||||
|
currentLocation = event.getLocation();
|
||||||
if (provider == connectedProvider) {
|
if (provider == connectedProvider) {
|
||||||
firePluginEvent(event);
|
firePluginEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -192,30 +192,35 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readDataState(SaveState saveState) {
|
public void readDataState(SaveState saveState) {
|
||||||
ProgramManager programManagerService = tool.getService(ProgramManager.class);
|
|
||||||
|
|
||||||
connectedProvider.readDataState(saveState);
|
restore(() -> {
|
||||||
|
|
||||||
int numDisconnected = saveState.getInt("Num Disconnected", 0);
|
ProgramManager programManagerService = tool.getService(ProgramManager.class);
|
||||||
for (int i = 0; i < numDisconnected; i++) {
|
|
||||||
Element xmlElement = saveState.getXmlElement("Provider" + i);
|
connectedProvider.readDataState(saveState);
|
||||||
SaveState providerSaveState = new SaveState(xmlElement);
|
|
||||||
String programPath = providerSaveState.getString("Program Path", "");
|
int numDisconnected = saveState.getInt("Num Disconnected", 0);
|
||||||
DomainFile file = tool.getProject().getProjectData().getFile(programPath);
|
for (int i = 0; i < numDisconnected; i++) {
|
||||||
if (file == null) {
|
Element xmlElement = saveState.getXmlElement("Provider" + i);
|
||||||
continue;
|
SaveState providerSaveState = new SaveState(xmlElement);
|
||||||
|
String programPath = providerSaveState.getString("Program Path", "");
|
||||||
|
DomainFile file = tool.getProject().getProjectData().getFile(programPath);
|
||||||
|
if (file == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Program program = programManagerService.openProgram(file);
|
||||||
|
if (program != null) {
|
||||||
|
ProgramByteViewerComponentProvider provider =
|
||||||
|
new ProgramByteViewerComponentProvider(tool, this, false);
|
||||||
|
provider.doSetProgram(program);
|
||||||
|
provider.readConfigState(providerSaveState);
|
||||||
|
provider.readDataState(providerSaveState);
|
||||||
|
tool.showComponentProvider(provider, true);
|
||||||
|
addProvider(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Program program = programManagerService.openProgram(file);
|
|
||||||
if (program != null) {
|
});
|
||||||
ProgramByteViewerComponentProvider provider =
|
|
||||||
new ProgramByteViewerComponentProvider(tool, this, false);
|
|
||||||
provider.doSetProgram(program);
|
|
||||||
provider.readConfigState(providerSaveState);
|
|
||||||
provider.readDataState(providerSaveState);
|
|
||||||
tool.showComponentProvider(provider, true);
|
|
||||||
addProvider(provider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,8 +297,6 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransientState() {
|
public Object getTransientState() {
|
||||||
Object[] state = new Object[2];
|
Object[] state = new Object[2];
|
||||||
|
@ -307,37 +310,31 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see ghidra.framework.plugintool.Plugin#restoreTransientState(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void restoreTransientState(Object objectState) {
|
public void restoreTransientState(Object objectState) {
|
||||||
restoringTransientState = true;
|
|
||||||
try {
|
restore(() -> {
|
||||||
Object[] state = (Object[]) objectState;
|
Object[] state = (Object[]) objectState;
|
||||||
|
|
||||||
connectedProvider.restoreLocation((SaveState) state[0]);
|
connectedProvider.restoreLocation((SaveState) state[0]);
|
||||||
|
|
||||||
connectedProvider.setSelection((ProgramSelection) state[1]);
|
connectedProvider.setSelection((ProgramSelection) state[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restore(Callback callback) {
|
||||||
|
isRestoringState = true;
|
||||||
|
try {
|
||||||
|
callback.call();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
restoringTransientState = false;
|
isRestoringState = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
boolean isRestoringState() {
|
||||||
// *** package-level methods ***
|
return isRestoringState;
|
||||||
/////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
boolean isRestoringTransientState() {
|
|
||||||
return restoringTransientState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void setStatusMessage(String msg) {
|
||||||
* Set the status info on the tool.
|
|
||||||
*/
|
|
||||||
void setStatusMessage(String msg, ComponentProvider provider) {
|
|
||||||
tool.setStatusInfo(msg);
|
tool.setStatusInfo(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +380,7 @@ public class ByteViewerPlugin extends Plugin {
|
||||||
public void updateLocation(ProgramByteViewerComponentProvider provider,
|
public void updateLocation(ProgramByteViewerComponentProvider provider,
|
||||||
ProgramLocationPluginEvent event, boolean export) {
|
ProgramLocationPluginEvent event, boolean export) {
|
||||||
|
|
||||||
if (isRestoringTransientState()) {
|
if (isRestoringState()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue