GP-5641 update SetExecutableCategoryScript

This commit is contained in:
James 2025-05-15 16:50:59 -04:00
parent 18d73945da
commit d2d0c989f9

View file

@ -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.
@ -16,6 +16,7 @@
import org.apache.commons.lang3.StringUtils;
import ghidra.app.script.GhidraScript;
import ghidra.features.base.values.GhidraValuesMap;
import ghidra.framework.options.Options;
import ghidra.program.model.listing.Program;
@ -23,6 +24,8 @@ import ghidra.program.model.listing.Program;
//sets a property on the current program which can be used as
//an executable category in BSim
public class SetExecutableCategoryScript extends GhidraScript {
private static final String PROPERTY_NAME = "Property Name";
private static final String PROPERTY_VALUE = "Property Value";
@Override
protected void run() throws Exception {
@ -30,16 +33,27 @@ public class SetExecutableCategoryScript extends GhidraScript {
popup("This script requires a program");
return;
}
GhidraValuesMap valuesMap = new GhidraValuesMap();
valuesMap.defineString(PROPERTY_NAME);
valuesMap.defineString(PROPERTY_VALUE);
valuesMap.setValidator((values, status) -> {
String name = valuesMap.getString(PROPERTY_NAME);
if (StringUtils.isAllBlank(name)) {
status.setStatusText("Name cannot be blank");
return false;
}
String value = valuesMap.getString(PROPERTY_VALUE);
if (StringUtils.isAllBlank(value)) {
status.setStatusText("Value cannot be blank");
return false;
}
return true;
});
askValues("Set Program Property", "Set Program Property", valuesMap);
Options opts = currentProgram.getOptions(Program.PROGRAM_INFO);
String name = askString("Enter Property Name", "Name");
if (StringUtils.isAllBlank(name)) {
return;
}
String value = askString("Enter Value of Property " + name, "Value");
if (StringUtils.isAllBlank(value)) {
return;
}
opts.setString(name, value);
opts.setString(valuesMap.getString(PROPERTY_NAME), valuesMap.getString(PROPERTY_VALUE));
}
}