ghidra.util.task.TaskMonitor Java Examples

The following examples show how to use ghidra.util.task.TaskMonitor. 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: MachoPrelinkUtils.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Scans the provider looking for PRELINK Mach-O headers.  
 * <p>
 * NOTE: The "System" Mach-O at offset 0 is not considered a PRELINK Mach-O.
 * <p>
 * NOTE: We used to scan on 0x1000, and then 0x10 byte boundaries.  Now iOS 12 seems to 
 * put them on 0x8-byte boundaries.
 * 
 * @param provider The provider to scan.
 * @param monitor A monitor.
 * @return A list of provider offsets where PRELINK Mach-O headers start (not including the
 *   "System" Mach-O at offset 0).
 * @throws IOException If there was an IO-related issue searching for PRELINK Mach-O headers.
 */
public static List<Long> findPrelinkMachoHeaderOffsets(ByteProvider provider,
		TaskMonitor monitor) throws IOException {
	monitor.setMessage("Finding PRELINK Mach-O headers...");
	monitor.initialize((int) provider.length());

	List<Long> list = new ArrayList<>(); // This list must maintain ordering...don't sort it		
	for (long offset = 0; offset < provider.length() - 4; offset += 8) {
		if (monitor.isCancelled()) {
			break;
		}
		monitor.setProgress((int) offset);

		if (getMachoLoadSpec(provider, offset) != null) {
			if (offset > 0) {
				// Don't put first "System" Mach-O in list
				list.add(offset);
			}
		}
		else if (offset == 0) {
			// if it doesn't start with a Mach-O, just quit
			break;
		}
	}
	return list;
}
 
Example #2
Source File: NoReturnsFunctionsValidator.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private int checkNumNoReturnFunctions(Program prog, TaskMonitor monitor) {
	FunctionIterator funcIter = prog.getFunctionManager().getFunctions(true);
	int numNoReturnFuncs = 0;

	monitor.setIndeterminate(true);
	while (funcIter.hasNext() && !monitor.isCancelled()) {
		monitor.incrementProgress(1);
		Function func = funcIter.next();
		Address address = func.getEntryPoint();
		Instruction inst = prog.getListing().getInstructionAt(address);

		//This check gets rid of Import Address Table "fake" functions
		if (inst != null) {
			if (func.hasNoReturn()) {
				numNoReturnFuncs++;
			}
		}
	}
	return numNoReturnFuncs;
}
 
Example #3
Source File: PeLoader.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void setProcessorContext(FileHeader fileHeader, Program program, TaskMonitor monitor,
		MessageLog log) {

	try {
		String machineName = fileHeader.getMachineName();
		if ("450".equals(machineName) || "452".equals(machineName)) {
			Register tmodeReg = program.getProgramContext().getRegister("TMode");
			if (tmodeReg == null) {
				return;
			}
			RegisterValue thumbMode = new RegisterValue(tmodeReg, BigInteger.ONE);
			AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();
			program.getProgramContext().setRegisterValue(space.getMinAddress(),
				space.getMaxAddress(), thumbMode);
		}
	}
	catch (ContextChangeException e) {
		throw new AssertException("instructions should not exist");
	}
}
 
Example #4
Source File: FunctionTagMerger.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Merges the desired program (based on the provided option) into the Result program.
 * 
 * @param chosenConflictOption conflict option indicating the program version to use.
 * @param monitor the task monitor
 * @throws CancelledException
 */
private void merge(int chosenConflictOption, TaskMonitor monitor) throws CancelledException {
	Program fromPgm = null;
	switch (chosenConflictOption) {
		case KEEP_LATEST:
			fromPgm = latestProgram;
			break;
		case KEEP_MY:
			fromPgm = myProgram;
			break;
		case KEEP_ORIGINAL:
			fromPgm = originalProgram;
			break;
		default:
			return;
	}

	try {
		merge(fromPgm, monitor);
	}
	catch (IOException e) {
		Msg.error(this, "error merging conflict", e);
	}
}
 
