ghidra.util.Msg Java Examples

The following examples show how to use ghidra.util.Msg. 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: GhidraFileChooserTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDesktop_SystemNativeDesktop() throws Exception {
	File userDesktopDir = chooser.getModel().getDesktopDirectory();

	if (userDesktopDir == null) {
		Msg.warn(this, "NOTE: unable to test 'Desktop' button in GhidraFileChooser " +
			"in this enviornment because it does not have a detectable Desktop folder.");
		return;
	}

	pressDesktop();
	waitForChooser();

	assertEquals("File chooser did not switch to the user's Desktop directory", userDesktopDir,
		getCurrentDirectory());
}
 
Example #2
Source File: ToolActionManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Create the Template object and add it to the tool chest.
 */
private void addToolTemplate(InputStream instream, String path) {
	try {
		SAXBuilder sax = XmlUtilities.createSecureSAXBuilder(false, false);
		Element root = sax.build(instream).getRootElement();

		ToolTemplate template = new GhidraToolTemplate(root, path);
		if (plugin.getActiveProject().getLocalToolChest().addToolTemplate(template)) {
			Msg.info(this,
				"Successfully added " + template.getName() + " to project tool chest.");
		}
		else {
			Msg.warn(this, "Could not add " + template.getName() + " to project tool chest.");
		}
	}
	catch (Exception e) {
		Msg.showError(getClass(), tool.getToolFrame(), "Error Reading Tool",
			"Could not read tool: " + e, e);
	}
}
 
Example #3
Source File: Preferences.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets an input stream to a file that is the same named file within a different 
 * application version directory for this user. This method will search for an 
 * alternate file based on the application version directories modification times 
 * and will use the first matching file it finds.  
 * 
 * @return a file input stream for an alternate file or null.
 */
private static FileInputStream getAlternateFileInputStream() {
	File previousFile =
		GenericRunInfo.getPreviousApplicationSettingsFile(APPLICATION_PREFERENCES_FILENAME);
	if (previousFile == null) {
		return null;
	}

	try {
		FileInputStream fis = new FileInputStream(previousFile);
		Msg.info(Preferences.class, "Loading previous preferences: " + previousFile);
		return fis;
	}
	catch (FileNotFoundException fnfe) {
		// Ignore so we can try another directory.
	}

	return null;
}
 
Example #4
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 #5
Source File: EditActionManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void clearCertPath() {

		String path = ApplicationKeyManagerFactory.getKeyStore();
		if (path == null) {
			// unexpected
			clearCertPathAction.setEnabled(false);
			return;
		}

		if (OptionDialog.YES_OPTION != OptionDialog.showYesNoDialog(tool.getToolFrame(),
			"Clear PKI Certificate", "Clear PKI certificate setting?\n(" + path + ")")) {
			return;
		}

		try {
			ApplicationKeyManagerFactory.setKeyStore(null, true);
			clearCertPathAction.setEnabled(false);
		}
		catch (IOException e) {
			Msg.error(this,
				"Error occurred while clearing PKI certificate setting: " + e.getMessage());
		}
	}
 
Example #6
Source File: ModuleSortPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void run(TaskMonitor monitor) {
	int txId = -1;
	boolean success = false;
	try {
		txId = currentProgram.startTransaction(getName());
		doSort(module, comparator, monitor);
		success = true;
	}
	catch (CancelledException ce) {
		// don't care
	}
	catch (Throwable t) {
		Msg.showError(this, null, "Error", "Module Sort Failed", t);
	}
	finally {
		currentProgram.endTransaction(txId, success);
	}
}
 
Example #7
Source File: EclipseConnectorTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link ProcessBuilder} to launch Eclipse.
 * 
 * @param eclipseExecutableFile The Eclipse executable file.
 * @param eclipseWorkspaceDir The Eclipse workspace directory.  Could be null.
 * @return A {@link ProcessBuilder} to launch Eclipse.
 */
