Java Code Examples for ghidra.program.model.listing.Program#isClosed()

The following examples show how to use ghidra.program.model.listing.Program#isClosed() . 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: ProgramManagerPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean closeProgram(final Program program, final boolean ignoreChanges) {
	if (program == null) {
		return false;
	}
	Runnable r = () -> {
		// Note: The tool.canCloseDomainObject() call must come before the
		// programSaveMgr.canClose()call since plugins may save changes to the program
		// so that they can close.
		if (ignoreChanges || program.isClosed() || programMgr.isPersistent(program) ||
			(tool.canCloseDomainObject(program) && programSaveMgr.canClose(program))) {
			programMgr.removeProgram(program);
			updateActions();
		}
	};
	SystemUtilities.runSwingNow(r);
	return !programMgr.contains(program);
}
 
Example 2
Source File: MakeProgramSelectionAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabledForContext(ActionContext context) {

	Component component = context.getSourceComponent();
	if (component != table) {
		return false;
	}

	Program program = table.getProgram();
	if (program == null) {
		return false;
	}

	if (program.isClosed()) {
		return false;
	}

	int n = table.getSelectedRowCount();
	return n > 0;
}
 
Example 3
Source File: TestEnv.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void deleteTestProject(String projectName) {
	boolean deletedProject = AbstractGhidraHeadlessIntegrationTest.deleteProject(
		AbstractGTest.getTestDirectoryPath(), projectName);

	if (!deletedProject) {
		Msg.error(TestEnv.class, "dispose() - Open programs after disposing project: ");
		Iterator<Program> iterator = ProgramUtilities.getSystemPrograms();
		while (iterator.hasNext()) {
			Program program = iterator.next();
			if (program.isClosed()) {
				continue;
			}
			System.err.println("->" + projectName + " " + program.getName());
			printProgramConsumers(program);
		}

		// signal a potential issue by printing out a throwable--we don't throw the exception
		// so that the tests may limp along if this is not a serious issue--throwing the
		// exception my prevent other cleanup from taking place.
		Msg.error(TestEnv.class, "Unable to delete project: " + projectName +
			" in directory: " + AbstractGTest.getTestDirectoryPath(), new RuntimeException());
	}
}
 
Example 4
Source File: ProgramManagerPlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void doCloseAllPrograms(Program[] openPrograms, boolean ignoreChanges) {
	List<Program> toRemove = new ArrayList<>();
	Program currentProgram = programMgr.getCurrentProgram();
	for (Program p : openPrograms) {
		if (ignoreChanges) {
			toRemove.add(p);
		}
		else if (p.isClosed()) {
			toRemove.add(p);
		}

		if (!tool.canCloseDomainObject(p)) {
			// Running tasks.  Do we cancel all closing or continue?  For now, continue
			// closing what we can.
			continue;
		}

		if (!programSaveMgr.canClose(p)) {
			// Cancelled!  Any cancel means to cancel all--just abort.
			return;
		}

		toRemove.add(p);
	}

	// Don't remove currentProgram until last to prevent activation of other programs.
	if (toRemove.contains(currentProgram)) {
		toRemove.remove(currentProgram);
		toRemove.add(currentProgram);
	}

	for (Program program : toRemove) {
		programMgr.removeProgram(program);
	}
	updateActions();
}
 
Example 5
Source File: TestProgramManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public void release(Program program) {

		List<Object> consumers = program.getConsumerList();
		if (consumers.contains(this)) {
			program.release(this);
		}

		if (!program.isClosed()) {
			return;
		}

		openTestPrograms.remove(program);
	}