Search in sources :

Example 61 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class CTagTreeCellRenderer method renderTagTreeNode.

/**
   * Renders tree nodes that display information about a tag. These are typically the visible root
   * nodes of the tag tree.
   *
   * @param node The node to render.
   */
private void renderTagTreeNode(final CTagTreeNode node) {
    final CTag tag = node.getTag().getObject();
    setToolTipText(buildToolTip(tag));
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag)

Example 62 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class CInliningHelper method inlineCodeNode.

/**
   * Inlines the basic blocks of a function into a code node.
   * 
   * @param view The view where the inlining operation takes place.
   * @param originalNode The node where the inlining operation takes place.
   * @param inlineInstruction The function call instruction after which the function is inlined.
   * @param functionToInline The function to be inlined.
   * 
   * @return Contains information about the inlining result.
   */
public static CInliningResult inlineCodeNode(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction inlineInstruction, final INaviFunction functionToInline) {
    Preconditions.checkNotNull(view, "IE00108: View argument can not be null");
    Preconditions.checkNotNull(originalNode, "IE00109: Node argument can not be null");
    Preconditions.checkNotNull(inlineInstruction, "IE00110: Instruction argument can not be null");
    Preconditions.checkArgument(originalNode.hasInstruction(inlineInstruction), "IE00111: Instruction is not part of the code node");
    Preconditions.checkNotNull(functionToInline, "IE00112: Function argument can not be null");
    Preconditions.checkArgument(view.isLoaded(), "IE00113: View must be loaded before it can be inlined");
    Preconditions.checkArgument(view.getGraph().getNodes().contains(originalNode), "IE00114: Code node does not belong to the view");
    Preconditions.checkArgument(functionToInline.isLoaded(), "IE00115: Function must be loaded before it can be inlined");
    Preconditions.checkArgument(functionToInline.getBasicBlockCount() != 0, "IE00116: Functions with 0 blocks can not be inlined");
    final INaviGroupNode parentGroup = originalNode.getParentGroup();
    GroupHelpers.expandParents(originalNode);
    final List<INaviEdge> oldIncomingEdges = originalNode.getIncomingEdges();
    final List<INaviEdge> oldOutgoingEdges = originalNode.getOutgoingEdges();
    // At first we find out which instructions will be part of the new first block
    // and which instructions will be part of the new second block.
    final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
    final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
    List<INaviInstruction> currentBlock = upperInstructions;
    for (final INaviInstruction currentInstruction : originalNode.getInstructions()) {
        currentBlock.add(currentInstruction);
        if (currentInstruction == inlineInstruction) {
            currentBlock = lowerInstructions;
        }
    }
    // Now we create the new nodes from the instructions blocks
    INaviCodeNode firstNode;
    final List<INaviViewNode> continueNodes = new ArrayList<INaviViewNode>();
    final boolean keepOriginalBlock = lowerInstructions.isEmpty();
    CCodeNode returnNode = null;
    if (keepOriginalBlock) {
        // There are no instructions in the second block => therefore the call instruction
        // is the last instruction of the block => therefore no splitting is necessary =>
        // therefore we can just reuse the original block.
        firstNode = originalNode;
        for (final INaviEdge edge : originalNode.getOutgoingEdges()) {
            continueNodes.add(edge.getTarget());
            view.getContent().deleteEdge(edge);
        }
    } else {
        // The second block is not empty => the call instruction is somewhere in the middle =>
        // the block must be split => the original block becomes useless and must be replaced by
        // two new blocks.
        final boolean recolor = (originalNode.getIncomingEdges().size() == 1) && (originalNode.getIncomingEdges().get(0).getType() == EdgeType.ENTER_INLINED_FUNCTION) && (originalNode.getOutgoingEdges().size() == 1) && (originalNode.getOutgoingEdges().get(0).getType() == EdgeType.LEAVE_INLINED_FUNCTION);
        view.getContent().deleteNode(originalNode);
        try {
            firstNode = view.getContent().createCodeNode(originalNode.getParentFunction(), upperInstructions);
        } catch (final MaybeNullException exception) {
            firstNode = view.getContent().createCodeNode(null, upperInstructions);
        }
        firstNode.setColor(originalNode.getColor());
        firstNode.setBorderColor(originalNode.getBorderColor());
        try {
            returnNode = view.getContent().createCodeNode(originalNode.getParentFunction(), lowerInstructions);
        } catch (final MaybeNullException e1) {
            returnNode = view.getContent().createCodeNode(null, lowerInstructions);
        }
        returnNode.setColor(originalNode.getColor());
        if (recolor) {
            firstNode.setBorderColor(new Color(-16736256));
            returnNode.setBorderColor(new Color(-6291456));
        }
        if (parentGroup != null) {
            parentGroup.addElement(firstNode);
            parentGroup.addElement(returnNode);
        }
        // Copy the tags of the original node too
        final Iterator<CTag> it = originalNode.getTagsIterator();
        while (it.hasNext()) {
            final CTag tag = it.next();
            try {
                firstNode.tagNode(tag);
                returnNode.tagNode(tag);
            } catch (final CouldntSaveDataException e) {
                CUtilityFunctions.logException(e);
            }
        }
        continueNodes.add(returnNode);
    }
    // Insert the nodes and edges from the loaded function
    final Triple<CCodeNode, List<CCodeNode>, ArrayList<CCodeNode>> nodes = insertNodes(view, functionToInline, parentGroup);
    final INaviCodeNode entryNode = nodes.first();
    final List<CCodeNode> exitNodes = nodes.second();
    if (!keepOriginalBlock) {
        for (final INaviEdge incomingEdge : oldIncomingEdges) {
            if (incomingEdge.getSource() == originalNode) {
                final EdgeType edgeType = incomingEdge.getType();
                view.getContent().createEdge(returnNode, firstNode, edgeType);
            } else {
                final EdgeType edgeType = incomingEdge.getType();
                view.getContent().createEdge(incomingEdge.getSource(), firstNode, edgeType);
            }
        }
    }
    // Create an edge from the upper part of the split block to the entry node
    // of the inlined function.
    view.getContent().createEdge(firstNode, entryNode, EdgeType.ENTER_INLINED_FUNCTION);
    // of the original function where control flow continues.
    for (final INaviCodeNode exitNode : exitNodes) {
        for (final INaviViewNode continueNode : continueNodes) {
            view.getContent().createEdge(exitNode, continueNode, EdgeType.LEAVE_INLINED_FUNCTION);
        }
    }
    if (!keepOriginalBlock) {
        for (final INaviEdge oldChild : oldOutgoingEdges) {
            for (final INaviViewNode continueNode : continueNodes) {
                if (oldChild.getTarget() != originalNode) {
                    view.getContent().createEdge(continueNode, oldChild.getTarget(), oldChild.getType());
                }
            }
        }
    }
    return new CInliningResult(firstNode, returnNode);
}
Also used : MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) Color(java.awt.Color) ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) EdgeType(com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType) ArrayList(java.util.ArrayList) List(java.util.List) CInliningResult(com.google.security.zynamics.binnavi.disassembly.algorithms.CInliningResult)