private ProcessBuilder createEclipseProcessBuilder(File eclipseExecutableFile,
		File eclipseWorkspaceDir) {
	List<String> args = new ArrayList<>();
	args.add(eclipseExecutableFile.getAbsolutePath());

	if (eclipseWorkspaceDir != null) {
		args.add("-data");
		args.add(eclipseWorkspaceDir.getAbsolutePath());
	}

	args.add("--launcher.appendVmargs");
	args.add("-vmargs");
	args.add("-Dghidra.install.dir=" + Application.getInstallationDirectory());

	// Eclipse on OS X can have file locking issues if the user home directory is networked.
	// The following property is set in the launch script if we should disable file locking
	// via the appropriate Eclipse JVM arg.
	if (Boolean.getBoolean("eclipse.filelock.disable")) {
		Msg.info(this, "Disabling Eclipse file locking...");
		args.add("-Dosgi.locking=none");
	}

	return new ProcessBuilder(args);
}
 
Example #8
Source File: ExactInstructionsFunctionHasher.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected long hash(TaskMonitor monitor, ArrayList<CodeUnit> units, int byteCount)
		throws MemoryAccessException, CancelledException {
	byte[] buffer = new byte[byteCount];
	int offset = 0;
	for (CodeUnit codeUnit : units) {
		monitor.checkCanceled();

		try {
			codeUnit.getBytesInCodeUnit(buffer, offset);
			applyMask(buffer, offset, codeUnit);
		}
		catch (MemoryAccessException e) {
			Msg.warn(this, "Could not get code unit bytes at " + codeUnit.getAddress());
		}
		offset += codeUnit.getLength();
	}
	if (offset != byteCount) {
		throw new IllegalStateException("did NOT use all the codeUnit buffer bytes");
	}
	synchronized (digest) {
		digest.reset();
		digest.update(buffer, monitor);
		return digest.digestLong();
	}
}
 
Example #9
Source File: LinuxFileUrlHandler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void doImport(Component component, Object transferData, ServiceProvider sp,
		DomainFolder folder) {

	FileImporterService im = sp.getService(FileImporterService.class);
	if (im == null) {
		Msg.showError(this, component, "Could Not Import", "Could not find importer service.");
		return;
	}

	List<File> files = toFiles(transferData);
	if (files.isEmpty()) {
		return;
	}

	if (files.size() == 1 && files.get(0).isFile()) {
		im.importFile(folder, files.get(0));
	}
	else {
		im.importFiles(folder, files);
	}
}
 