Example #5
Source File: IncomingCallNode.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public List<GTreeNode> generateChildren(TaskMonitor monitor) throws CancelledException {

	FunctionSignatureFieldLocation location =
		new FunctionSignatureFieldLocation(program, functionAddress);

	Set<Address> addresses = ReferenceUtils.getReferenceAddresses(location, monitor);
	List<GTreeNode> nodes = new ArrayList<>();
	FunctionManager functionManager = program.getFunctionManager();
	for (Address fromAddress : addresses) {
		monitor.checkCanceled();
		Function callerFunction = functionManager.getFunctionContaining(fromAddress);
		if (callerFunction == null) {
			continue;
		}

		IncomingCallNode node = new IncomingCallNode(program, callerFunction, fromAddress,
			filterDuplicates, filterDepth);
		addNode(nodes, node);
	}

	Collections.sort(nodes, new CallNodeComparator());

	return nodes;
}
 
Example #6
Source File: VTHashedFunctionAddressCorrelation.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor)
		throws CancelledException {
	try {
		initializeCorrelation(monitor);
		Address destinationAddress = addressCorrelation.getAddressInSecond(sourceAddress);
		if (destinationAddress == null) {
			return null; // No matching destination.
		}
		return new AddressRangeImpl(destinationAddress, destinationAddress);
	}
	catch (MemoryAccessException e) {
		Msg.error(this, "Could not create HashedFunctionAddressCorrelation", e);
		return null;
	}
}
 
Example #7
Source File: CreateFunctionCmd.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * subtract this functions entire body from existing functions
 *
 * @param entry - entry point of new function
 * @param body - new functions body
 * @param bodyChangeMap - map of functions that have their bodies changed by creating this function
 * @param monitor
 * @return
 * @throws CancelledException
 * @throws OverlappingFunctionException
 */
private AddressSetView subtractBodyFromExisting(Address entry, AddressSetView body,
		Map<Function, AddressSetView> bodyChangeMap, TaskMonitor monitor)
		throws CancelledException, OverlappingFunctionException {
	Iterator<Function> iter = program.getFunctionManager().getFunctionsOverlapping(body);
	while (iter.hasNext()) {
		monitor.checkCanceled();
		Function elem = iter.next();
		AddressSetView funcBody = elem.getBody();
		if (funcBody.contains(entry)) {
			bodyChangeMap.put(elem, funcBody);
			// re-define the function that does contain me....
			funcBody = funcBody.subtract(body);
			elem.setBody(funcBody);
		}
		else {
			// else, the body flowed into an existing function
			body = body.subtract(funcBody);
		}
	}
	return body;
}
 
Example #8
Source File: ApplyFidEntriesCommand.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private String generateBookmark(String bookmark, boolean includeNames,
		boolean includeNamespaces, TaskMonitor monitor) throws CancelledException {
	StringBuilder buffer = new StringBuilder();
	if (createBookmarksEnabled) {
		buffer.append(bookmark);

		// append names, class, and library info buffer
		buffer.append(" ");
		buffer.append(listNames(monitor));

		buffer.append(", ");
		buffer.append(listLibraries(monitor));
	}

	return buffer.toString();
}
 
Example #9
Source File: FrontEndPluginScreenShots.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveFiles() throws InvalidNameException, CancelledException, IOException {
	program = env.getProgram("WinHelloCPP.exe");

	Project project = env.getProject();
	ProjectData projectData = project.getProjectData();
	projectData.getRootFolder().createFile("WinHelloCpp.exe", program, TaskMonitor.DUMMY);

	int tx = program.startTransaction("Test");
	program.setName("Bob");
	program.setName("WinHelloCPP.exe");
	program.endTransaction(tx, true);

	runSwing(() -> {
		SaveDataDialog dialog = new SaveDataDialog(tool);

		dialog.showDialog(Arrays.asList(new DomainFile[] { program.getDomainFile() }));
	}, false);

	captureDialog();
}
 
