GP-676 - Updated TableChooserDialog API to allow for bulk transaction

usage
This commit is contained in:
dragonmacher 2021-02-09 17:49:37 -05:00
parent ed3cc10344
commit 83e6e614a5
6 changed files with 118 additions and 488 deletions

View file

@ -40,8 +40,7 @@ import ghidra.program.model.pcode.*;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.ReferenceIterator;
import ghidra.program.util.*;
import ghidra.util.SystemUtilities;
import ghidra.util.UndefinedFunction;
import ghidra.util.*;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.InvalidInputException;
@ -157,10 +156,9 @@ public class ShowConstantUse extends GhidraScript {
}
/**
* Builds the configurable columns for the TableDialog. More columns could
* be added.
* Builds the configurable columns for the TableDialog. More columns could be added.
*
* @param tableChooserDialog
* @param tableChooserDialog the dialog
*/
private void configureTableColumns(TableChooserDialog tableChooserDialog) {
// First column added is the Constant value that is found.
@ -254,8 +252,10 @@ public class ShowConstantUse extends GhidraScript {
@Override
public String getColumnValue(AddressableRowObject rowObject) {
ConstUseLocation entry = (ConstUseLocation) rowObject;
Function func = entry.getProgram().getFunctionManager().getFunctionContaining(
entry.getAddress());
Function func = entry.getProgram()
.getFunctionManager()
.getFunctionContaining(
entry.getAddress());
if (func == null) {
return "";
}
@ -299,7 +299,7 @@ public class ShowConstantUse extends GhidraScript {
* script by creating an artificial ScriptState. This is a useful technique
* for other scripts as well.
*
* @return
* @return the executor
*/
@SuppressWarnings("unused")
private TableChooserExecutor createTableExecutor() {
@ -311,26 +311,22 @@ public class ShowConstantUse extends GhidraScript {
return "Create Structure";
}
@Override
public boolean useBulkTransaction() {
return true;
}
@Override
public boolean execute(AddressableRowObject rowObject) {
ConstUseLocation constLoc = (ConstUseLocation) rowObject;
System.out.println("Follow Structure : " + rowObject.getAddress());
println("Follow Structure : " + rowObject.getAddress());
Program cp = constLoc.getProgram();
Address entry = constLoc.getAddress();
// If we will change something in program, have to open a
// transaction
int trans = cp.startTransaction("Run Script" + entry);
try {
System.out.println("Create Structure at " + entry);
runScript("CreateStructure.java", cp, entry);
}
finally {
cp.endTransaction(trans, true);
}
println("Create Structure at " + entry);
runScript("CreateStructure.java", cp, entry);
return false; // don't remove row from display table
}
@ -347,7 +343,7 @@ public class ShowConstantUse extends GhidraScript {
}
}
catch (Exception exc) {
exc.printStackTrace();
Msg.error(this, "Exception running script", exc);
}
throw new IllegalArgumentException("Script does not exist: " + name);
}
@ -393,7 +389,7 @@ public class ShowConstantUse extends GhidraScript {
* decompiler. In the decompiler this could be a local/parameter at any
* point in the decompiler. In the listing, it must be a parameter variable.
*
* @return
* @return the varnode
*/
private Varnode getVarnodeLocation() {
Varnode var = null;
@ -559,7 +555,7 @@ public class ShowConstantUse extends GhidraScript {
* - accumulate entries. Don't like passing it, but this way the
* user gets immediate feedback as locations are found
* @return a map of Addresses->constants (constants could be NULL)
* @throws CancelledException
* @throws CancelledException if cancelled
*/
private HashMap<Address, Long> backtrackToConstant(Varnode var,
TableChooserDialog tableChooserDialog) throws CancelledException {
@ -587,15 +583,12 @@ public class ShowConstantUse extends GhidraScript {
* Backtrack to a constant given a start position of a parameter of a given
* function Useful if you want to start from a function paramter.
*
* @param f
* - function to start in
* @param paramIndex
* - parameter index to backtrack from
* @param tableChooserDialog
* - accumulate entries. Don't like passing it, but this way the
* user gets immediate feedback as locations are found
* @return a map of Addresses->constants (constants could be NULL)
* @throws CancelledException
* @param f function to start in
* @param paramIndex parameter index to backtrack from
* @param tableChooserDialog accumulate entries. Don't like passing it, but this way the
* user gets immediate feedback as locations are found
* @return a map of Addresses to constants (constants could be NULL)
* @throws CancelledException if cancelled
*/
private HashMap<Address, Long> backtrackParamToConstant(Function f, int paramIndex,
TableChooserDialog tableChooserDialog) throws CancelledException {
@ -699,14 +692,7 @@ public class ShowConstantUse extends GhidraScript {
this.addConstantProblem(tableDialog, address, problem);
}
/**
* Analyze a functions references
*
* @param constUse
* @param funcVarUse
* @param funcList
*/
public void analyzeFunction(HashMap<Address, Long> constUse, DecompInterface decompInterface,
private void analyzeFunction(HashMap<Address, Long> constUse, DecompInterface decompInterface,
Program prog, Function f, Address refAddr, FunctionParamUse funcVarUse, int paramIndex,
ArrayList<PcodeOp> defUseList, ArrayList<FunctionParamUse> funcList) {
if (f == null) {
@ -722,12 +708,9 @@ public class ShowConstantUse extends GhidraScript {
Iterator<PcodeOpAST> ops = hfunction.getPcodeOps(refAddr.getPhysicalAddress());
while (ops.hasNext() && !monitor.isCancelled()) {
PcodeOpAST pcodeOpAST = ops.next();
// System.out.println(pcodeOpAST);
if (pcodeOpAST.getOpcode() == PcodeOp.CALL) {
// get the second parameter
Varnode parm = pcodeOpAST.getInput(paramIndex + 1); // 1st param
// is the
// call dest
Varnode parm = pcodeOpAST.getInput(paramIndex + 1); // 1st param is the call dest
if (parm == null) {
constUse.put(instr.getAddress(), null);
String problem = " *** Warning, it appears that function '" +