Example #10
Source File: DWARFSectionProviderFactory.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Iterates through the statically registered {@link #sectionProviderFactoryFuncs factory funcs},
 * trying each factory method until one returns a {@link DWARFSectionProvider} 
 * that can successfully retrieve the {@link DWARFSectionNames#MINIMAL_DWARF_SECTIONS minimal} 
 * sections we need to do a DWARF import.
 * <p>
 * The resulting {@link DWARFSectionProvider} is {@link Closeable} and it is the caller's
 * responsibility to ensure that the object is closed when done. 
 * 
 * @param program
 * @return {@link DWARFSectionProvider} that should be closed by the caller or NULL if no
 * section provider types match the specified program.
 */
public static DWARFSectionProvider createSectionProviderFor(Program program) {
	for (Function<Program, DWARFSectionProvider> factoryFunc : sectionProviderFactoryFuncs) {
		DWARFSectionProvider sp = factoryFunc.apply(program);
		if (sp != null) {
			try {
				if (sp.hasSection(DWARFSectionNames.MINIMAL_DWARF_SECTIONS)) {
					return sp;
				}
			}
			catch (Exception e) {
				Msg.warn(DWARFSectionProviderFactory.class,
					"Problem detecting DWARFSectionProvider", e);
			}
			sp.close();
		}
	}
	return null;
}
 
Example #11
Source File: AnalysisScheduler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public void registerOptions(Options options) {
	Options analyzerOptions = options.getOptions(analyzer.getName());

	boolean defaultEnable = analyzer.getDefaultEnablement(analysisMgr.getProgram());

	boolean overrideEnable = getEnableOverride(defaultEnable);

	// only warn when option registered
	if (defaultEnable != overrideEnable) {
		Msg.warn(this,
			"Analyzer \'" + analyzer.getName() + "\' for " +
				analysisMgr.getProgram().getName() + " " +
				(overrideEnable ? "enabled" : "disabled") + " by PSPEC file override");
	}

	options.registerOption(analyzer.getName(),
		overrideEnable, null,
		analyzer.getDescription());

	analyzer.registerOptions(analyzerOptions, analysisMgr.getProgram());
}
 
Example #12
Source File: AbstractMergeTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected void checkTransactions(String prefix) {
	Program p = mtf.getResultProgram();
	if (p == null) {
		return;
	}

	Transaction tx = p.getCurrentTransaction();
	if (tx == null) {
		return;
	}
	ArrayList<String> list = tx.getOpenSubTransactions();
	StringBuffer tip = new StringBuffer();
	Iterator<String> iter = list.iterator();
	while (iter.hasNext()) {
		if (tip.length() != 0) {
			tip.append('\n');
		}
		tip.append(iter.next());
	}
	Msg.error(this, prefix + "Test Case " + testName.getMethodName() +
		" : ERROR: Transactions still exist!  " + tip.toString());
}
 
Example #13
Source File: ExtensionUtils.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts information from a Java Properties file to create an {@link ExtensionDetails}
 * object.
 * 
 * @param resourceFile the resource file file to parse
 * @return a new extension details object
 */
public static ExtensionDetails createExtensionDetailsFromPropertyFile(
		ResourceFile resourceFile) {

	try (InputStream in = resourceFile.getInputStream()) {
		Properties props = new Properties();
		props.load(in);
		return createExtensionDetailsFromProperties(props);
	}
	catch (IOException e) {
		Msg.error(null,
			"Error processing extension properties for " + resourceFile.getAbsolutePath(),
			e);
		return null;
	}
}
 
Example #14
Source File: AbstractToolSavingTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
protected Map<String, Object> getOptionsMap(PluginTool tool) {
	Map<String, Object> map = new TreeMap<>();
	Options[] options = tool.getOptions();
	for (Options option : options) {
		String optionsName = option.getName();

		if (optionsName.equals("Key Bindings")) {
			Msg.debug(this, "break");
		}

		List<String> optionNames = option.getOptionNames();
		for (String name : optionNames) {
			Object value = invokeInstanceMethod("getObject", option,
				new Class[] { String.class, Object.class }, new Object[] { name, null });
			map.put(optionsName + "." + name, value);
		}
	}
	return map;
}
 
Example #15
Source File: ThreadedTableTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void assertPendingPanelShowing() {
	JComponent pendingPanel = (JComponent) getInstanceField("pendingPanel", threadedTablePanel);

	waitForCondition(() -> {

		boolean isShowing = isShowing(pendingPanel);

		if (!isShowing) {
			JComponent loadedComponent =
				(JComponent) getInstanceField("loadedComponent", threadedTablePanel);
			String name = (loadedComponent == null) ? "<no component showing>"
					: loadedComponent.getName();
			Msg.debug(this, "Pending is not yet showing--what is?: " + name);
		}

		return isShowing;
	});
}
 
Example #16
Source File: ByteUtil.java    From Ghidra-Switch-Loader with ISC License 6 votes vote down vote up
public static void logBytes(byte[] data)
{
    StringBuilder sb = new StringBuilder();
    int lineWidth = 0;
    
    for (byte b : data) 
    {
        sb.append(String.format("%02X ", b));
        lineWidth++;
        
        if (lineWidth >= 16)
        {
            sb.append("\n");
            lineWidth = 0;
        }
    }
    
    Msg.info(null, sb.toString());
}
 
Example #17
Source File: EntryDescriptorID.java    From ghidra with Apache License 2.0 6 votes vote down vote up
public final static String convertEntryIdToName(int entryID) {
	Field [] fields = EntryDescriptorID.class.getDeclaredFields();
	for (Field field : fields) {
		if (field.getName().startsWith("ENTRY_")) {
			try {
				Integer value = (Integer)field.get(null);
				if (value == entryID) {
					return field.getName().substring("ENTRY_".length());
				}
			}
			catch (Exception e) {
			    Msg.error(EntryDescriptorID.class, "Unexpected Exception: " + e.getMessage(), e);
			}
		}
	}
	return "Unrecognized entry id: 0x"+Integer.toHexString(entryID);
}
 
Example #18
Source File: DIEAggregate.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the {@link DebugInfoEntry die} instance pointed to by the requested attribute,
 * or null if the attribute does not exist.
 * <p>
 * @param attribute
 * @return
 */
public DebugInfoEntry getRefDIE(int attribute) {
	AttrInfo attrInfo = findAttribute(attribute);
	if (attrInfo == null) {
		return null;
	}

	DWARFNumericAttribute val = attrInfo.getValue(DWARFNumericAttribute.class);
	long offset = (val != null) ? val.getUnsignedValue() : -1;

	DebugInfoEntry result = getProgram().getEntryAtByteOffsetUnchecked(offset);
	if (result == null) {
		Msg.warn(this, "Invalid reference value [" + Long.toHexString(offset) + "]");
		Msg.warn(this, this.toString());
	}
	return result;
}
 
Example #19
Source File: OptionType.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
Object stringToObject(String string) {
	SaveState saveState = getSaveStateFromXmlString(string);
	String customOptionClassName = saveState.getString("CUSTOM_OPTION_CLASS", null);
	try {
		Class<?> c = Class.forName(customOptionClassName);
		CustomOption option = (CustomOption) c.newInstance();
		option.readState(saveState);
		return option;
	}
	catch (Exception e) {
		Msg.error(this, "Can't create customOption instance for: " + customOptionClassName,
			e);
	}
	return null;
}
 
Example #20
Source File: GNUExternalDisassembler.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private static void reportMultipleMappings(Language language) {
	List<String> externalNames = language.getLanguageDescription().getExternalNames("gnu");
	if (externalNames != null && externalNames.size() > 1) {
		LanguageID currentLanguageID = language.getLanguageID();
		StringBuilder sb = new StringBuilder();
		boolean prependSeparator = false;
		for (String name : externalNames) {
			if (prependSeparator)
				sb.append(", ");
			sb.append(name);
			prependSeparator = true;
		}
		Msg.warn(GNUExternalDisassembler.class,
			"Language " + currentLanguageID + " illegally maps to multiple (" +
				externalNames.size() + ") external gnu names: " + sb.toString() +
				".  The first external name will be used.");
	}
}
 
Example #21
Source File: BlockGraphTask.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the move memory operation.
 */
@Override
public void run(TaskMonitor monitor) throws CancelledException {
	AttributedGraph graph = createGraph();
	monitor.setMessage("Generating Graph...");
	try {
		GraphDisplay display = graphService.getGraphDisplay(reuseGraph, monitor);
		display.setGraphDisplayListener(
			new BlockModelGraphDisplayListener(tool, blockModel, display));
		if (showCode) {
			display.defineVertexAttribute(CODE_ATTRIBUTE);
			display.defineVertexAttribute(SYMBOLS_ATTRIBUTE);
			display.setVertexLabel(CODE_ATTRIBUTE, GraphDisplay.ALIGN_LEFT, 12, true,
				codeLimitPerBlock + 1);
		}
		display.setGraph(graph, actionName, appendGraph, monitor);
	}
	catch (GraphException e) {
		if (!monitor.isCancelled()) {
			Msg.showError(this, null, "Graphing Error", e.getMessage());
		}
	}
}
 
Example #22
Source File: ELFExternalSymbolResolver.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private static Collection<String> getOrderedLibraryNamesNeeded(Program program) {
	TreeMap<Integer, String> orderLibraryMap = new TreeMap<>();
	Options options = program.getOptions(Program.PROGRAM_INFO);
	//List<String> sortedOptionNames = new ArrayList<>();
	for (String optionName : options.getOptionNames()) {
		if (!optionName.startsWith(ElfLoader.ELF_REQUIRED_LIBRARY_PROPERTY_PREFIX) ||
			!optionName.endsWith("]")) {
			continue;
		}
		String libName = options.getString(optionName, null);
		if (libName == null) {
			continue;
		}
		String indexStr =
			optionName.substring(ElfLoader.ELF_REQUIRED_LIBRARY_PROPERTY_PREFIX.length(),
				optionName.length() - 1).trim();
		try {
			orderLibraryMap.put(Integer.parseInt(indexStr), libName.trim());
		}
		catch (NumberFormatException e) {
			Msg.error(ELFExternalSymbolResolver.class,
				"Program contains invalid property: " + optionName);
		}
	}
	return orderLibraryMap.values();
}
 
Example #23
Source File: PowerPCAddressAnalyzer.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private RegisterValue findPefR2Value(Program program, Address start) {

		Listing listing = program.getListing();
		ReferenceManager referenceManager = program.getReferenceManager();
		Symbol tocSymbol = SymbolUtilities.getExpectedLabelOrFunctionSymbol(program,
			PefConstants.TOC, err -> Msg.error(this, err));
		if (tocSymbol == null) {
			return null;
		}

		PseudoDisassembler pdis = new PseudoDisassembler(program);
		ReferenceIterator refIter = referenceManager.getReferencesTo(start);

		while (refIter.hasNext()) {
			Reference ref = refIter.next();
			// if is a data pointer
			Data data = listing.getDataAt(ref.getFromAddress());
			if (data == null) {
				continue;
			}
			if (!data.isPointer()) {
				continue;
			}
			// check after the data pointer to see if it is the same as the TOC value
			Address dataAddr = data.getMaxAddress().add(1);
			Address tocAddr = pdis.getIndirectAddr(dataAddr);
			if (tocSymbol.getAddress().equals(tocAddr)) {
				BigInteger tocValue = BigInteger.valueOf(tocAddr.getOffset());
				Register r2 = program.getRegister("r2");
				return new RegisterValue(r2, tocValue);
			}
		}
		return null;
	}
 
Example #24
Source File: CompositeTestUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Compare dump of composite with the expected on
 * @param test JUnit test instance used for reporting
 * @param expectedDump expected composite dump
 * @param composite test result composite
 * @param recursive if true all child composites will be included in dump
 */
public static void assertExpectedComposite(Object test, String expectedDump, DataType composite,
		boolean recursive) {
	assertTrue(composite instanceof Composite);
	String result = dump(composite, recursive).trim();
	expectedDump = expectedDump.trim();
	int len = expectedDump.length();
	int expectedLine = 1;
	int expectedCol = 0;
	int index = 0;
	boolean mismatch = false;

	for (index = 0; index < len; index++) {
		++expectedCol;
		char expectedChar = expectedDump.charAt(index);
		if (expectedChar == '\n') {
			++expectedLine;
			expectedCol = 0; // newline
		}
		char resultChar = (index < result.length()) ? result.charAt(index) : 0;
		if (resultChar != expectedChar) {
			Msg.error(test, "Expected and result differ: expected line " + expectedLine +
				", column " + expectedCol);
			mismatch = true;
			break;
		}
	}

	mismatch |= len != result.length();

	if (mismatch) {
		Msg.error(test, "Expected composite:\n" + expectedDump);
		Msg.error(test, "Result composite:\n" + result);
		fail("Failed to parse expected composite (see log)");
	}
}
 
Example #25
Source File: GroupIconResourceDataType.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
protected DataTypeComponent[] getAllComponents(MemBuffer buf) {

	List<DataTypeComponent> comps = new ArrayList<>();
	MemBuffer memBuffer = buf;
	int structureOffset = 0;
	int numIconDirEntries;

	try {
		//first add the main GroupIcon header GRPIICONDIR			
		comps.add(new ReadOnlyDataTypeComponent(GroupIconHeaderStructure(), this, 6,
			comps.size(), structureOffset, "GroupIcon Header", null));

		//get the number of Icon Directory Entry Structures from the idCount member of the header structure 
		numIconDirEntries = memBuffer.getShort(structureOffset + 4);

		//increment the offset by the header size
		structureOffset += 6;

		//add each Icon Directory Entry structure and increment the offset by the structure size
		for (int i = 0; i < numIconDirEntries; i++) {
			comps.add(new ReadOnlyDataTypeComponent(GroupIconDirEntryStructure(), this, 14,
				comps.size(), structureOffset, "GroupIcon Entry", null));
			structureOffset += 14;
		}

	}
	catch (MemoryAccessException e1) {
		Msg.debug(this, "Error applying GroupIcon Resource Data Type.");
	}

	DataTypeComponent[] result = comps.toArray(new DataTypeComponent[comps.size()]);
	return result;
}
 
Example #26
Source File: GhidraTransferable.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static DataFlavor createLocalGhidraFlavor() {
	try {
		return new GenericDataFlavor(
				DataFlavor.javaJVMLocalObjectMimeType+
				"; class=java.util.ArrayList",
		"Local list of Drag/Drop User objects");
	}catch (Exception e) {
		Msg.showError(GhidraTransferable.class, null, null, null, e);
	}
	return null;
}
 
Example #27
Source File: DoThumbDisassemble.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {

	Processor armProcessor = Processor.findOrPossiblyCreateProcessor("ARM");
	if (currentProgram == null ||
		!currentProgram.getLanguage().getProcessor().equals(armProcessor)) {
		Msg.showError(this, null, "Script Error",
			"Script only supports programs with ARM language");
		return;
	}

	Register tmodeReg = currentProgram.getProgramContext().getRegister("TMode");
	if (tmodeReg == null) {
		Msg.showError(this, null, "Script Error",
			"Script only supports ARM language variants with Thumb support");
		return;
	}
	RegisterValue thumbMode = new RegisterValue(tmodeReg, BigInteger.ONE);

	AddressSet set = new AddressSet();
	if (currentSelection == null || currentSelection.isEmpty()) {
		set.addRange(currentAddress, currentAddress);
	}
	else {
		set.add(currentSelection);
	}

	DisassembleCommand cmd = new DisassembleCommand(set, null, true);
	cmd.setInitialContext(thumbMode);
	cmd.applyTo(currentProgram, monitor);

}
 
Example #28
Source File: EventManager.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void sendToolEvent(PluginEvent event) {
	if (toolListeners.isEmpty()) {
		return;
	}

	if (!event.isToolEvent()) {
		return;
	}

	sendingToolEvent = true;
	try {
		event.setSourceName(PluginEvent.EXTERNAL_SOURCE_NAME);
		event.setTriggerEvent(null);
		for (int i = 0; i < toolListeners.size(); i++) {
			ToolListener tl = toolListeners.get(i);

			try {
				tl.processToolEvent(event);
			}
			catch (Throwable t) {
				Msg.showError(this, tool.getToolFrame(), "Plugin Event Error",
					"Error sending event to connected tool", t);
			}
		}
	}
	finally {
		sendingToolEvent = false;
	}
}
 
Example #29
Source File: ElfCompatibilityProvider.java    From Ghidra-Switch-Loader with ISC License 5 votes vote down vote up
public List<NXRelocation> getRelocations()
{
    if (!this.relocs.isEmpty())
        return this.relocs;
    
    ElfDynamicTable dynamicTable = this.getDynamicTable();
    ElfSymbolTable symbolTable = this.getSymbolTable();
    
    if (dynamicTable == null || symbolTable == null)
        return this.relocs;
    
    try
    {
        if (dynamicTable.containsDynamicValue(ElfDynamicType.DT_REL.value)) 
        {
            Msg.info(this, "Processing DT_REL relocations...");
            processRelocations(this.relocs, this.symbolTable,
                    (long)this.dynamicTable.getDynamicValue(ElfDynamicType.DT_REL),
                    (long)this.dynamicTable.getDynamicValue(ElfDynamicType.DT_RELSZ));
        }
        
        if (dynamicTable.containsDynamicValue(ElfDynamicType.DT_RELA)) 
        {
            Msg.info(this, "Processing DT_RELA relocations...");
            processRelocations(this.relocs, this.symbolTable,
                    (long)this.dynamicTable.getDynamicValue(ElfDynamicType.DT_RELA),
                    (long)this.dynamicTable.getDynamicValue(ElfDynamicType.DT_RELASZ));
        }
    }
    catch (NotFoundException | IOException e)
    {
        Msg.error(this, "Failed to get relocations", e);
    }
    
    this.relocs.addAll(this.getPltRelocations());
    return this.relocs;
}
 
Example #30
Source File: MemoryBlockUtils.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Adjusts the name of the fragment at the given address to the given name.
 * @param program the program whose fragment is to be renamed.
 * @param address the address of the fragment to be renamed.
 * @param name the new name for the fragment.
 */
public static void adjustFragment(Program program, Address address, String name) {
	Listing listing = program.getListing();
	String[] treeNames = listing.getTreeNames();
	for (String treeName : treeNames) {
		try {
			ProgramFragment frag = listing.getFragment(treeName, address);
			frag.setName(name);
		}
		catch (DuplicateNameException e) {
			Msg.warn(MemoryBlockUtils.class,
				"Could not rename fragment to match newly created block because of name conflict");
		}
	}
}