Example #10
Source File: GraphServicesScreenShots.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultGraphDisplay() throws Exception {

	GraphDisplayBroker broker = tool.getService(GraphDisplayBroker.class);
	GraphDisplayProvider export = broker.getGraphDisplayProvider("Default Graph Display");
	GraphDisplay display = export.getGraphDisplay(false, TaskMonitor.DUMMY);
	AttributedGraph graph = new AttributedGraph();
	AttributedVertex v1 = graph.addVertex("0000", "main");
	v1.setAttribute("VertexType", "Entry");
	AttributedVertex v2 = graph.addVertex("0100", "Fun_One");
	v2.setAttribute("VertexType", "Entry");
	AttributedVertex v3 = graph.addVertex("0200", "Fun_Two");
	v3.setAttribute("VertexType", "Entry");

	AttributedEdge e1 = graph.addEdge(v1, v2);
	e1.setAttribute("EdgeType", "Unconditional-Call");
	AttributedEdge e2 = graph.addEdge(v1, v3);
	e2.setAttribute("EdgeType", "Unconditional-Call");

	display.setGraph(graph, "test", false, TaskMonitor.DUMMY);
	waitForSwing();
	setGraphWindowSize(700, 500);
	((DefaultGraphDisplay) display).centerAndScale();

	captureProvider(DefaultGraphDisplayComponentProvider.class);
}
 
Example #11
Source File: GTreeCollapseAllTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void collapseNode(GTreeNode node, TaskMonitor monitor) throws CancelledException {
	if (node.isLeaf()) {
		return;
	}
	monitor.checkCanceled();
	List<GTreeNode> allChildren = node.getChildren();
	if (allChildren.size() == 0) {
		return;
	}
	TreePath treePath = node.getTreePath();
	if (jTree.isExpanded(treePath)) {
		collapsePath(treePath, monitor);
	}
	for (GTreeNode child : allChildren) {
		monitor.checkCanceled();
		collapseNode(child, monitor);
	}
	monitor.incrementProgress(1);
}
 
Example #12
Source File: PowerPC64_ElfExtension.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void processGotPlt(ElfLoadHelper elfLoadHelper, TaskMonitor monitor)
		throws CancelledException {

	if (!canHandle(elfLoadHelper)) {
		return;
	}

	setEntryPointContext(elfLoadHelper, monitor);

	processOPDSection(elfLoadHelper, monitor);

	super.processGotPlt(elfLoadHelper, monitor);

	processPpc64v2PltPointerTable(elfLoadHelper, monitor);
	processPpc64PltGotPointerTable(elfLoadHelper, monitor);
}
 
Example #13
Source File: FunctionMerger.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void determineBodyConflicts(AddressSetView addrs, TaskMonitor monitor)
		throws CancelledException {
	monitor.checkCanceled();
	long totalAddresses = addrs.getNumAddresses();
	monitor.initialize(totalAddresses);
	long granularity = (totalAddresses / 100) + 1;
	int addressCount = 0;
	AddressIterator iter = addrs.getAddresses(true);
	// Look at every address where the Latest or My made a function change.
	while (iter.hasNext()) {
		Address entry = iter.next();
		if (addressCount % granularity == 0) {
			monitor.setProgress(addressCount);
			updateProgress((int) (BODY_CONFLICT_START +
				((addressCount * BODY_CONFLICT_SIZE) / totalAddresses)));
		}
		monitor.setMessage(
			"Checking & Auto-Merging Body Changes for Function " + (++addressCount) + " of " +
				totalAddresses + "." + " Address = " + entry.toString());
		Function originalFunc = functionManagers[ORIGINAL].getFunctionAt(entry);
		Function latestFunc = functionManagers[LATEST].getFunctionAt(entry);
		Function myFunc = functionManagers[MY].getFunctionAt(entry);
		determineBodyConflicts(entry, originalFunc, latestFunc, myFunc, monitor);
	}
}
 
Example #14
Source File: ApplySourceFiles.java    From ghidra with Apache License 2.0 6 votes vote down vote up
static void applyTo(PdbParser pdbParser, XmlPullParser xmlParser, TaskMonitor monitor,
		MessageLog log) {
	Program program = pdbParser.getProgram();
	Options proplist = program.getOptions(Program.PROGRAM_INFO);
	monitor.setMessage("Applying source files...");
	while (xmlParser.hasNext()) {
		if (monitor.isCancelled()) {
			return;
		}
		XmlElement elem = xmlParser.next();
		if (elem.isEnd() && elem.getName().equals("table")) {
			break;
		}

		String name = elem.getAttribute("name");
		int id = XmlUtilities.parseInt(elem.getAttribute("id"));
		proplist.setString("SourceFile" + id, name);

		xmlParser.next();//skip end element
	}
}
 
