Java Code Examples for ghidra.framework.plugintool.PluginTool#execute()

The following examples show how to use ghidra.framework.plugintool.PluginTool#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalVersionInfoHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(PluginTool tool, Object obj, DropTargetDropEvent e, DataFlavor f) {
	VersionInfo info = (VersionInfo) obj;

	DomainFile file = tool.getProject().getProjectData().getFile(info.getDomainFilePath());
	GetVersionedObjectTask task =
		new GetVersionedObjectTask(this, file, info.getVersionNumber());
	tool.execute(task, 250);
	DomainObject versionedObj = task.getVersionedObject();

	if (versionedObj != null) {
		DomainFile vfile = versionedObj.getDomainFile();
		tool.acceptDomainFiles(new DomainFile[] { vfile });
		versionedObj.release(this);
	}
}
 
Example 2
Source File: DeleteVarArgsAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Method called when the action is invoked.
 * @param ev details regarding the invocation of this action
 */
@Override
public void actionPerformed(ListingActionContext context) {
	Function function = functionPlugin.getFunction(context);
	if ((function != null) && (function.hasVarArgs())) {
		Command command = new SetFunctionVarArgsCommand(function, false);

		PluginTool tool = functionPlugin.getTool();
		Program program = context.getProgram();

		if (!tool.execute(command, program)) {
			tool.setStatusInfo("Unable to delete function varArgs on " + "function: " +
				function.getName());
		}
	}
}
 
Example 3
Source File: AddVarArgsAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void actionPerformed(ListingActionContext context) {
	ProgramLocation loc = context.getLocation();

	if ((loc instanceof FunctionSignatureFieldLocation) || (loc instanceof VariableLocation)) {

		Function function = functionPlugin.getFunction(context);
		if ((function != null) && (!function.hasVarArgs())) {
			Command command = new SetFunctionVarArgsCommand(function, true);

			PluginTool tool = functionPlugin.getTool();
			Program program = context.getProgram();

			if (!tool.execute(command, program)) {
				tool.setStatusInfo("Unable to add function varArgs on " + "function: " +
					function.getName());
			}
		}
	}
}
 
Example 4
Source File: CreateArrayAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createArrayAtAddress(Program program, Address addr) {
	PluginTool tool = plugin.getTool();
	Data data = program.getListing().getDataAt(addr);
	if (data == null) {
		tool.setStatusInfo("Create Array Failed! No data at " + addr);
		return;
	}

	DataType dt = data.getDataType();
	int length = data.getLength();
	int maxNoConflictElements = getMaxElementsThatFit(program, addr, length);
	int maxElements = getMaxElementsIgnoreExisting(program, addr, length);
	int numElements = getNumElements(dt, maxNoConflictElements, maxElements);

	// this signals that the user cancelled the operation
	if (numElements == Integer.MIN_VALUE) {
		return;
	}

	CreateArrayCmd cmd = new CreateArrayCmd(addr, numElements, dt, length);
	if (!tool.execute(cmd, program)) {
		tool.setStatusInfo(cmd.getStatusMsg());
	}
}
 
Example 5
Source File: CreateArrayAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void createArrayFromSelection(Program program, ProgramSelection sel) {
	PluginTool tool = plugin.getTool();

	AddressRange range = sel.getFirstRange();
	Address addr = sel.getMinAddress();
	Data data = program.getListing().getDataAt(addr);
	if (data == null) {
		tool.setStatusInfo("Create Array Failed! No data at " + addr);
		return;
	}
	DataType dt = data.getDataType();
	int dtLength = data.getLength();
	int length = (int) range.getLength();
	int numElements = length / dtLength;
	CreateArrayCmd cmd = new CreateArrayCmd(addr, numElements, dt, dtLength);
	if (!tool.execute(cmd, program)) {
		tool.setStatusInfo(cmd.getStatusMsg());
	}
}
 
Example 6
Source File: EditFunctionPurgeAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void showDialog(Function function) {
	int currentFunctionPurgeSize = function.getStackPurgeSize();

	if (currentFunctionPurgeSize == Function.INVALID_STACK_DEPTH_CHANGE ||
		currentFunctionPurgeSize == Function.UNKNOWN_STACK_DEPTH_CHANGE) {
		currentFunctionPurgeSize = 0;
	}
	NumberInputDialog numberInputDialog = new NumberInputDialog("Please Enter Function Purge",
		"Enter Function Purge", currentFunctionPurgeSize, -1048576, 1048576, false);
	numberInputDialog.setHelpLocation(new HelpLocation("FunctionPlugin", "Function_Purge"));

	if (!numberInputDialog.show()) {
		functionPlugin.getTool().setStatusInfo("User cancelled function purge");
		return;
	}
	int newFunctionPurgeSize = numberInputDialog.getValue();

	if (newFunctionPurgeSize != currentFunctionPurgeSize) {
		Command command = new SetFunctionPurgeCommand(function, newFunctionPurgeSize);

		PluginTool tool = functionPlugin.getTool();
		Program program = function.getProgram();

		if (!tool.execute(command, program)) {
			tool.setStatusInfo("Unable to set function purge on " + "function: " +
					function.getName());
		}
	}
}
 
