Java Code Examples for ghidra.util.task.TaskMonitor#setShowProgressValue()

The following examples show how to use ghidra.util.task.TaskMonitor#setShowProgressValue() . 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: PowerPC64_ElfExtension.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void processOPDSection(ElfLoadHelper elfLoadHelper, TaskMonitor monitor)
		throws CancelledException {

	MemoryBlock opdBlock = elfLoadHelper.getProgram().getMemory().getBlock(".opd");
	if (opdBlock == null) {
		return;
	}

	monitor.setMessage("Processing Function Descriptor Symbols...");

	Address addr = opdBlock.getStart();
	Address endAddr = opdBlock.getEnd();

	monitor.setShowProgressValue(true);
	monitor.setProgress(0);
	monitor.setMaximum((endAddr.subtract(addr) + 1) / 24);
	int count = 0;

	try {
		while (addr.compareTo(endAddr) < 0) {
			monitor.checkCanceled();
			monitor.setProgress(++count);
			processOPDEntry(elfLoadHelper, addr);
			addr = addr.addNoWrap(24);
		}
	}
	catch (AddressOverflowException e) {
		// ignore end of space
	}

	// allow .opd section contents to be treated as constant values
	opdBlock.setWrite(false);
}
 
Example 2
Source File: GccExceptionAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean added(Program program, AddressSetView addedLocationAddresses,
		TaskMonitor monitor, MessageLog log) throws CancelledException {

	if (visitedPrograms.contains(program)) {
		return true;
	}

	AutoAnalysisManager analysisManager = AutoAnalysisManager.getAnalysisManager(program);
	analysisManager.addListener(analysisListener);

	monitor.setMessage("Analyzing GCC exception-handling artifacts");
	monitor.setIndeterminate(true);
	monitor.setShowProgressValue(false);

	handleStandardSections(program, monitor, log);

	handleDebugFrameSection(program, monitor, log);

	// handleArmSections(program, monitor, log);

	visitedPrograms.add(program);
	monitor.setIndeterminate(false);
	monitor.setShowProgressValue(true);

	return true;
}
 
Example 3
Source File: SearchAllInstructionsTask.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TaskMonitor monitor) {
	if (monitor == null) {
		return;
	}

	// Just show percentage complete in the pop-up.
	monitor.setShowProgressValue(false);

	List<InstructionMetadata> results = doSearch(monitor);

	// If the search finished without being cancelled, just show the results. If it was 
	// cancelled, prompt the user for confirmation and to give them the option of seeing any
	// results which have been collected thus far.
	if (!monitor.isCancelled()) {
		searchDialog.displaySearchResults(results);
	}
	else {
		if (results.isEmpty()) {
			return;
		}
		int option = OptionDialog.showYesNoDialog(searchDialog.getFocusComponent(),
			"Results found!", results.size() + " match(es) found. View results?");

		if (option == OptionDialog.YES_OPTION) {
			searchDialog.displaySearchResults(results);
		}
	}
}
 
Example 4
Source File: DIEAMonitoredIterator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public SimpleDIEAMonitoredIterator(DWARFProgram prog, String monitorMessage,
		TaskMonitor monitor) {
	this.monitor = monitor;
	this.monitorMessage = monitorMessage;
	this.aggregateTotalCount = prog.getTotalAggregateCount();
	this.aggregateIterator = prog.getAggregates().iterator();

	monitor.setIndeterminate(false);
	monitor.setShowProgressValue(true);
	monitor.initialize(aggregateTotalCount);
	monitor.setMessage(monitorMessage);
}
 
Example 5
Source File: DIEAMonitoredIterator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public PagedDIEAMonitoredIterator(DWARFProgram prog, String monitorMessage,
		TaskMonitor monitor) {
	this.prog = prog;
	this.monitor = monitor;
	this.monitorMessage = monitorMessage;
	this.cuCount = prog.getCompilationUnits().size();
	this.aggregateTotalCount = prog.getTotalAggregateCount();
	this.cuIterator = prog.getCompilationUnits().iterator();

	monitor.setIndeterminate(false);
	monitor.setShowProgressValue(true);
	monitor.initialize(aggregateTotalCount);
	monitor.setMessage(monitorMessage);
}
 
Example 6
Source File: ProgramMappingService.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Recursively searches the current active {@link Project} for {@link DomainFile}s that
 * have metadata that matches a {@link FSRL} in the specified list.
 * <p>
 * Warning, this operation is expensive and should only be done in a Task thread.
 * <p>
 * @param fsrls List of {@link FSRL} to match against the metadata of each DomainFile in Project.
 * @param monitor {@link TaskMonitor} to watch for cancel and update with progress.
 * @return Map of FSRLs to {@link DomainFile}s of the found files, never null.
 */