Example #15
Source File: FileSystemService.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private String getMD5(FSRL fsrl, TaskMonitor monitor) throws CancelledException, IOException {
	if (fsrl.getNestingDepth() == 1) {
		File f = localFS.getLocalFile(fsrl);
		if (!f.isFile()) {
			return null;
		}
		String md5 = fileFingerprintCache.getMD5(f.getPath(), f.lastModified(), f.length());
		if (md5 == null) {
			md5 = FSUtilities.getFileMD5(f, monitor);
			fileFingerprintCache.add(f.getPath(), md5, f.lastModified(), f.length());
		}
		return md5;
	}
	FileCacheEntry fce = getCacheFile(fsrl, monitor);
	return fce.md5;
}
 
Example #16
Source File: CallTreeProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run(TaskMonitor monitor) throws CancelledException {
	CallNode rootNode = (CallNode) tree.getModelRoot();
	List<GTreeNode> children = rootNode.getChildren();
	for (GTreeNode node : children) {
		updateFunction((CallNode) node);
	}
}
 
Example #17
Source File: GraphAlgorithmsTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testDominance_GetDominatorGraph() throws CancelledException {
	//
	//          v1->.
	//           |  |
	// 			v2  |
	//		     |  \/
	//           |  | 
	//      	    v3  |
	//           |  |
	//           |  \/
	//          v4--<
	//

	TestV v1 = vertex(1);
	TestV v2 = vertex(2);
	TestV v3 = vertex(3);
	TestV v4 = vertex(4);

	edge(v1, v2);
	edge(v2, v3);
	edge(v3, v4);
	edge(v1, v4);

	GDirectedGraph<TestV, GEdge<TestV>> dg =
		GraphAlgorithms.findDominanceTree(g, TaskMonitor.DUMMY);

	//@formatter:off
	assertContainsEdgesExactly(dg,
							   resultEdge(v1, v2),
							   resultEdge(v1, v2), 
							   resultEdge(v2, v3),
							   resultEdge(v1, v4));
	//@formatter:on

}
 
Example #18
Source File: ProgramMemoryUtil.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Checks a programs memory for direct references to the CodeUnit indicated.
 * Direct references are only found at addresses that match the indicated alignment. 
 * @param program the program whose memory is to be checked.
 * @param alignment direct references are to only be found at the indicated alignment in memory.
 * @param codeUnit the code unit to to search for references to.
 * @param monitor a task monitor for progress or to allow canceling.
 * @return list of addresses referring directly to the toAddress.
 */
public static List<Address> findDirectReferencesCodeUnit(Program program, int alignment,
		CodeUnit codeUnit, TaskMonitor monitor) {

	if (monitor == null) {
		monitor = TaskMonitorAdapter.DUMMY_MONITOR;
	}

	AddressSet toAddressSet =
		new AddressSet((codeUnit.getMinAddress()), codeUnit.getMaxAddress());

	List<ReferenceAddressPair> directReferenceList = new ArrayList<>();
	List<Address> results = new ArrayList<>();

	try {
		ProgramMemoryUtil.loadDirectReferenceList(program, alignment,
			toAddressSet.getMinAddress(), toAddressSet, directReferenceList, monitor);
	}
	catch (CancelledException e) {
		return Collections.emptyList();
	}

	for (ReferenceAddressPair rap : directReferenceList) {
		if (monitor.isCancelled()) {
			return null;
		}
		Address fromAddr = rap.getSource();
		if (!results.contains(fromAddr)) {
			results.add(fromAddr);
		}
	}

	return results;
}
 
Example #19
Source File: FidProgramSeeker.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Search for matches to a single function. Only returns null, if the function can't be hashed.
 * @param function is the function to search for
 * @param monitor is a monitor to check for cancels
 * @return the FidSearchResult object describing any matches (or if there are none)
 * @throws MemoryAccessException
 * @throws CancelledException
 */
public FidSearchResult searchFunction(Function function, TaskMonitor monitor)
		throws MemoryAccessException, CancelledException {
	HashFamily family = getFamily(function, monitor);
	FidSearchResult fidResult = null;
	if (family != null) {
		fidResult = processMatches(function, family, monitor);
		if (fidResult == null) {
			fidResult = new FidSearchResult(function, family.getHash(), null);
		}
	}
	return fidResult;
}
 
