Search in sources :

Example 36 with INaviInstruction

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

the class CTracking method track.

/**
   * Performs a register forward tracking operation.
   * 
   * @param view The view where the operation happens.
   * @param startInstruction The start instruction.
   * @param trackedRegister The register to track.
   * @param options Register tracking options.
   * 
   * @return The result of the register tracking operation.
   * 
   * @throws InternalTranslationException Thrown if the graph from the code could not be translated
   *         to REIL.
   */
public static CTrackingResult track(final INaviView view, final INaviInstruction startInstruction, final String trackedRegister, final RegisterTrackingOptions options) throws InternalTranslationException {
    Preconditions.checkNotNull(view, "IE01660: View argument can not be null");
    Preconditions.checkNotNull(startInstruction, "IE01661: Start instruction argument can not be null");
    Preconditions.checkNotNull(trackedRegister, "IE01662: Register argument can not be null");
    final MonoReilSolverResult<RegisterSetLatticeElement> result = RegisterTracker.track(view.getContent().getReilCode(), startInstruction, trackedRegister, options);
    final Map<IAddress, INaviInstruction> instructionMap = CRegisterTrackingHelper.getInstructionMap(view);
    final List<CInstructionResult> instructionResultList = new ArrayList<CInstructionResult>();
    final Map<IAddress, RegisterSetLatticeElement> perInstructionElement = result.generateAddressToStateMapping(startInstruction, options.trackIncoming());
    for (final Map.Entry<IAddress, RegisterSetLatticeElement> addressToStateMapEntry : perInstructionElement.entrySet()) {
        final RegisterSetLatticeElement element = addressToStateMapEntry.getValue();
        if (!element.getReadRegisters().isEmpty() || !element.getNewlyTaintedRegisters().isEmpty() || !element.getUntaintedRegisters().isEmpty() || !element.getUpdatedRegisters().isEmpty()) {
            final CAddress concreteAddress = new CAddress(addressToStateMapEntry.getKey().toLong() >> 8);
            instructionResultList.add(new CInstructionResult(instructionMap.get(concreteAddress), addressToStateMapEntry.getValue()));
        }
    }
    return new CTrackingResult(startInstruction, trackedRegister, instructionResultList);
}
Also used : ArrayList(java.util.ArrayList) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) RegisterSetLatticeElement(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterSetLatticeElement) Map(java.util.Map) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 37 with INaviInstruction

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

the class CViewPruner method convertNodes.

/**
   * Converts the nodes from the original view to the pruned view.
   *
   * @param view The original view.
   * @param prunedView The pruned view.
   * @param keptInstructions Instructions to add to the new view.
   *
   * @return A mapping between nodes of the original view and nodes of the pruned view.
   */
private static Map<INaviViewNode, INaviViewNode> convertNodes(final INaviView view, final INaviView prunedView, final List<INaviInstruction> keptInstructions) {
    final Map<INaviViewNode, INaviViewNode> nodeMap = new HashMap<INaviViewNode, INaviViewNode>();
    for (final INaviViewNode node : view.getGraph().getNodes()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            final ArrayList<INaviInstruction> newInstructions = Lists.newArrayList(cnode.getInstructions());
            newInstructions.retainAll(keptInstructions);
            if (!newInstructions.isEmpty()) {
                CCodeNode newNode;
                try {
                    newNode = prunedView.getContent().createCodeNode(cnode.getParentFunction(), newInstructions);
                } catch (final MaybeNullException e) {
                    newNode = prunedView.getContent().createCodeNode(null, newInstructions);
                }
                newNode.setBorderColor(node.getBorderColor());
                newNode.setColor(node.getColor());
                nodeMap.put(node, newNode);
            }
        } else if (node instanceof INaviFunctionNode) {
            final INaviFunction function = ((INaviFunctionNode) node).getFunction();
            final CFunctionNode newNode = prunedView.getContent().createFunctionNode(function);
            nodeMap.put(node, newNode);
        }
    }
    return nodeMap;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 38 with INaviInstruction

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

the class LocalInstructionCommentAccessor method getAllComments.

@Override
public ArrayList<Pair<INaviInstruction, IComment>> getAllComments() {
    final ArrayList<Pair<INaviInstruction, IComment>> values = new ArrayList<>();
    final CCodeNodeComments currentComments = m_codeNode.getComments();
    for (final INaviInstruction instruction : m_codeNode.getInstructions()) {
        final List<IComment> comments = currentComments.getLocalInstructionComment(instruction);
        if ((comments == null) || comments.isEmpty()) {
            values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
            continue;
        } else {
            for (final IComment comment : comments) {
                values.add(new Pair<INaviInstruction, IComment>(instruction, comment));
            }
            values.add(new Pair<INaviInstruction, IComment>(instruction, new EmptyComment()));
        }
    }
    return values;
}
Also used : EmptyComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.EmptyComment) 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 39 with INaviInstruction

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

the class CSteppingHelper method getAddress.

/**
   * Determines the start address of a node.
   *
   * @param node Node whose address is determined.
   *
   * @return The start address of the given node or null if the node does not have an address.
   */
private static BreakpointAddress getAddress(final INaviViewNode node) {
    if (node instanceof INaviCodeNode) {
        final INaviCodeNode ccnode = (INaviCodeNode) node;
        final INaviInstruction instruction = Iterables.getFirst(ccnode.getInstructions(), null);
        return new BreakpointAddress(instruction.getModule(), new UnrelocatedAddress(instruction.getAddress()));
    } else if (node instanceof INaviFunctionNode) {
        final INaviFunction function = ((INaviFunctionNode) node).getFunction();
        final INaviModule module = function.getModule();
        return new BreakpointAddress(module, new UnrelocatedAddress(function.getAddress()));
    } else {
        // Node types we can not step to
        return null;
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) UnrelocatedAddress(com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress) INaviFunctionNode(com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode) BreakpointAddress(com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 40 with INaviInstruction

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

the class CGraphSynchronizer method updateInstructionMap.

/**
   * Updates the cached Address => Instruction map.
   */
private void updateInstructionMap() {
    m_instructionMap.clear();
    for (final INaviViewNode node : m_graph.getRawView().getGraph()) {
        if (node instanceof INaviCodeNode) {
            final INaviCodeNode cnode = (INaviCodeNode) node;
            for (final INaviInstruction instruction : cnode.getInstructions()) {
                final IAddress address = instruction.getAddress();
                m_instructionMap.put(address, instruction);
            }
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) 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