Java Code Examples for ghidra.framework.model.DomainFolder#createFolder()

The following examples show how to use ghidra.framework.model.DomainFolder#createFolder() . 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: MSLibBatchImportWorker.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private static DomainFolder getFolder(DomainFolder folder, String path,
		boolean createIfMissing) throws InvalidNameException, IOException {
	for (String pathpart : path.split("[/\\\\]")) {
		if (pathpart.isEmpty()) {
			continue;
		}
		pathpart = ensureSafeProjectObjName(pathpart);
		DomainFolder tmp = folder.getFolder(pathpart);
		if (tmp == null) {
			if (!createIfMissing) {
				return null;
			}
			tmp = folder.createFolder(pathpart);
		}
		folder = tmp;
	}
	return folder;
}
 
Example 2
Source File: FrontEndPluginActionsTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpandAll() throws Exception {
	DomainFolder f = rootFolder.createFolder("myFolder");
	f = f.createFolder("A");
	f = f.createFolder("B");
	f = f.createFolder("C");
	waitForSwing();

	GTreeNode myNode = rootNode.getChild("myFolder");
	setSelectionPath(rootNode.getTreePath());
	DockingActionIf expandAction = getAction("Expand All");
	performAction(expandAction, getDomainFileActionContext(), true);
	GTreeNode aNode = myNode.getChild("A");
	assertNotNull(aNode);
	GTreeNode bNode = aNode.getChild("B");
	assertNotNull(bNode);
	GTreeNode cNode = bNode.getChild("C");
	assertNotNull(cNode);
}
 
Example 3
Source File: FrontEndPluginActionsTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testCollapseAll() throws Exception {
	DomainFolder f = rootFolder.createFolder("myFolder");
	f = f.createFolder("A");
	f = f.createFolder("B");
	f = f.createFolder("C");
	waitForSwing();

	GTreeNode myNode = rootNode.getChild("myFolder");
	setSelectionPath(myNode.getTreePath());
	DockingActionIf expandAction = getAction("Expand All");
	performAction(expandAction, getDomainFileActionContext(), true);
	waitForTree();

	DockingActionIf collapseAction = getAction("Collapse All");
	performAction(collapseAction, getDomainFileActionContext(), true);
	waitForTree();
	assertTrue(!tree.isExpanded(myNode.getTreePath()));
	GTreeNode aNode = myNode.getChild("A");
	assertTrue(!tree.isExpanded(aNode.getTreePath()));
	GTreeNode bNode = aNode.getChild("B");
	assertTrue(!tree.isExpanded(bNode.getTreePath()));
	GTreeNode cNode = bNode.getChild("C");
	assertNotNull(cNode);
	assertTrue(!tree.isExpanded(cNode.getTreePath()));
}
 
Example 4
Source File: FrontEndPluginActionsTest.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectAll() throws Exception {
	DomainFolder f = rootFolder.createFolder("myFolder");
	f = f.createFolder("A");
	f = f.createFolder("B");
	f = f.createFolder("C");
	waitForSwing();

	setSelectionPath(rootNode.getTreePath());
	DockingActionIf selectAction = getAction("Select All");
	performAction(selectAction, getDomainFileActionContext(), true);
	waitForTree();

	BreadthFirstIterator it = new BreadthFirstIterator(rootNode);
	while (it.hasNext()) {
		GTreeNode node = it.next();
		assertTrue(tree.isPathSelected(node.getTreePath()));
	}
}
 
Example 5
Source File: GenerateLotsOfProgramsScript.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
protected void run() throws Exception {
	DomainFolder root = getProjectRootFolder();
	DomainFolder stuff = root.createFolder("stuff");
	createPrograms(stuff, 30);
	DomainFolder a = stuff.createFolder("A");
	createPrograms(a, 10);
	DomainFolder b = stuff.createFolder("B");
	createPrograms(b, 10);
	DomainFolder c = stuff.createFolder("C");
	createPrograms(c, 10);
	DomainFolder d = stuff.createFolder("D");
	createPrograms(d, 10);
	DomainFolder e = stuff.createFolder("E");
	createPrograms(e, 10);
	DomainFolder f = stuff.createFolder("F");
	createPrograms(f, 10);

	DomainFolder big = a.createFolder("Big");
	createPrograms(big, 200);
}
 