Example #20
Source File: CodeXmlMgr.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void processCodeBlock(XmlPullParser parser, XmlElement element, TaskMonitor monitor,
		AddressSet set) throws AddressFormatException {

	AddressFactory af = program.getAddressFactory();
	String startAddrStr = element.getAttribute("START");
	String endAddrStr = element.getAttribute("END");
	Address start = XmlProgramUtilities.parseAddress(af, startAddrStr);
	Address end = XmlProgramUtilities.parseAddress(af, endAddrStr);
	if (start == null || end == null) {
		throw new AddressFormatException("Incompatible Code Block Address Range: [" +
			startAddrStr + "," + endAddrStr + "]");
	}
	set.addRange(start, end);
}
 
Example #21
Source File: VTAutoVersionTrackingTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private boolean runAutoVTCommand(double minReferenceCorrelatorScore,
		double minReferenceCorrelatorConfidence) {
	AtomicBoolean result = new AtomicBoolean();
	runSwing(() -> {
		String transactionName = "Auto Version Tracking Test";
		int startTransaction = session.startTransaction(transactionName);

		AutoVersionTrackingCommand vtCommand = new AutoVersionTrackingCommand(controller,
			session, minReferenceCorrelatorScore, minReferenceCorrelatorConfidence);
		result.set(vtCommand.applyTo(session, TaskMonitor.DUMMY));

		session.endTransaction(startTransaction, result.get());
	});
	return result.get();
}
 
Example #22
Source File: AutoTableDisassemblerModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private AddressTable get(Address addr, TaskMonitor monitor) {
	AddressTable entry;

	entry = AddressTable.getEntry(getProgram(), addr, monitor, false, minimumTableSize,
		alignment, skipAmount, 0, shiftedAddresses, true, false);
	if (map != null) {
		map.put(addr, entry);
	}
	return entry;
}
 
Example #23
Source File: OverlapCodeSubModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
    * @see ghidra.program.model.block.CodeBlockModel#getNumDestinations(ghidra.program.model.block.CodeBlock, ghidra.util.task.TaskMonitor)
    */
   @Override
public int getNumDestinations(CodeBlock block, TaskMonitor monitor) throws CancelledException {

       if (!(block.getModel() instanceof OverlapCodeSubModel)) {
		throw new IllegalArgumentException();
	}

	return SubroutineDestReferenceIterator.getNumDestinations(block, monitor);
   }
 
Example #24
Source File: AutoAnalysisWorkerTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public boolean applyTo(DomainObject obj, TaskMonitor monitor) {
	try {
		Thread.sleep(delay);
	}
	catch (InterruptedException e) {
		Assert.fail();// should never happen
	}

	Program p = (Program) obj;
	Options list = p.getOptions("TEST");
	list.setBoolean(property, true);
	return true;
}
 
Example #25
Source File: iBootImFileSystem.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon(GFile file, TaskMonitor monitor) throws IOException, CancelledException {
	File cacheFile = fsService.getFile(file.getFSRL(), monitor);
	try (InputStream cacheInputStream = new FileInputStream(cacheFile)) {
		GImageFormat format =
			(header.getFormat() == iBootImConstants.FORMAT_ARGB) ? GImageFormat.RGB_ALPHA_4BYTE
					: GImageFormat.GRAY_ALPHA_2BYTE;
		GImage image = new GImage(header.getWidth(), header.getHeight(), format,
			cacheInputStream, cacheFile.length());
		return image.toPNG();
	}
}
 
Example #26
Source File: ProgramDiff.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/** Gets the addresses where the Program Context (register bits) differ
 * between two programs.
 *
 * @param addressSet the addresses to check for differences.
 * The addresses in this address set should be derived from program1.
 * @param monitor the task monitor for indicating the progress of
 * determining differences. This monitor reports the progress to the user.
 *
 * @return the addresses of code units where the program context (register
 * bits values) differs.
 * The addresses in this address set are derived from program1.
 *
 * @throws ProgramConflictException if the two programs are not comparable since registers differ.
 * @throws CancelledException if the user cancelled the Diff.
 */