public static Map<FSRL, DomainFile> searchProjectForMatchingFiles(List<FSRL> fsrls,
		TaskMonitor monitor) {
	int fc = AppInfo.getActiveProject().getProjectData().getFileCount();
	if (fc > 0) {
		monitor.setShowProgressValue(true);
		monitor.setMaximum(fc);
		monitor.setProgress(0);
	}
	else {
		monitor.setIndeterminate(true);
	}
	monitor.setMessage("Searching project for matching files");

	Map<String, FSRL> fsrlsToFindByMD5;
	try {
		fsrlsToFindByMD5 = buildFullyQualifiedFSRLMap(fsrls, monitor);
	}
	catch (CancelledException ce) {
		Msg.info(ProgramMappingService.class, "Canceling project search");
		return Collections.emptyMap();
	}

	Map<FSRL, DomainFile> results = new HashMap<>();

	for (DomainFile domainFile : ProjectDataUtils.descendantFiles(
		AppInfo.getActiveProject().getProjectData().getRootFolder())) {
		if (monitor.isCancelled() || fsrlsToFindByMD5.isEmpty()) {
			break;
		}

		monitor.incrementProgress(1);
		Map<String, String> metadata = domainFile.getMetadata();

		FSRL dfFSRL = getFSRLFromMetadata(metadata, domainFile);
		if (dfFSRL != null) {
			// side effect: create association between the FSRL in the DomainFile's props
			// to the DomainFile's path if there is room in the cache.
			// (ie. don't blow out the cache for files that haven't been requested yet)
			createAssociation(dfFSRL, domainFile, true);
		}
		String dfMD5 = (dfFSRL != null) ? dfFSRL.getMD5() : getMD5FromMetadata(metadata);
		if (dfMD5 != null) {
			FSRL matchedFSRL = fsrlsToFindByMD5.get(dfMD5);
			if (matchedFSRL != null) {
				results.put(matchedFSRL, domainFile);
				fsrlsToFindByMD5.remove(dfMD5);
			}
		}
	}

	return results;
}
 
Example 7
Source File: InstructionSearchData.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Searches for a specific byte pattern in the positive direction.
 * 
 * @param plugin the instruction pattern search plugin
 * @param searchBounds the addresses to search
 * @param taskMonitor the task monitor
 * @param maskContainer the bytes to search for
 * @return the instruction, or null if not found
 */
private InstructionMetadata searchForward(ProgramPlugin plugin, AddressRange searchBounds,
		TaskMonitor taskMonitor, MaskContainer maskContainer) {

	Address startAddress = searchBounds.getMinAddress();
	Address endAddress = searchBounds.getMaxAddress();
	Address currentPosition = plugin.getProgramLocation().getByteAddress().next();

	taskMonitor.setShowProgressValue(false);// no need to show the number of bytes
	taskMonitor.setProgress(0);

	// The maximum value for the monitor is the number of bytes to be checked - this will 
	// NOT always be the size of the range passed-in. If the cursor is in the middle of
	// the range already, then only the number of bytes in the range PAST the cursor will 
	// will be checked.
	long max = searchBounds.getLength();
	if (currentPosition.compareTo(searchBounds.getMinAddress()) > 0) {
		max = searchBounds.getMaxAddress().subtract(currentPosition);
	}
	taskMonitor.setMaximum(max);

	// Move the cursor to the beginning of the range if it is currently short of it. We don't
	// want to search for any addresses that aren't in the search bounds.
	if (currentPosition.compareTo(startAddress) < 0) {
		currentPosition = startAddress;
	}

	while (currentPosition.compareTo(endAddress) < 0) {

		// Search program memory for the given mask and val.
		currentPosition = plugin.getCurrentProgram().getMemory().findBytes(currentPosition,
			endAddress, maskContainer.getValue(), maskContainer.getMask(), true, taskMonitor);

		// If no match was found, currentPosition will be null.
		if (currentPosition == null) {
			break;
		}

		// Otherwise construct a new entry to put in our results table.
		MaskContainer masks =
			new MaskContainer(maskContainer.getMask(), maskContainer.getValue());
		InstructionMetadata temp = new InstructionMetadata(masks);
		temp.setAddr(currentPosition);

		return temp;
	}

	return null;
}
 
Example 8
Source File: InstructionSearchData.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Searches for a specific byte pattern in the reverse direction.
 * 
 * @param plugin the instruction pattern search plugin
 * @param searchBounds the addresses to search
 * @param taskMonitor the task monitor
 * @param maskContainer the bytes to search for
 * @return the instruction, or null if not found
 */
