GP-0 ignore reserved SaveState key when restoring AnalysisStateInfo

This commit is contained in:
ghidra1 2020-12-11 19:05:56 -05:00
parent e32276b5bd
commit e1e9dc0f8f
3 changed files with 21 additions and 7 deletions

View File

@ -39,6 +39,9 @@ public class StoredAnalyzerTimes implements CustomOption {
public void readState(SaveState saveState) {
taskTimes.clear();
for (String taskName : saveState.getNames()) {
if (CustomOption.CUSTOM_OPTION_CLASS_NAME_KEY.equals(taskName)) {
continue; // skip this reserved key
}
taskTimes.put(taskName, saveState.getLong(taskName, 0));
}
names = null;

View File

@ -17,6 +17,15 @@ package ghidra.framework.options;
public interface CustomOption {
/**
* <code>SaveState</code> key which corresponds to custom option
* implementation class. The use of this key/value within the stored
* state information is reserved for use by the option storage
* implementation and should be ignored by {@link #readState(SaveState)}
* implementation
*/
public final String CUSTOM_OPTION_CLASS_NAME_KEY = "CUSTOM_OPTION_CLASS";
/**
* Concrete subclass of WrappedOption should read all of its
* state from the given saveState object.

View File

@ -100,14 +100,14 @@ public enum OptionType {
static class IntStringAdapter extends StringAdapter {
@Override
Object stringToObject(String string) {
return new Integer(string);
return Integer.valueOf(string);
}
}
static class LongStringAdapter extends StringAdapter {
@Override
Object stringToObject(String string) {
return new Long(string);
return Long.valueOf(string);
}
}
@ -121,7 +121,7 @@ public enum OptionType {
static class DoubleStringAdapter extends StringAdapter {
@Override
Object stringToObject(String string) {
return new Double(string);
return Double.valueOf(string);
}
}
@ -155,7 +155,7 @@ public enum OptionType {
static class FloatStringAdapter extends StringAdapter {
@Override
Object stringToObject(String string) {
return new Float(string);
return Float.valueOf(string);
}
}
@ -216,10 +216,11 @@ public enum OptionType {
@Override
Object stringToObject(String string) {
SaveState saveState = getSaveStateFromXmlString(string);
String customOptionClassName = saveState.getString("CUSTOM_OPTION_CLASS", null);
String customOptionClassName =
saveState.getString(CustomOption.CUSTOM_OPTION_CLASS_NAME_KEY, null);
try {
Class<?> c = Class.forName(customOptionClassName);
CustomOption option = (CustomOption) c.newInstance();
CustomOption option = (CustomOption) c.getConstructor().newInstance();
option.readState(saveState);
return option;
}
@ -239,7 +240,8 @@ public enum OptionType {
String objectToString(Object object) {
CustomOption customOption = (CustomOption) object;
SaveState saveState = new SaveState();
saveState.putString("CUSTOM_OPTION_CLASS", object.getClass().getName());
saveState.putString(CustomOption.CUSTOM_OPTION_CLASS_NAME_KEY,
object.getClass().getName());
customOption.writeState(saveState);
return saveToXmlString(saveState);
}