Example 6
Source File: SetLanguageTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Before
	public void setUp() throws Exception {
		env = new TestEnv();

		setErrorGUIEnabled(true);
		frontEndTool = env.getFrontEndTool();
		env.showFrontEndTool();

		setLanguageAction = getAction(frontEndTool, "LanguageProviderPlugin", "Set Language");

		// NOTE: Only test translation from a supported language to another supported language

// TODO: Change test data to a supported case (e.g., MIPS-32 to MIPS-64)

		DomainFolder rootFolder = env.getProject().getProjectData().getRootFolder();

		ProgramBuilder builder = new ProgramBuilder("notepad", "x86:LE:32:default");
		Program p = builder.getProgram();

		assertEquals(new LanguageID("x86:LE:32:default"), p.getLanguageID());
		rootFolder.createFile("notepad", p, TaskMonitor.DUMMY);
		env.release(p);
		builder.dispose();

		rootFolder.createFolder("XYZ");
		GTree tree = findComponent(frontEndTool.getToolFrame(), GTree.class);
		waitForTree(tree);

		GTreeNode rootNode = tree.getViewRoot();
		xyzFolderNode = rootNode.getChild(0);
		notepadNode = rootNode.getChild(1);
		notepadFile = ((DomainFileNode) notepadNode).getDomainFile();

		waitForSwing();
	}
 
Example 7
Source File: VersionControlAction1Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testRefreshFolder() throws Exception {

	doCreateVersions();

	DomainFolder rootFolder = frontEnd.getRootFolder();
	DomainFolder folder = rootFolder.createFolder("myFolder");

	Program p = frontEnd.buildProgram(this);
	folder.createFile("My_Program", p, TaskMonitor.DUMMY);
	p.release(this);

	waitForSwing();

	GTreeNode node = getNode(PROGRAM_A);
	DomainFile df = ((DomainFileNode) node).getDomainFile();
	df.copyTo(folder, TaskMonitor.DUMMY);

	waitForSwing();

	final GTreeNode fnode = getFolderNode("myFolder");
	assertNotNull(fnode);
	expandNode(fnode);
	assertEquals(2, fnode.getChildCount());
	selectNode(fnode);

	DockingActionIf action = getAction("Refresh");
	performFrontEndAction(action);
	assertEquals(2, fnode.getChildCount());
}
 
Example 8
Source File: VersionControlAction2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testActionsEnabledForFolder() throws Exception {

	DomainFolder rootFolder = frontEnd.getRootFolder();
	DomainFolder f = rootFolder.createFolder("myFolder");
	waitForSwing();

	Program p = frontEnd.buildProgram(this);
	f.createFile("Sample", p, TaskMonitor.DUMMY);
	p.release(this);

	waitForSwing();
	GTreeNode node = getFolderNode("myFolder");
	assertNotNull(node);

	expandNode(node);
	selectNode(node);

	Set<DockingActionIf> actions = frontEnd.getFrontEndActions();
	for (DockingActionIf action : actions) {
		if (!(action instanceof VersionControlAction)) {
			continue;
		}
		if (action.getName().equals("Find Checkouts")) {
			assertTrue(action.isEnabledForContext(getDomainFileActionContext(node)));
		}
		else {
			assertTrue(!action.isEnabledForContext(getDomainFileActionContext(node)));
		}
	}
}
 
Example 9
Source File: VersionControlAction2Test.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindCheckoutsInSubFolder() throws Exception {

	DomainFolder rootFolder = frontEnd.getRootFolder();
	DomainFolder folder = rootFolder.createFolder("myFolder_1");
	folder = folder.createFolder("myFolder_2");

	Program p = frontEnd.buildProgram(this);
	folder.createFile("My_Program", p, TaskMonitor.DUMMY);
	p.release(this);
	waitForSwing();

	GTreeNode node = getFolderNode("myFolder_1");
	assertNotNull(node);
	node = node.getChild("myFolder_2");
	assertNotNull(node);
	node = node.getChild("My_Program");
	assertNotNull(node);
	addToVersionControl(node, true);

	selectNode(getFolderNode("myFolder_1"));
	DockingActionIf action = getAction("Find Checkouts");
	performFrontEndAction(action);

	FindCheckoutsDialog dialog = waitForDialogComponent(FindCheckoutsDialog.class);
	assertNotNull(dialog);

	final GTable table = findComponent(dialog.getComponent(), GTable.class);
	assertNotNull(table);
	waitForBusyTable(table);

	FindCheckoutsTableModel model = (FindCheckoutsTableModel) table.getModel();

	assertEquals(1, model.getRowCount());
	CheckoutInfo checkoutInfo = model.getRowObject(0);
	DomainFile file = checkoutInfo.getFile();
	DomainFolder parent = file.getParent();
	assertEquals("/myFolder_1/myFolder_2", parent.getPathname());
	pressButtonByText(dialog, "Dismiss");
}
 
