Search in sources :

Example 11 with TypeMember

use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.

the class TypeEditorMouseHandler method createNodeClickedMenu.

private JPopupMenu createNodeClickedMenu(final TreeNode clickedNode) {
    final JPopupMenu popupMenu = new JPopupMenu();
    if (clickedNode instanceof TypeMemberTreeNode) {
        final TypeMember selectedMember = ((TypeMemberTreeNode) clickedNode).getTypeMember();
        final AbstractAction editMemberAction = new EditMemberAction(owner, typeManager, selectedMember);
        final AbstractAction insertAction = new InsertMemberAction(owner, typeManager, selectedMember);
        if (tree.getSelectionCount() > 1) {
            editMemberAction.setEnabled(false);
            insertAction.setEnabled(false);
        }
        if (selectedMember.getParentType() != null && selectedMember.getParentType().getCategory() == BaseTypeCategory.STRUCT) {
            popupMenu.add(new AppendMemberAction(owner, typeManager, selectedMember.getParentType()));
            popupMenu.add(insertAction);
        }
        popupMenu.add(editMemberAction);
        popupMenu.add(new DeleteMemberAction(owner, typeManager, typeEditor));
    } else if (clickedNode instanceof BaseTypeTreeNode) {
        final BaseType selectedType = ((BaseTypeTreeNode) clickedNode).getBaseType();
        final AbstractAction editAction = new EditTypeAction(owner, typeManager, selectedType);
        final AbstractAction appendAction = new AppendMemberAction(owner, typeManager, selectedType);
        if (tree.getSelectionCount() > 1) {
            editAction.setEnabled(false);
            appendAction.setEnabled(false);
        } else if (selectedType.getCategory() != BaseTypeCategory.STRUCT) {
            appendAction.setEnabled(false);
        }
        popupMenu.add(editAction);
        popupMenu.add(appendAction);
        popupMenu.add(new DeleteTypeAction(owner, typeManager, typeEditor));
    }
    return popupMenu;
}
Also used : AppendMemberAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.AppendMemberAction) EditMemberAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.EditMemberAction) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) EditTypeAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.EditTypeAction) InsertMemberAction(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.InsertMemberAction) AbstractAction(javax.swing.AbstractAction) JPopupMenu(javax.swing.JPopupMenu)

Example 12 with TypeMember

use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.

the class TypesTree method determineTypePath.

/**
   * Returns a {@link TypeSelectionPath} instance that describes the path to the selected member or
   * base type. Returns null if no selection exists.
   */
public TypeSelectionPath determineTypePath() {
    final TreePath path = getSelectionModel().getSelectionPath();
    if (path == null || path.getPathCount() == 0) {
        return new TypeSelectionPath(null, new ArrayList<TypeMember>());
    }
    // The first node is the invisible root node, the second a base type node. Afterwards, a list
    // of member nodes.
    final Object[] nodes = path.getPath();
    final BaseType rootType = ((BaseTypeTreeNode) nodes[1]).getBaseType();
    final List<TypeMember> memberPath = Lists.newArrayList();
    for (int i = 2; i < path.getPathCount(); ++i) {
        memberPath.add(((TypeMemberTreeNode) nodes[i]).getTypeMember());
    }
    return new TypeSelectionPath(rootType, memberPath);
}
Also used : TreePath(javax.swing.tree.TreePath) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember)

Example 13 with TypeMember

use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.

the class TypesTreeModel method removeNodes.

/**
   * Removes a list of given nodes from the model and updates node maps.
   */
private void removeNodes(final List<DefaultMutableTreeNode> nodes) {
    for (final DefaultMutableTreeNode node : nodes) {
        if (node instanceof TypeMemberTreeNode) {
            final TypeMember member = ((TypeMemberTreeNode) node).getTypeMember();
            nestedStructNodes.get(member.getBaseType()).removeAll(memberNodes.get(member));
            memberNodes.remove(member, node);
        }
        node.removeFromParent();
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember)

Example 14 with TypeMember

use of com.google.security.zynamics.binnavi.disassembly.types.TypeMember in project binnavi by google.

the class TypesTreeModel method createTypeNodes.

// Recursively creates all tree nodes for the given base type instance.
private void createTypeNodes(final DefaultMutableTreeNode currentNode, final BaseType baseType) {
    if (baseType.getCategory() == BaseTypeCategory.ARRAY) {
        // without creating that member node.
        return;
    } else {
        for (final TypeMember member : baseType) {
            switch(member.getBaseType().getCategory()) {
                case ARRAY:
                case ATOMIC:
                case POINTER:
                    final TypeMemberTreeNode memberNode = new TypeMemberTreeNode(member);
                    currentNode.add(memberNode);
                    memberNodes.put(member, memberNode);
                    break;
                case FUNCTION_PROTOTYPE:
                    break;
                case STRUCT:
                case UNION:
                    // This member has a base type that itself has multiple members: we need to go deeper!
                    final TypeMemberTreeNode nestedNode = new TypeMemberTreeNode(member);
                    memberNodes.put(member, nestedNode);
                    nestedStructNodes.put(member.getBaseType(), nestedNode);
                    currentNode.add(nestedNode);
                    createTypeNodes(nestedNode, member.getBaseType());
                    break;
                default:
                    NaviLogger.warning("Unknown type category: %d", member.getBaseType().getCategory());
                    break;
            }
        }
    }
}
Also used : TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember)

Aggregations

TypeMember (com.google.security.zynamics.binnavi.disassembly.types.TypeMember)14 BaseType (com.google.security.zynamics.binnavi.disassembly.types.BaseType)6 TypeSubstitution (com.google.security.zynamics.binnavi.disassembly.types.TypeSubstitution)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 TreePath (javax.swing.tree.TreePath)2 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)1 MemberDialog (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.MemberDialog)1 TypeMemberTreeNode (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.TypeMemberTreeNode)1 AppendMemberAction (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.AppendMemberAction)1 EditMemberAction (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.EditMemberAction)1 EditTypeAction (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.EditTypeAction)1 InsertMemberAction (com.google.security.zynamics.binnavi.Gui.GraphWindows.types.actions.InsertMemberAction)1 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)1 WalkResult (com.google.security.zynamics.binnavi.disassembly.types.BaseTypeHelpers.WalkResult)1 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)1 AbstractAction (javax.swing.AbstractAction)1 JPopupMenu (javax.swing.JPopupMenu)1 BadLocationException (javax.swing.text.BadLocationException)1 Style (javax.swing.text.Style)1 Test (org.junit.Test)1