private InstructionMetadata searchBackward(ProgramPlugin plugin, AddressRange searchBounds,
		TaskMonitor taskMonitor, MaskContainer maskContainer) {

	Address startAddress = searchBounds.getMaxAddress();
	Address endAddress = searchBounds.getMinAddress();
	Address currentPosition = plugin.getProgramLocation().getByteAddress().previous();

	taskMonitor.setShowProgressValue(false);
	taskMonitor.setProgress(0);

	// The maximum value for the monitor is the number of bytes to be checked - this will 
	// NOT always be the size of the range passed-in. If the cursor is in the middle of
	// the range already, then only the number of bytes in the range BEFORE the cursor will 
	// will be checked.
	long max = searchBounds.getLength();
	if (currentPosition.compareTo(searchBounds.getMaxAddress()) < 0) {
		max = currentPosition.subtract(searchBounds.getMinAddress());
	}
	taskMonitor.setMaximum(max);

	// Move the cursor to the end of the range if it is currently past it. We don't
	// want to search for any addresses that aren't in the search bounds.
	if (currentPosition.compareTo(startAddress) > 0) {
		currentPosition = startAddress;
	}

	while (currentPosition.compareTo(endAddress) > 0) {

		// Search program memory for the given mask and val.
		currentPosition = plugin.getCurrentProgram().getMemory().findBytes(currentPosition,
			endAddress, maskContainer.getValue(), maskContainer.getMask(), false, taskMonitor);

		// If no match was found, currentPosition will be null.
		if (currentPosition == null) {
			break;
		}

		// Otherwise construct a new entry to put in our results table.
		MaskContainer masks =
			new MaskContainer(maskContainer.getMask(), maskContainer.getValue());
		InstructionMetadata temp = new InstructionMetadata(masks);
		temp.setAddr(currentPosition);

		return temp;
	}

	return null;
}
 
Example 9
Source File: DWARFProgram.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Iterates over all the DWARF DIE records in the program and checks for some
 * pre-known issues, throwing an exception if there is a problem that would
 * prevent a successful run.
 *
 * @param monitor {@link TaskMonitor} to check for cancel and upate with status.
 * @throws DWARFException if DWARF structure error.
 * @throws CancelledException if user cancels.
 * @throws IOException if error reading data.
 */
public void checkPreconditions(TaskMonitor monitor)
		throws DWARFPreconditionException, DWARFException, CancelledException, IOException {
	monitor.setIndeterminate(false);
	monitor.setShowProgressValue(true);

	monitor.setMaximum(getCompilationUnits().size());

	if (getCompilationUnits().size() > 0 &&
		getCompilationUnits().get(0).getCompileUnit().hasDWO()) {
		// probably won't get anything from the file because its all in an external DWO
		Msg.warn(this,
			"Unsupported DWARF DWO (external debug file) detected -- unlikely any debug information will be found");
	}

	// This loop:
	// 1) preloads the DIEs if that option is set
	// 2) checks for cross-cu refs
	// 3) sums up the total number of DIE records found and updates prog with total.
	boolean preLoad = importOptions.isPreloadAllDIEs();
	totalDIECount = 0;
	totalAggregateCount = 0;
	clearDIEIndexes();
	for (DWARFCompilationUnit cu : getCompilationUnits()) {
		monitor.setMessage("DWARF Checking Preconditions - Compilation Unit #" +
			cu.getCompUnitNumber() + "/" + getCompilationUnits().size());
		monitor.setProgress(cu.getCompUnitNumber());

		cu.readDIEs(currentDIEs, monitor);

		if (totalDIECount > importOptions.getImportLimitDIECount() && !preLoad) {
			throw new DWARFPreconditionException(
				String.format(program.getName() + " has more DIE records (%d) than limit of %d",
					totalDIECount, importOptions.getImportLimitDIECount()));
		}

		if (!preLoad) {
			foundCrossCURefs |= checkForCrossCURefs(currentDIEs);
			totalDIECount += currentDIEs.size();
			totalAggregateCount += countAggregates();
			currentDIEs.clear();
			if (foundCrossCURefs) {
				throw new DWARFPreconditionException(
					"Found cross-compilation unit references between DIE records, but 'preload' is not turned on");
			}
		}

	}
	if (preLoad) {
		// build DIE indexes once
		rebuildDIEIndexes();
		this.totalAggregateCount = aggregates.size();
		this.totalDIECount = currentDIEs.size();
	}
}