Example 10
Source File: VersionControlSlowScreenShots.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindMyCheckouts() throws Exception {

	frontEnd.createMultipleCheckins();

	DomainFolder rootFolder = frontEnd.getRootFolder();
	DomainFolder folder = rootFolder.createFolder("myFolder_1");
	folder = folder.createFolder("myFolder_2");
	Program p = frontEnd.buildProgram(this);
	folder.createFile("My_Program", p, TaskMonitor.DUMMY);
	p.release(this);

	GTreeNode node = frontEnd.waitForFolderNode("myFolder_1");
	assertNotNull(node);
	node = node.getChild("myFolder_2");
	assertNotNull(node);
	node = node.getChild("My_Program");
	assertNotNull(node);
	frontEnd.addToVersionControl(node, true);

	GTreeNode rootNode = frontEnd.getRootNode();
	frontEnd.selectNodes(rootNode);
	DockingActionIf action = frontEnd.getAction("Find Checkouts");
	frontEnd.performFrontEndAction(action);

	FindCheckoutsDialog dialog = waitForDialogComponent(FindCheckoutsDialog.class);
	assertNotNull(dialog);

	captureDialog(dialog);
}
 
Example 11
Source File: ProjectDataNewFolderAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private DomainFolder createNewFolderWithDefaultName(DomainFolder parentFolder) {
	String name = getNewFolderName(parentFolder);
	try {
		return parentFolder.createFolder(name);
	}
	catch (InvalidNameException | IOException e) {
		throw new AssertException("Unexpected Error creating new folder: "+name, e);
	}
}
 
Example 12
Source File: RecursiveRecursiveMSLibImport.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Pair<DomainFolder, String> establishProgramFolder(DomainFolder current,
		String preferredName) throws InvalidNameException, IOException {
	String[] splits = preferredName.split("[/\\\\]");
	for (int ii = 0; ii < splits.length - 1; ++ii) {
		String nextName = splits[ii];
		DomainFolder next = current.getFolder(nextName);
		if (next == null) {
			next = current.createFolder(mangleNameBecauseDomainFoldersAreSoRetro(nextName));
		}
		current = next;
	}
	return new Pair<DomainFolder, String>(current, splits[splits.length - 1]);
}
 
Example 13
Source File: ImportMSLibs.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private DomainFolder obtainSubfolder(DomainFolder parent, String child)
		throws InvalidNameException, IOException {
	child = mangleNameBecauseDomainFoldersAreSoRetro(child);
	DomainFolder folder = parent.getFolder(child);
	if (folder == null) {
		folder = parent.createFolder(child);
	}
	return folder;
}
 
Example 14
Source File: FrontEndPluginActionsTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteFolder() throws Exception {
	DomainFolder f = rootFolder.createFolder("myFolder");
	f = f.createFolder("A");
	f = f.createFolder("B");
	f = f.createFolder("C");

	createNotepadFile(f);

	GTreeNode myNode = getChild(rootNode, "myFolder");
	expandTreePath(myNode.getTreePath());

	// delete "A"; all subfolders should be removed
	GTreeNode aNode = getChild(myNode, "A");
	expandTreePath(aNode.getTreePath());
	setSelectionPaths(new TreePath[] { aNode.getTreePath() });
	GTreeNode bNode = getChild(aNode, "B");

	// ensure that selection occurred
	assertNotNull(tree.getSelectionPath());

	pressDelete();

	confirmDelete();

	waitForTasks();

	assertNull(getChild(myNode, "A"));
	assertNull(bNode.getParent());
}
 
