Java Code Examples for ghidra.program.model.listing.ProgramFragment#getMinAddress()

The following examples show how to use ghidra.program.model.listing.ProgramFragment#getMinAddress() . 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: ProgramTreePlugin1Test.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoubleClick2() {
	setTreeView("Main Tree");
	ProgramNode node = root.getChild(".data");
	TreePath[] paths = new TreePath[] { node.getTreePath() };
	setViewPaths(paths);

	int row = getRowForPath(paths[0]);

	Rectangle rect = tree.getRowBounds(row);
	clickMouse(tree, MouseEvent.BUTTON1, rect.x, rect.y, 2, 0);
	node = (ProgramNode) tree.getPathForRow(3).getLastPathComponent();
	ProgramFragment fragment = node.getFragment();
	Address address = fragment.getMinAddress();
	assertEquals(address, cbPlugin.getCurrentAddress());
}
 
Example 2
Source File: AutoRenamePlugin.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Perform Fragment Auto-Rename on selected Fragments.
 * Rename is performed on all selected Fragments within Program Tree.
 */
void autoRenameCallback(ActionContext context) {

    Object obj = context.getContextObject();
    if (obj instanceof ProgramNode) {
        ProgramNode node = (ProgramNode) obj;

        CompoundCmd cmd = new CompoundCmd("Auto Rename Fragment(s)");
        SymbolTable symTable = currentProgram.getSymbolTable();

        // Find selected Fragments
        TreePath[] selectedPaths = node.getTree().getSelectionPaths();
        boolean ignoreDuplicateNames = (selectedPaths.length > 1);
        for (int i = 0; i < selectedPaths.length; i++) {
            ProgramNode n = (ProgramNode) selectedPaths[i].getLastPathComponent();
            if (!n.isFragment())
                continue;

            // Rename Fragment using minimum address label	
            ProgramFragment f = n.getFragment();
            Address a = f.getMinAddress();
            if (a == null)
                continue; // empty Fragment
            Symbol s = symTable.getPrimarySymbol(a);
            if (s != null) {
                cmd.add(new RenameCmd(f.getTreeName(), false, f.getName(), s.getName(), 
                	ignoreDuplicateNames));
            }
        }

        if (cmd.size() > 0 && !tool.execute(cmd, currentProgram)) {
            tool.setStatusInfo("Error renaming fragment: " + cmd.getStatusMsg());
        }
    }
}
 
Example 3
Source File: ProgramTreePlugin1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testDoubleClickOnFragment() {

	setTreeView("Main Tree");
	Rectangle rect = tree.getRowBounds(2);
	clickMouse(tree, MouseEvent.BUTTON1, rect.x, rect.y, 2, 0);

	ProgramNode node = (ProgramNode) tree.getPathForRow(2).getLastPathComponent();
	ProgramFragment fragment = node.getFragment();
	Address address = fragment.getMinAddress();
	assertEquals(address, cbPlugin.getCurrentAddress());
}