private AddressSet getProgramContextDifferences(AddressSetView addressSet, TaskMonitor monitor)
		throws ProgramConflictException, CancelledException {
	AddressSet differences = new AddressSet();
	ProgramContext pc1 = program1.getProgramContext();
	ProgramContext pc2 = program2.getProgramContext();
	String[] names1 = pc1.getRegisterNames();
	String[] names2 = pc2.getRegisterNames();
	Arrays.sort(names1);
	Arrays.sort(names2);
	if (!Arrays.equals(names1, names2)) {
		throw new ProgramConflictException(
			"Program Context Registers don't match between the programs.");
	}

	// Check each address range from the address set for differences.
	AddressSet inCommon = pgmMemComp.getAddressesInCommon();
	addressSet = (addressSet != null) ? inCommon.intersect(addressSet) : inCommon;

	for (String element : names1) {
		monitor.checkCanceled();
		Register rb1 = pc1.getRegister(element);
		Register rb2 = pc2.getRegister(element);
		if (rb1.isProcessorContext() || rb2.isProcessorContext()) {
			continue; // context handled with CodeUnit differencing
		}
		Register p1 = rb1.getParentRegister();
		Register p2 = rb2.getParentRegister();
		if (p1 != null && p2 != null && p1.getName().equals(p2.getName())) {
			continue;
		}

		getProgramContextDifferences(pc1, rb1, pc2, rb2, addressSet, differences, monitor);
	}
	return differences;
}
 
Example #27
Source File: CliAbstractStream.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Does basic markup that all streams will want:
 * <ul>
 *   <li>Set monitor message</li>
 *   <li>Validate addresses</li>
 *   <li>Add bookmark</li>
 *   <li>Add symbol</li>
 *   <li>Create data type</li>
 * </ul>
 * Subclass should first call this and then provide any custom markup they need. 
 */
@Override
public void markup(Program program, boolean isBinary, TaskMonitor monitor, MessageLog log,
		NTHeader ntHeader) throws DuplicateNameException, IOException {

	monitor.setMessage("[" + program.getName() + "]: CLI stream...");
	Address addr = PeUtils.getMarkupAddress(program, isBinary, ntHeader, rva);

	program.getBookmarkManager().setBookmark(addr, BookmarkType.INFO, "CLI Stream",
		header.getName());

	try {
		program.getSymbolTable().createLabel(addr, "CLI_Stream_" + header.getName(),
			SourceType.ANALYSIS);
	}
	catch (InvalidInputException e) {
		Msg.error(this, "Error marking up CLI stream \"" + header.getName() + "\"", e);
		return;
	}

	if (!program.getMemory().contains(addr)) {
		return;
	}

	DataType dt = this.toDataType();
	dt.setCategoryPath(new CategoryPath(PATH));
	PeUtils.createData(program, addr, dt, log);
}
 
Example #28
Source File: AbstractDyldInfoProcessor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
protected String readString( ByteArrayInputStream byteStream, TaskMonitor monitor ) {
	StringBuffer buffer = new StringBuffer();
	while ( !monitor.isCancelled() ) {
		int value = byteStream.read();
		if ( value == -1 ) {
			break;
		}
		byte b = (byte) value;
		if ( b == '\0' ) {
			break;
		}
		buffer.append( (char) ( b & 0xff ) );
	}
	return buffer.toString();
}
 
Example #29
Source File: DecompilerParameterIdCmd.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Address address, TaskMonitor monitor) throws CancelledException, Exception {

	DecompInterface decompiler = pool.get();
	try {
		Function function = program.getFunctionManager().getFunctionAt(address);
		doWork(function, decompiler, monitor);
	}
	finally {
		pool.release(decompiler);
		monitor.incrementProgress(1);
	}
}
 
Example #30
Source File: LocalFileSystem.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized LocalDatabaseItem createDatabase(String parentPath, String name,
		String fileID, BufferFile bufferFile, String comment, String contentType,
		boolean resetDatabaseId, TaskMonitor monitor, String user)
		throws InvalidNameException, IOException, CancelledException {

	if (readOnly) {
		throw new ReadOnlyException();
	}

	testValidName(parentPath, true);
	testValidName(name, false);

	ItemStorage itemStorage = allocateItemStorage(parentPath, name);
	LocalDatabaseItem item = null;
	try {
		PropertyFile propertyFile = itemStorage.getPropertyFile();
		item = new LocalDatabaseItem(this, propertyFile, bufferFile, contentType, fileID,
			comment, resetDatabaseId, monitor, user);
	}
	finally {
		if (item == null) {
			deallocateItemStorage(parentPath, name);
		}
	}
	return item;
}