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

The following examples show how to use ghidra.program.model.listing.Program#addConsumer() . 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: ProgramMappingService.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an open {@link Program} instance that matches the specified
 * {@link FSRL}, either from the set of currently open programs, or by
 * requesting the specified {@link ProgramManager} to
 * open a {@link DomainFile} that was found to match this GFile.
 * <p>
 * @param fsrl {@link FSRL} of program original location.
 * @param domainFile optional {@link DomainFile} that corresponds to the FSRL param.
 * @param consumer Object that will be used to pin the matching Program open.  Caller
 * must release the consumer when done.
 * @param programManager {@link ProgramManager} that will be used to open DomainFiles
 * if necessary.
 * @param openState one of {@link ProgramManager#OPEN_VISIBLE}, {@link ProgramManager#OPEN_HIDDEN}, {@link ProgramManager#OPEN_VISIBLE}
 * @return {@link Program} which was imported from the specified FSRL, or null if not found.
 */
public static Program findMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile,
		Object consumer, ProgramManager programManager, int openState) {
	Program program = findMatchingOpenProgram(fsrl, consumer);
	if (program != null) {
		programManager.openProgram(program, openState);
		return program;
	}
	DomainFile df = (domainFile == null) ? getCachedDomainFileFor(fsrl) : domainFile;
	if (df == null || programManager == null) {
		return null;
	}

	program = programManager.openProgram(df, DomainFile.DEFAULT_VERSION, openState);
	if (program != null) {
		program.addConsumer(consumer);
	}
	return program;
}
 
Example 2
Source File: MultiProgramManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
void addProgram(Program p, URL ghidraURL, int state) {
	ProgramInfo oldInfo = programMap.get(p);
	if (oldInfo == null) {
		p.addConsumer(tool);
		ProgramInfo info = new ProgramInfo(p, state != ProgramManager.OPEN_HIDDEN);
		info.ghidraURL = ghidraURL;
		openProgramList.add(info);
		Collections.sort(openProgramList);
		programMap.put(p, info);

		fireOpenEvents(p);

		p.addListener(this);
		p.addTransactionListener(this);
	}
	else {
		if (!oldInfo.visible && state != ProgramManager.OPEN_HIDDEN) {
			oldInfo.setVisible(true);
		}
	}
	if (state == ProgramManager.OPEN_CURRENT) {
		saveLocation();
		setCurrentProgram(p);
	}
}
 
Example 3
Source File: ProgramMappedMemory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public ProgramMappedMemory(Program program, MemoryFaultHandler faultHandler) {
	this.program = program;
	Memory memory = program.getMemory();

	initializedAddressSet = memory.getLoadedAndInitializedAddressSet();
	for (MemoryBlock block : memory.getBlocks()) {
		if (!block.isInitialized() && block.isMapped()) {
			initializedAddressSet = addMappedInitializedMemory(block);
		}
	}

	program.addConsumer(this);
	this.faultHandler = faultHandler;
}
 
Example 4
Source File: VTSessionDB.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("hiding")
// this is from our constructor
private void initializePrograms(Program sourceProgram, Program destinationProgram) {
	this.sourceProgram = sourceProgram;
	this.destinationProgram = destinationProgram;
	sourceProgram.addConsumer(this);
	destinationProgram.addConsumer(this);
	Options properties = getOptions(PROGRAM_ID_PROPERTYLIST_NAME);
	DomainFile sourceDomainFile = sourceProgram.getDomainFile();
	properties.setString(SOURCE_PROGRAM_ID_PROPERTY_KEY, sourceDomainFile.getFileID());
	DomainFile destinationDomainFile = destinationProgram.getDomainFile();
	properties.setString(DESTINATION_PROGRAM_ID_PROPERTY_KEY,
		destinationDomainFile.getFileID());

}