Search in sources :

Example 6 with TypeMember

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

the class TypeSubstitutionDialog method createOrUpdateSubstitution.

private void createOrUpdateSubstitution(final TypeSelectionPath path) throws CouldntSaveDataException {
    final int offset = path.determineTotalMemberOffset();
    final BaseType baseType = path.getRootType();
    final int position = selectedNode.getOperandPosition();
    final IAddress address = selectedNode.getInstructionAddress();
    final TypeSubstitution substitution = selectedNode.getTypeSubstitution();
    final List<TypeMember> memberPath = path.getMembers();
    if (substitution == null) {
        typeManager.createTypeSubstitution(selectedNode, baseType, memberPath, position, offset, address);
    } else {
        typeManager.updateTypeSubstitution(selectedNode, substitution, baseType, path.getMembers(), offset);
    }
}
Also used : TypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.TypeSubstitution) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 7 with TypeMember

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

the class AppendMemberAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final MemberDialog dlg = MemberDialog.createBuildNewMemberDialog(owner, typeManager);
    GuiHelper.centerChildToParent(owner, dlg, true);
    dlg.setVisible(true);
    if (!dlg.wasCanceled()) {
        final String name = dlg.getMemberName();
        final BaseType baseType = dlg.getBaseType();
        try {
            final TypeMember member = typeManager.appendMember(selectedType, baseType, name);
            if (member == null) {
                CMessageBox.showInformation(owner, "Unable to append member since that would create a recursive type definition.");
            }
        } catch (final CouldntSaveDataException exception) {
            CUtilityFunctions.logException(exception);
        }
    }
}
Also used : BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) MemberDialog(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.MemberDialog)

Example 8 with TypeMember

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

the class TypeDependenceGraph method initializeMembers.

/**
   * Initializes a set of members in the type dependence graph. This function is supposed to be used
   * on database load only. The reason for this class is reduction of database load time. This is
   * due to the normal mechanism of adding a member where the type system ensures consistency. On
   * load time we assume that the data from the database is sane and will bail out otherwise.
   *
   * @param members The {@link ImmutableCollection collection} of {@link TypeMember type members} to
   *        add to the dependence graph.
   */
private void initializeMembers(final ImmutableCollection<TypeMember> members) {
    Preconditions.checkNotNull(members, "Error: members argument can not be null.");
    for (TypeMember typeMember : members) {
        final Node memberTypeNode = containedRelationMap.get(typeMember.getBaseType());
        final Node parentNode = containedRelationMap.get(typeMember.getParentType());
        containedRelation.createEdge(memberTypeNode, parentNode);
    }
    if (!Cycles.findCycle(containedRelation, true).isEmpty()) {
        throw new IllegalStateException("Error: Dependence graph has cycles after initialization.");
    }
}
Also used : TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) Node(y.base.Node)

Example 9 with TypeMember

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

the class BaseTypeTableCellRenderer method renderStruct.

private static void renderStruct(final TypeInstance instance, final StyledDocument document, final boolean renderData) {
    final Style structNameStyle = createDeclarationStyle(document);
    final Style structMemberStyle = document.addStyle("STRUCTMEMBERSTYLE", structNameStyle);
    StyleConstants.setForeground(structMemberStyle, Color.GRAY);
    final Style structContentStyle = document.addStyle("STRUCTCONTENTSTYLE", structNameStyle);
    StyleConstants.setForeground(structContentStyle, Color.BLUE);
    StyleConstants.setAlignment(structNameStyle, StyleConstants.ALIGN_RIGHT);
    final BaseType baseType = instance.getBaseType();
    int maxMemberLength = 0;
    for (final TypeMember member : baseType) {
        if (member.getBaseType().getName().length() > maxMemberLength) {
            maxMemberLength = member.getBaseType().getName().length();
        }
    }
    int maxNameLength = 0;
    for (final TypeMember member : baseType) {
        if (member.getName().length() > maxNameLength) {
            maxNameLength = member.getName().length();
        }
    }
    /* Renders type information for structures - construct a string such as:
     *
     * struct STRUCT_NAME { BASE_TYPE_NAME
     */
    try {
        document.remove(0, document.getLength());
        appendString(document, "struct " + baseType.getName() + " {\n", structNameStyle);
        long memberOffset = 0;
        for (final TypeMember member : baseType) {
            appendString(document, "  " + member.getBaseType().getName(), structNameStyle);
            final String separator = Strings.repeat(" ", maxMemberLength - member.getBaseType().getName().length() + 1);
            appendString(document, separator + member.getName(), structMemberStyle);
            appendString(document, ";", structMemberStyle);
            if (renderData) {
                final String dataSeperator = Strings.repeat(".", maxNameLength - member.getName().length() + 1);
                appendString(document, dataSeperator, structNameStyle);
                appendString(document, renderInstanceData(member.getBaseType(), instance.getAddress().getOffset() + memberOffset, instance.getSection()), createDataStyle(document));
                memberOffset += member.getBaseType().getByteSize();
            }
            appendString(document, "\n", structMemberStyle);
        }
        appendString(document, "};", structNameStyle);
    } catch (final BadLocationException exception) {
        CUtilityFunctions.logException(exception);
    }
}
Also used : BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Example 10 with TypeMember

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

the class ViewReferencesTableModel method addCompoundTypeSubstitutionToTree.

/**
   * Adds a {@link TypeSubstitution type substitution} for the given {@link INaviInstruction
   * instruction} to the tree. The types passed to this function need to be compund types.
   *
   * @param operandNode The {@link INaviOperandTreeNode operand node} which holds the
   *        {@link TypeSubstitution type substitution}.
   * @param instruction The {@link INaviInstruction instruction} which holds the
   *        {@link INaviOperandTreeNode operand node}.
   * @param typeSubstitution A {@link TypeSubstitution type substitution} which is a compound type.
   *        Must be of a compound {@link BaseTypeCategory base type category}.
   */
private void addCompoundTypeSubstitutionToTree(final INaviOperandTreeNode operandNode, final INaviInstruction instruction, final TypeSubstitution typeSubstitution) {
    final long completeOffset = operandNode.hasAddendSibling() ? (operandNode.determineAddendValue() * 8 + typeSubstitution.getOffset()) : typeSubstitution.getOffset();
    final WalkResult walkResult = BaseTypeHelpers.findMember(typeSubstitution.getBaseType(), completeOffset);
    if (!walkResult.isValid()) {
        return;
    }
    addBaseType(typeSubstitution.getBaseType());
    DefaultMutableTreeNode currentNode = baseTypeToTreeNode.get(typeSubstitution.getBaseType());
    for (TypeMember typeMember : walkResult.getPath()) {
        TypeMemberTreeNode nextNode = checkTypeMemberNodeExists(typeMember, currentNode);
        if (nextNode == null) {
            nextNode = new TypeMemberTreeNode(typeMember);
            typeMemberToTreeNode.put(typeMember, nextNode);
            insertNodeInto(nextNode, currentNode, currentNode.getChildCount());
        }
        currentNode = nextNode;
    }
    insertNodeInto(multiIndex.putTypeSubstitution(typeSubstitution, instruction), currentNode, currentNode.getChildCount());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TypeMember(com.google.security.zynamics.binnavi.disassembly.types.TypeMember) WalkResult(com.google.security.zynamics.binnavi.disassembly.types.BaseTypeHelpers.WalkResult) TypeMemberTreeNode(com.google.security.zynamics.binnavi.Gui.GraphWindows.types.TypeMemberTreeNode)

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