Search in sources :

Example 66 with INaviInstruction

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

the class CCommentUtilities method getLocalInstructionComments.

/**
 * TODO (timkornau): either comment the function or find a better way on how the commenting for
 * instructions can access all comments.
 */
public static List<Pair<INaviInstruction, IComment>> getLocalInstructionComments(final CCodeNode codeNode) {
    Preconditions.checkNotNull(codeNode, "IE02633: codeNode argument can not be null");
    final List<Pair<INaviInstruction, IComment>> values = new ArrayList<Pair<INaviInstruction, IComment>>();
    final CCodeNodeComments currentComments = codeNode.getComments();
    for (final INaviInstruction instruction : codeNode.getInstructions()) {
        final List<IComment> comments = currentComments.getLocalInstructionComment(instruction);
        if ((comments == null) || comments.isEmpty()) {
            values.add(new Pair<INaviInstruction, IComment>(instruction, null));
            continue;
        } else {
            for (final IComment comment : comments) {
                values.add(new Pair<INaviInstruction, IComment>(instruction, comment));
            }
        }
    }
    return values;
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CCodeNodeComments(com.google.security.zynamics.binnavi.disassembly.CCodeNodeComments) ArrayList(java.util.ArrayList) Pair(com.google.security.zynamics.zylib.general.Pair) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 67 with INaviInstruction

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

the class CRegisterTrackingHelper method getInstructionMap.

/**
 * Creates an address -> instruction mapping for all instructions in a graph.
 *
 * @param view The input graph.
 * @return The created mapping.
 */
public static Map<IAddress, INaviInstruction> getInstructionMap(final INaviView view) {
    final Map<IAddress, INaviInstruction> instructionMap = new HashMap<IAddress, INaviInstruction>();
    final List<INaviViewNode> nodes = view.getGraph().getNodes();
    for (final INaviViewNode node : nodes) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            for (final INaviInstruction instruction : cnode.getInstructions()) {
                instructionMap.put(instruction.getAddress(), instruction);
            }
        }
    }
    return instructionMap;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) HashMap(java.util.HashMap) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 68 with INaviInstruction

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

the class InstructionCommentsDataModel method keyPressedOrTyped.

@Override
public /**
 * Please read the comment in the base class regarding this method - it is somewhat counter-
 * intuitive for people used to the Swing keyboard handling model.
 */
void keyPressedOrTyped(CodeDisplayCoordinate coordinate, KeyEvent event) {
    if (!isEditable(coordinate)) {
        return;
    }
    // Are there any existing comments?
    INaviInstruction instruction = internalData.get(coordinate.getRow()).first();
    Pair<IComment, Pair<Integer, Integer>> commentAndIndex = getCommentAndIndexAtCoordinate(coordinate);
    IComment comment = commentAndIndex.first();
    Pair<Integer, Integer> indices = commentAndIndex.second();
    switch(event.getKeyCode()) {
        // VK_UNDEFINED implies that this was a KEY_TYPED event.
        case KeyEvent.VK_UNDEFINED:
            switch(event.getKeyChar()) {
                case java.awt.Event.ENTER:
                    handleRegularKeyInComment(instruction, comment, indices, coordinate, event);
                    coordinate.setLine(coordinate.getLine() + 1);
                    coordinate.setFieldIndex(0);
                    break;
                case java.awt.Event.BACK_SPACE:
                    handleBackspaceKeyInComment(instruction, comment, indices, coordinate);
                    break;
                case java.awt.Event.DELETE:
                    handleDeleteKeyInComment(instruction, comment, indices, coordinate);
                    break;
                default:
                    handleRegularKeyInComment(instruction, comment, indices, coordinate, event);
                    coordinate.setFieldIndex(coordinate.getFieldIndex() + 1);
                    break;
            }
            break;
        case KeyEvent.VK_HOME:
            coordinate.setFieldIndex(0);
            break;
        case KeyEvent.VK_END:
            coordinate.setFieldIndex(indices.second() - indices.first());
            break;
        default:
            Logger.warning("Default case in keyTyped hit, investigate why.");
            break;
    }
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 69 with INaviInstruction

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

the class InstructionCommentsDataModel method updateDataRepresentation.

private void updateDataRepresentation() {
    internalData.clear();
    for (INaviInstruction instruction : node.getInstructions()) {
        internalData.add(new Pair<INaviInstruction, ArrayList<IComment>>(instruction, new ArrayList<IComment>()));
    }
    int currentIndex = 0;
    for (Pair<INaviInstruction, IComment> dataPair : commentAccessor.getAllComments()) {
        // Is this the right instruction?
        while (dataPair.first() != internalData.get(currentIndex).first()) {
            currentIndex++;
        }
        internalData.get(currentIndex).second().add(dataPair.second());
    }
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ArrayList(java.util.ArrayList) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 70 with INaviInstruction

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

the class CReferenceFinder method fetchReferenceList.

/**
 * Searches for outgoing references of a tree node and its children.
 *
 * @param node The start node of the search,
 * @param instruction The instruction the node belongs to.
 * @param functions List where the found references are stored.
 */
private static void fetchReferenceList(final IOperandTreeNode node, final INaviInstruction instruction, final List<Pair<INaviInstruction, INaviFunction>> functions) {
    final List<IReference> references = node.getReferences();
    for (final IReference reference : references) {
        if (ReferenceType.isCodeReference(reference.getType())) {
            final IAddress target = reference.getTarget();
            final INaviFunction function = instruction.getModule().getContent().getFunctionContainer().getFunction(target);
            if (function != null) {
                functions.add(new Pair<INaviInstruction, INaviFunction>(instruction, function));
            }
        }
    }
    for (final IOperandTreeNode child : node.getChildren()) {
        fetchReferenceList(child, instruction, functions);
    }
}
Also used : IReference(com.google.security.zynamics.zylib.disassembly.IReference) IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Aggregations

INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)82 Test (org.junit.Test)27 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)26 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 ArrayList (java.util.ArrayList)24 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)20 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)18 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)16 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)15 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)15 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)10 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)10 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)9 IBlockNode (com.google.security.zynamics.binnavi.disassembly.IBlockNode)9 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)9 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)8 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)7