avoid calling GhidraScriptUtils.getScriptSourceDirectories

- when called from the GUI, the bundle host manages paths
- when used to find a script by name, use findScriptByName
This commit is contained in:
Jason P. Leasure 2020-04-28 17:23:08 -04:00
parent 2b49816c6c
commit 7ee2467016
7 changed files with 135 additions and 156 deletions

View file

@ -113,8 +113,8 @@ public class ShowConstantUse extends GhidraScript {
for (int i = 0; i < clangStmt.numChildren(); i++) {
ClangNode child = clangStmt.Child(i);
if (child.equals(clangVar)) {
constLocs =
backtrackParamToConstant(f, paramIndex, tableDialog);
constLocs = backtrackParamToConstant(f, paramIndex,
tableDialog);
break;
}
if (child instanceof ClangVariableToken) {
@ -254,9 +254,8 @@ 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 "";
}
@ -336,20 +335,15 @@ public class ShowConstantUse extends GhidraScript {
}
public void runScript(String name, Program prog, Address loc) {
GhidraState scriptState =
new GhidraState(state.getTool(), state.getProject(), prog, new ProgramLocation(
prog, loc), null, null);
GhidraState scriptState = new GhidraState(state.getTool(), state.getProject(), prog,
new ProgramLocation(prog, loc), null, null);
try {
List<ResourceFile> dirs = GhidraScriptUtil.getScriptSourceDirectories();
for (ResourceFile dir : dirs) {
ResourceFile scriptSource = new ResourceFile(dir, name);
if (scriptSource.exists()) {
GhidraScriptProvider provider =
GhidraScriptUtil.getProvider(scriptSource);
GhidraScript script = provider.getScriptInstance(scriptSource, writer);
script.execute(scriptState, monitor, writer);
return;
}
ResourceFile scriptSource = GhidraScriptUtil.findScriptByName(name);
if (scriptSource != null) {
GhidraScriptProvider provider = GhidraScriptUtil.getProvider(scriptSource);
GhidraScript script = provider.getScriptInstance(scriptSource, writer);
script.execute(scriptState, monitor, writer);
return;
}
}
catch (Exception exc) {
@ -615,7 +609,8 @@ public class ShowConstantUse extends GhidraScript {
Varnode pvnode = null;
Parameter parm = f.getParameter(paramIndex);
if (parm == null) {
this.popup("Please put the cursor on a function parameter variable\nIf the function has not had it's parameters identified\nplease do so and try again");
this.popup(
"Please put the cursor on a function parameter variable\nIf the function has not had it's parameters identified\nplease do so and try again");
return constUse;
}
@ -672,9 +667,8 @@ public class ShowConstantUse extends GhidraScript {
if (refFunc == null) {
localConstUse.put(refAddr, null);
String problem =
"*** No function at " + refAddr +
".\nCould not analyze constant use past this undefined function!";
String problem = "*** No function at " + refAddr +
".\nCould not analyze constant use past this undefined function!";
addConstantProblem(tableChooserDialog, refAddr, problem);
refFunc = UndefinedFunction.findFunction(currentProgram, refAddr, monitor);
}
@ -736,11 +730,10 @@ public class ShowConstantUse extends GhidraScript {
// call dest
if (parm == null) {
constUse.put(instr.getAddress(), null);
String problem =
" *** Warning, it appears that function '" + funcVarUse.getName() +
"' at " + funcVarUse.getAddress() +
" does not have it's parameters recovered!\n" +
" Use Commit Params/Return in the decompiler on this function.";
String problem = " *** Warning, it appears that function '" +
funcVarUse.getName() + "' at " + funcVarUse.getAddress() +
" does not have it's parameters recovered!\n" +
" Use Commit Params/Return in the decompiler on this function.";
addErrorNote(instr.getAddress(), problem);
break;
}
@ -805,7 +798,8 @@ public class ShowConstantUse extends GhidraScript {
value = value & pcodeOp.getInput(1).getOffset();
}
else {
throw new InvalidInputException(" Unhandled Pcode OP " + pcodeOp.toString());
throw new InvalidInputException(
" Unhandled Pcode OP " + pcodeOp.toString());
}
break;
default:
@ -855,7 +849,8 @@ public class ShowConstantUse extends GhidraScript {
long value = def.getInput(0).getOffset();
try {
value = applyDefUseList(value, defUseList);
constUse.put(remapAddress(funcEntry, def.getOutput().getPCAddress()), value);
constUse.put(remapAddress(funcEntry, def.getOutput().getPCAddress()),
value);
println(" " + function.getName() + " " +
def.getOutput().getPCAddress() + " : 0x" + Long.toHexString(value));
}
@ -954,7 +949,7 @@ public class ShowConstantUse extends GhidraScript {
break;
case PcodeOp.PTRSUB: // Pointer + some sub element access (usually a
// structure ref)
// structure ref)
Varnode offsetVal = def.getInput(1);
if (!offsetVal.isConstant()) {
break;
@ -965,7 +960,8 @@ public class ShowConstantUse extends GhidraScript {
long value = baseVal.getOffset() + offsetVal.getOffset();
try {
value = applyDefUseList(value, defUseList);
constUse.put(remapAddress(funcEntry, def.getOutput().getPCAddress()), value);
constUse.put(remapAddress(funcEntry, def.getOutput().getPCAddress()),
value);
println(" " + function.getName() + " " +
def.getOutput().getPCAddress() + " : 0x" + Long.toHexString(value));
}
@ -997,8 +993,9 @@ public class ShowConstantUse extends GhidraScript {
// println(" Lost IT! " + vnode.getPCAddress());
}
private void followThroughGlobal(HashMap<Address, Long> constUse,
ArrayList<PcodeOp> defUseList, HighVariable hvar, ArrayList<FunctionParamUse> funcList,
private void followThroughGlobal(HashMap<Address, Long> constUse, ArrayList<PcodeOp> defUseList,
HighVariable hvar,
ArrayList<FunctionParamUse> funcList,
HashSet<SequenceNumber> doneSet) {
Address loc = hvar.getRepresentative().getAddress();
PcodeOp def = hvar.getRepresentative().getDef();
@ -1068,9 +1065,8 @@ public class ShowConstantUse extends GhidraScript {
// don't decompile the function again if it was the same as the last one
//
if (!f.getEntryPoint().equals(lastDecompiledFuncAddr)) {
lastResults =
decompInterface.decompileFunction(f,
decompInterface.getOptions().getDefaultTimeout(), monitor);
lastResults = decompInterface.decompileFunction(f,
decompInterface.getOptions().getDefaultTimeout(), monitor);
}
hfunction = lastResults.getHighFunction();