mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 19:42:36 +02:00
GP-4085 Added ability to add VTSession to a shared repository
This commit is contained in:
parent
b8f004c792
commit
c3386b72a2
33 changed files with 1063 additions and 565 deletions
|
@ -13,6 +13,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// A script that runs Auto Version Tracking given the options set in one of the following ways:
|
||||
// 1. If script is run from the CodeBrowser, the GUI options are set in a pop up dialog by user.
|
||||
// 2. If script is run in headless mode either the defaults provided by the script are used or the
|
||||
|
@ -129,67 +130,72 @@ public class AutoVersionTrackingScript extends GhidraScript {
|
|||
Program otherProgram = startupValues.getProgram("Please select the other program", this,
|
||||
state.getTool(), autoUpgradeIfNeeded);
|
||||
|
||||
if (isCurrentProgramSourceProg) {
|
||||
sourceProgram = currentProgram;
|
||||
destinationProgram = otherProgram;
|
||||
}
|
||||
else {
|
||||
destinationProgram = currentProgram;
|
||||
sourceProgram = otherProgram;
|
||||
}
|
||||
|
||||
if (sourceProgram == null || destinationProgram == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Need to end the script transaction or it interferes with vt things that need locks
|
||||
end(true);
|
||||
|
||||
VTSession session =
|
||||
VTSessionDB.createVTSession(name, sourceProgram, destinationProgram, this);
|
||||
|
||||
if (folder.getFile(name) == null) {
|
||||
folder.createFile(name, session, monitor);
|
||||
}
|
||||
|
||||
// create a default options map in case cannot get user input
|
||||
GhidraValuesMap optionsMap = createDefaultOptions();
|
||||
|
||||
// if running script in GUI get options from user and update the vtOptions with them
|
||||
if (!isRunningHeadless()) {
|
||||
optionsMap = getOptionsFromUser();
|
||||
|
||||
}
|
||||
// else if running script in headless get possible options set by prescript that saves
|
||||
// optionsMap in script state variable and update the vtOptions with them
|
||||
else {
|
||||
// try to get options map from state if running headless
|
||||
// if user runs prescript to set up their own options map those options will be used
|
||||
// See SetAutoVersionTrackingOptionsScript.java as an example
|
||||
GhidraValuesMap stateOptionsMap =
|
||||
(GhidraValuesMap) state.getEnvironmentVar("autoVTOptionsMap");
|
||||
if (optionsMap != null) {
|
||||
optionsMap = stateOptionsMap;
|
||||
VTSession session = null;
|
||||
try {
|
||||
if (isCurrentProgramSourceProg) {
|
||||
sourceProgram = currentProgram;
|
||||
destinationProgram = otherProgram;
|
||||
}
|
||||
else {
|
||||
destinationProgram = currentProgram;
|
||||
sourceProgram = otherProgram;
|
||||
}
|
||||
|
||||
}
|
||||
if (sourceProgram == null || destinationProgram == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ToolOptions vtOptions = setToolOptionsFromOptionsMap(optionsMap);
|
||||
// Need to end the script transaction or it interferes with vt things that need locks
|
||||
end(true);
|
||||
|
||||
AutoVersionTrackingTask autoVtTask = new AutoVersionTrackingTask(session, vtOptions);
|
||||
session = new VTSessionDB(name, sourceProgram, destinationProgram, this);
|
||||
|
||||
TaskLauncher.launch(autoVtTask);
|
||||
if (folder.getFile(name) == null) {
|
||||
folder.createFile(name, session, monitor);
|
||||
}
|
||||
|
||||
// if not running headless user can decide whether to save or not
|
||||
// if running headless - must save here or nothing that was done in this script will be
|
||||
// accessible later.
|
||||
if (isRunningHeadless()) {
|
||||
// create a default options map in case cannot get user input
|
||||
GhidraValuesMap optionsMap = createDefaultOptions();
|
||||
|
||||
// if running script in GUI get options from user and update the vtOptions with them
|
||||
if (!isRunningHeadless()) {
|
||||
optionsMap = getOptionsFromUser();
|
||||
|
||||
}
|
||||
// else if running script in headless get possible options set by prescript that saves
|
||||
// optionsMap in script state variable and update the vtOptions with them
|
||||
else {
|
||||
// try to get options map from state if running headless
|
||||
// if user runs prescript to set up their own options map those options will be used
|
||||
// See SetAutoVersionTrackingOptionsScript.java as an example
|
||||
GhidraValuesMap stateOptionsMap =
|
||||
(GhidraValuesMap) state.getEnvironmentVar("autoVTOptionsMap");
|
||||
if (optionsMap != null) {
|
||||
optionsMap = stateOptionsMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ToolOptions vtOptions = setToolOptionsFromOptionsMap(optionsMap);
|
||||
|
||||
AutoVersionTrackingTask autoVtTask = new AutoVersionTrackingTask(session, vtOptions);
|
||||
|
||||
TaskLauncher.launch(autoVtTask);
|
||||
|
||||
// Save destination program and session changes
|
||||
otherProgram.save("Updated with Auto Version Tracking", monitor);
|
||||
session.save();
|
||||
}
|
||||
|
||||
println(autoVtTask.getStatusMsg());
|
||||
otherProgram.release(this);
|
||||
println(autoVtTask.getStatusMsg());
|
||||
}
|
||||
finally {
|
||||
if (otherProgram != null) {
|
||||
otherProgram.release(this);
|
||||
}
|
||||
if (session != null) {
|
||||
session.release(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,8 +63,7 @@ public class CreateAppliedExactMatchingSessionScript extends GhidraScript {
|
|||
return;
|
||||
}
|
||||
|
||||
VTSession session =
|
||||
VTSessionDB.createVTSession(name, sourceProgram, destinationProgram, this);
|
||||
VTSession session = new VTSessionDB(name, sourceProgram, destinationProgram, this);
|
||||
|
||||
// it seems clunky to have to create this separately, but I'm not sure how else to do it
|
||||
folder.createFile(name, session, monitor);
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import ghidra.feature.vt.GhidraVersionTrackingScript;
|
||||
import ghidra.feature.vt.AbstractGhidraVersionTrackingScript;
|
||||
import ghidra.feature.vt.api.main.VTMatch;
|
||||
import ghidra.framework.model.Project;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
public class FindChangedFunctionsScript extends GhidraVersionTrackingScript {
|
||||
public class FindChangedFunctionsScript extends AbstractGhidraVersionTrackingScript {
|
||||
|
||||
private Program p1;
|
||||
private Program p2;
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import ghidra.feature.vt.GhidraVersionTrackingScript;
|
||||
import ghidra.feature.vt.AbstractGhidraVersionTrackingScript;
|
||||
import ghidra.feature.vt.api.main.*;
|
||||
|
||||
public class OpenVersionTrackingSessionScript extends GhidraVersionTrackingScript {
|
||||
public class OpenVersionTrackingSessionScript extends AbstractGhidraVersionTrackingScript {
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
|
@ -33,6 +33,9 @@ public class OpenVersionTrackingSessionScript extends GhidraVersionTrackingScrip
|
|||
}
|
||||
|
||||
private void acceptMatchesWithGoodConfidence() throws Exception {
|
||||
|
||||
VTSession vtSession = getVTSession();
|
||||
|
||||
println("Working on session: " + vtSession);
|
||||
|
||||
List<VTMatchSet> matchSets = vtSession.getMatchSets();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue