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

The following examples show how to use ghidra.program.model.listing.Program#getName() . 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: DiffActionManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Notification to the action manager that a program was opened as the
 * second program to the program Diff. Actions are adjusted accordingly.
 */
void secondProgramOpened() {
	openCloseProgram2Action.setSelected(true);
	openCloseProgram2Action.setDescription("Close Diff View");

	Program firstProgram = plugin.getFirstProgram();
	Program secondProgram = plugin.getSecondProgram();
	String firstName = firstProgram.getName();
	String secondName = secondProgram.getName();

	//@formatter:off
	openCloseProgram2Action.setDescription(
		"<html><center>Close Diff View</center><br>" +
		"Current diff: " +
		"<b>"+HTMLUtilities.escapeHTML(firstName)+"</b> to <b>" +HTMLUtilities.escapeHTML(secondName)+"</b>");
	//@formatter:on
}
 
Example 2
Source File: ImporterUtilities.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private static Program doFSImportHelper(GFileSystemProgramProvider pfs, GFile gfile,
		DomainFolder destFolder, Object consumer, TaskMonitor monitor) throws Exception {
	Program program =
		pfs.getProgram(gfile, DefaultLanguageService.getLanguageService(), monitor, consumer);

	if (program != null) {
		String importFilename = ProjectDataUtils.getUniqueName(destFolder, program.getName());
		if (importFilename == null) {
			program.release(consumer);
			throw new IOException("Unable to find unique name for " + program.getName());
		}

		destFolder.createFile(importFilename, program, monitor);
	}
	return program;

}
 
Example 3
Source File: OpenFunctionTableAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionContext context) {
	if (!(context.getComponentProvider() instanceof FunctionComparisonProvider)) {
		return;
	}

	FunctionComparisonProvider provider =
		(FunctionComparisonProvider) context.getComponentProvider();
	Program currentProgram = programManagerService.getCurrentProgram();
	FunctionTableModel model = new FunctionTableModel(tool, currentProgram);
	model.reload(programManagerService.getCurrentProgram());

	TableChooserDialog<FunctionRowObject> diag =
		new TableChooserDialog<>("Select Functions: " + currentProgram.getName(),
			model, true);
	tool.showDialog(diag);
	List<FunctionRowObject> rows = diag.getSelectionItems();
	if (CollectionUtils.isBlank(rows)) {
		return; // the table chooser can return null if the operation was cancelled
	}

	Set<Function> functions =
		rows.stream().map(row -> row.getFunction()).collect(Collectors.toSet());
	comparisonService.compareFunctions(new HashSet<>(functions), provider);
}
 
Example 4
Source File: ProgramManagerPlugin.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void showProgramOptions(final Program currentProgram) {
	List<String> names = currentProgram.getOptionsNames();
	Options[] options = new Options[names.size()];
	for (int i = 0; i < names.size(); i++) {
		String optionName = names.get(i);
		options[i] = currentProgram.getOptions(optionName);
		if (optionName.equals("Program Information")) {
			setPropertyEditor(options[i], "Executable Location");
			options[i].setOptionsHelpLocation(new HelpLocation(getName(), "Program_Options"));
		}
	}
	OptionsDialog dialog = new OptionsDialog("Properties for " + currentProgram.getName(),
		"Properties", options, new OptionsEditorListener() {
			@Override
			public void beforeChangesApplied() {
				startTransaction(currentProgram);
			}

			@Override
			public void changesApplied() {
				endTransaction(currentProgram);
			}
		});
	dialog.setHelpLocation(new HelpLocation(HelpTopics.PROGRAM, "Program_Options"));
	tool.showDialog(dialog);
}
 
Example 5
Source File: ProgramMemoryComparator.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
   * <CODE>ProgramMemoryComparator</CODE> is used to determine the memory
   * address differences between two programs.
   *
   * @param program1 the first program
   * @param program2 the second program
   * @throws ProgramConflictException if the two programs can't be compared.
   */
  public ProgramMemoryComparator(Program program1, Program program2)
  throws ProgramConflictException {
      this.program1 = program1;
      this.program2 = program2;
      if (program1 == null || program2 == null) {
          throw new IllegalArgumentException("program cannot be null.");
      }
      // Check each program to see if the memory blocks have the same address types.
if (!similarPrograms(program1, program2)) {
	throw new ProgramConflictException("Address spaces conflict between "
		+ program1.getName() 
		+ " and "
		+ program2.getName() + ".\n");
}
      
      determineAddressDiffs();
  }
 
Example 6
Source File: ProgramMemoryComparator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Check each program to see if the memory blocks have the same address types.
 *
 * @param program1 the first program
 * @param program2 the second program
 *
 * @throws ProgramConflictException if the address types for the two programs
 * do not match.
 */
public static void compareAddressTypes(Program program1, Program program2)
        throws ProgramConflictException {
    // Do the programs have the same types of addresses?
    AddressFactory af1 = program1.getAddressFactory();
    AddressFactory af2 = program2.getAddressFactory();
    if (!af1.equals(af2)){
        throw new ProgramConflictException("Address types conflict between "
            + program1.getName() 
            + " and "
            + program2.getName() + ".\n");
    }
}
 
Example 7
Source File: MultiTabPluginTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testTabUpdate() throws Exception {
	Program p = openDummyProgram("login", true);

	// select second tab (the "login" program)
	panel = findComponent(tool.getToolFrame(), MultiTabPanel.class);

	// don't let focus issues hide the popup list
	panel.setIgnoreFocus(true);

	panel.setSelectedProgram(p);
	assertEquals(p, panel.getSelectedProgram());

	addComment(p);

	String oldName = p.getName();
	String newName = "myNewLogin";
	renameProgramFile(p, newName);
	ArrayList<DomainObjectChangeRecord> changeRecs = new ArrayList<>();
	changeRecs.add(
		new DomainObjectChangeRecord(DomainObject.DO_OBJECT_RENAMED, oldName, p.getName()));
	DomainObjectChangedEvent ev = new DomainObjectChangedEvent(p, changeRecs);
	runSwing(() -> env.getPlugin(MultiTabPlugin.class).domainObjectChanged(ev));

	// Check the name on the tab and in the tooltip.
	JPanel tabPanel = getTabPanel(p);
	JLabel label = (JLabel) findComponentByName(tabPanel, "objectName");
	assertEquals("*" + newName + " [Read-Only]", label.getText());
	assertTrue(label.getToolTipText().endsWith("/" + newName + " [Read-Only]*"));
}
 
Example 8
Source File: MultiProgramManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * @see ghidra.framework.model.DomainObjectListener#domainObjectChanged(ghidra.framework.model.DomainObjectChangedEvent)
 */
@Override
public void domainObjectChanged(DomainObjectChangedEvent ev) {
	if (!(ev.getSource() instanceof Program)) {
		return;
	}
	Program program = (Program) ev.getSource();
	if (ev.containsEvent(DomainObject.DO_DOMAIN_FILE_CHANGED) ||
		ev.containsEvent(DomainObject.DO_OBJECT_ERROR)) {
		for (int i = 0; i < ev.numRecords(); i++) {
			DomainObjectChangeRecord docr = ev.getChangeRecord(i);
			int eventType = docr.getEventType();
			if (eventType == DomainObject.DO_DOMAIN_FILE_CHANGED) {
				if (currentInfo != null && currentInfo.program == program) {
					String name = program.getDomainFile().toString();
					tool.setSubTitle(name);
				}
			}
			else if (eventType == DomainObject.DO_OBJECT_ERROR) {
				String msg;
				Throwable t = (Throwable) docr.getNewValue();
				if (t instanceof NoSuchObjectException) {
					msg = program.getName() + " was closed due to an unrecoverable error!" +
						"\nThis error could be the result of your computer becoming suspended" +
						"\nor sleeping allowing the network connection with the Ghidra Server" +
						"\nto fail.";
				}
				else {
					msg = program.getName() + " was closed due to an unrecoverable error!" +
						"\n \nSuch failures are generally due to an IO Error caused" +
						"\nby the local filesystem or server.";
				}

				//abort();
				Msg.showError(this, tool.getToolFrame(), "Severe Error Condition", msg);
				removeProgram(program);
				return;
			}

		}
	}
}
 
Example 9
Source File: DualProgramLocationPluginEvent.java    From ghidra with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a new DualProgramLocationPluginEvent.
 * @param src the name of the plugin that generated this event.
 * @param loc the ProgramLocation object that contains the new location.
 * @param program the program for which the loc object refers.
 */
public DualProgramLocationPluginEvent(String src, ProgramLocation loc, Program program) {
	super(src, NAME);
	this.loc = loc;
	this.programName = program.getName();
}