Example 7
Source File: CreateArrayAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createArrayInStructure(Program program, Address addr, int[] compPath) {
	PluginTool tool = plugin.getTool();
	Data data = program.getListing().getDataContaining(addr);
	Data comp = null;
	if (data != null) {
		comp = data.getComponent(compPath);
	}

	if (comp == null) {
		tool.setStatusInfo("Create Array Failed! No data at " + addr);
		return;
	}
	DataType dt = comp.getDataType();
	DataType parentDataType = comp.getParent().getBaseDataType();

	if (!(parentDataType instanceof Structure)) {
		tool.setStatusInfo("Cannot create array here");
		return;
	}
	Structure struct = (Structure) parentDataType;

	int maxElements = getMaxElements(struct, comp.getComponentIndex(), dt);
	int maxNoConflictElements = getMaxNoConflictElements(struct, comp.getComponentIndex(), dt);
	int numElements = getNumElements(dt, maxNoConflictElements, maxElements);

	Command cmd = new CreateArrayInStructureCmd(addr, numElements, dt, compPath);
	if (!tool.execute(cmd, program)) {
		tool.setStatusInfo(cmd.getStatusMsg());
	}
}
 
Example 8
Source File: CreateArrayAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void createArrayInStructure(Program program, InteriorSelection sel) {
	PluginTool tool = plugin.getTool();
	ProgramLocation from = sel.getFrom();

	Data data = program.getListing().getDataContaining(from.getAddress());
	Data comp = null;
	if (data != null) {
		comp = data.getComponent(from.getComponentPath());
	}

	if (comp == null) {
		tool.setStatusInfo("Create Array Failed! No data at " + from.getAddress());
		return;
	}
	DataType dt = comp.getDataType();
	DataType parentDataType = comp.getParent().getBaseDataType();

	if (!(parentDataType instanceof Structure)) {
		tool.setStatusInfo("Cannot create array here");
		return;
	}

	int length = sel.getByteLength();
	int numElements = length / dt.getLength();

	Command cmd = new CreateArrayInStructureCmd(from.getAddress(), numElements, dt,
		from.getComponentPath());
	if (!tool.execute(cmd, program)) {
		tool.setStatusInfo(cmd.getStatusMsg());
	}
}
 
Example 9
Source File: CreateStructureAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void createStructureInStructure(Program program, InteriorSelection sel) {
	PluginTool tool = plugin.getTool();
	ProgramLocation from = sel.getFrom();
	ProgramLocation to = sel.getTo();
	Data data = program.getListing().getDataContaining(from.getAddress());
	Data comp = null;
	if (data != null) {
		comp = data.getComponent(from.getComponentPath());
	}

	if (comp == null) {
		tool.setStatusInfo("Create Structure Failed! No data at " + from.getAddress());
		return;
	}

	DataType parentDataType = comp.getParent().getBaseDataType();
	if (!(parentDataType instanceof Structure)) {
		tool.setStatusInfo("Cannot create structure here");
		return;
	}

	Address newStructureAddress = from.getAddress();
	int[] fromPath = from.getComponentPath();
	int[] toPath = to.getComponentPath();
	Structure tempStructure = null;
	try {
		tempStructure = StructureFactory.createStructureDataTypeInStrucuture(program,
			newStructureAddress, fromPath, toPath);
	}
	catch (Exception exc) {
		tool.setStatusInfo("Create structure failed: " + exc.getMessage());
		return;
	}

	Structure userChoice =
		createStructureDialog.showCreateStructureDialog(program, tempStructure);

	if (userChoice != null) {
		CreateStructureInStructureCmd cmd = new CreateStructureInStructureCmd(userChoice,
			newStructureAddress, fromPath, toPath);

		if (!tool.execute(cmd, program)) {
			tool.setStatusInfo(cmd.getStatusMsg());
		}
		else {
			plugin.updateRecentlyUsed(cmd.getNewDataType());
		}
	}
}
 
Example 10
Source File: CreateStructureAction.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void createStructureInProgram(Program program, ProgramSelection sel) {
	PluginTool tool = plugin.getTool();

	if (sel.getNumAddressRanges() > 1) {
		tool.setStatusInfo("Can only create structure on contiguous selection");
		return;
	}
	if (sel.getNumAddresses() > Integer.MAX_VALUE) {
		tool.setStatusInfo("Can't create structures greater than 0x7fffffff bytes");
		return;
	}

	Data data = program.getListing().getDataContaining(sel.getMinAddress());
	if (data == null) {
		tool.setStatusInfo("Create structure failed! No data at " + sel.getMinAddress());
		return;
	}

	Address structureAddress = sel.getMinAddress();
	int structureLength = (int) sel.getNumAddresses();

	// create a temporary structure to compare with the data types
	// in the current sytem
	Structure tempStructure = null;
	try {
		tempStructure = StructureFactory.createStructureDataType(program, structureAddress,
			structureLength);
	}
	catch (Exception exc) {
		tool.setStatusInfo("Create structure failed: " + exc.getMessage());
		return;
	}

	Structure userChoice =
		createStructureDialog.showCreateStructureDialog(program, tempStructure);

	// exit if the user cancels the operation
	if (userChoice != null) {
		CreateStructureCmd cmd = new CreateStructureCmd(userChoice, structureAddress);

		if (!tool.execute(cmd, program)) {
			tool.setStatusInfo(cmd.getStatusMsg());
		}
		else {
			plugin.updateRecentlyUsed(cmd.getNewDataType());
		}
	}
}