Example 15
Source File: VersionControlAction1Test.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testFindMyCheckouts() throws Exception {
	doCreateVersions();

	DomainFolder rootFolder = frontEnd.getRootFolder();
	DomainFolder folder = rootFolder.createFolder("myFolder_1");
	folder = folder.createFolder("myFolder_2");
	Program p = frontEnd.buildProgram(this);
	folder.createFile("My_Program", p, TaskMonitor.DUMMY);
	p.release(this);

	GTreeNode node = getFolderNode("myFolder_1");
	assertNotNull(node);
	node = node.getChild("myFolder_2");
	assertNotNull(node);
	node = node.getChild("My_Program");
	assertNotNull(node);
	addToVersionControl(node, true);

	GTreeNode rootNode = frontEnd.getRootNode();
	selectNode(rootNode);
	DockingActionIf action = getAction("Find Checkouts");
	performFrontEndAction(action);

	FindCheckoutsDialog dialog = waitForDialogComponent(FindCheckoutsDialog.class);
	assertNotNull(dialog);

	final GTable table = findComponent(dialog.getComponent(), GTable.class);
	assertNotNull(table);
	waitForBusyTable(table);

	FindCheckoutsTableModel model = (FindCheckoutsTableModel) table.getModel();

	assertEquals(2, model.getRowCount());
	assertEquals(4, model.getColumnCount());

	DockingActionIf undoCheckoutAction = getAction("UndoCheckOut");
	DockingActionIf checkInAction = getAction("CheckIn");
	assertFalse(checkInAction.isEnabledForContext(dialog.getActionContext(null)));
	assertFalse(undoCheckoutAction.isEnabledForContext(dialog.getActionContext(null)));

	// make a selection in the table
	selectInTable(table, node);
	assertFalse(checkInAction.isEnabledForContext(dialog.getActionContext(null)));
	assertTrue(undoCheckoutAction.isEnabledForContext(dialog.getActionContext(null)));

	CheckoutInfo checkoutInfo = model.getRowObject(0);
	DomainFile file = checkoutInfo.getFile();
	DomainFolder parent = file.getParent();
	assertEquals("/myFolder_1/myFolder_2", parent.getPathname());
	pressButtonByText(dialog, "Dismiss");
}
 
Example 16
Source File: FrontEndPluginActionsTest.java    From ghidra with Apache License 2.0 4 votes vote down vote up
@Test
public void testRenameFolderInUse() throws Exception {
	// folder contains a file that is in use
	DomainFolder f = rootFolder.createFolder("myFolder");
	f = f.createFolder("A");
	f = f.createFolder("B");
	f = f.createFolder("C");

	Program p = createDefaultProgram("new", ProgramBuilder._TOY, this);

	DomainFile df = f.createFile("notepad", p, TaskMonitor.DUMMY);
	waitForSwing();

	final GTreeNode myNode = rootNode.getChild("myFolder");
	((DomainFolderNode) myNode).getDomainFolder().createFile("notepad", p, TaskMonitor.DUMMY);
	p.release(this);

	waitForSwing();
	tree.expandPath(myNode.getTreePath());
	assertNotNull(myNode.getChild("notepad"));

	setInUse(df, "/myFolder/notepad");

	setSelectionPath(myNode.getTreePath());

	final DockingActionIf renameAction = getAction("Rename");
	performAction(renameAction, getDomainFileActionContext(), true);
	waitForTree();

	// attempt to rename "myFolder"
	SwingUtilities.invokeLater(() -> {
		int row = tree.getRowForPath(myNode.getTreePath());
		DefaultTreeCellEditor cellEditor = (DefaultTreeCellEditor) tree.getCellEditor();
		JTree jTree = (JTree) getInstanceField("tree", tree);
		Container container = (Container) cellEditor.getTreeCellEditorComponent(jTree, myNode,
			true, true, false, row);
		JTextField textField = (JTextField) container.getComponent(0);

		textField.setText("My_Newfolder");
		tree.stopEditing();
	});

	waitForSwing();

	OptionDialog d = waitForDialogComponent(OptionDialog.class);
	assertNotNull(d);
	assertEquals("Rename Failed", d.getTitle());
	pressButtonByText(d.getComponent(), "OK");
	assertNotNull(rootNode.getChild("myFolder"));
}