Example 63 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLProviderTest method testCTagFunctionsMoveTag3.

@Test(expected = NullPointerException.class)
public void testCTagFunctionsMoveTag3() throws CouldntSaveDataException, CouldntLoadDataException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    tagManager.addTag(tagManager.getRootTag(), "Node Tag I");
    final ITreeNode<CTag> tag1 = tagManager.getRootTag().getChildren().get(0);
    PostgreSQLTagFunctions.moveTag((AbstractSQLProvider) getProvider(), tag1, null, null);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 64 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class PostgreSQLProviderTest method testSetDescription11.

@Test(expected = NullPointerException.class)
public void testSetDescription11() throws CouldntLoadDataException, CouldntSaveDataException {
    final CTagManager tagManager = getProvider().loadTagManager(TagType.VIEW_TAG);
    final ITreeNode<CTag> tag = tagManager.getRootTag().getChildren().get(0);
    getProvider().setDescription(tag.getObject(), null);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) ExpensiveBaseTest(com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest) Test(org.junit.Test)

Example 65 with CTag

use of com.google.security.zynamics.binnavi.Tagging.CTag in project binnavi by google.

the class CGraphDebuggerTest method testGetDebugger.

@Test
public void testGetDebugger() {
    final MockModule module = new MockModule();
    module.getConfiguration().setDebugger(m_debugger);
    final DebugTargetSettings target = new ModuleTargetSettings(module);
    final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
    debuggerProvider.addDebugger(m_debugger);
    final CFunction function = new CFunction(module, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, m_provider);
    final CFunctionNode functionNode = new CFunctionNode(0, function, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), m_provider);
    assertEquals(m_debugger, CGraphDebugger.getDebugger(debuggerProvider, functionNode));
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) DebugTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.DebugTargetSettings) ModuleTargetSettings(com.google.security.zynamics.binnavi.debug.debugger.ModuleTargetSettings) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

CTag (com.google.security.zynamics.binnavi.Tagging.CTag)113 Test (org.junit.Test)55 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)42 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)35 Date (java.util.Date)28 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)24 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)24 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)21 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)20 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)18 ArrayList (java.util.ArrayList)17 Tree (com.google.security.zynamics.zylib.types.trees.Tree)15 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)14 TreeNode (com.google.security.zynamics.zylib.types.trees.TreeNode)14 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)13 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)13 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)13 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)13 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12