Search in sources :

Example 21 with INaviView

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

the class CDataflowViewCreator method create.

/**
   * Creates a new dataflow view.
   * 
   * @param container The container in which the dataflow view is created.
   * @param view The normal view that provides the control-flow information.
   * 
   * @return The created dataflow view.
   * 
   * @throws InternalTranslationException Thrown if the input view could not be translated to REIL.
   */
public static INaviView create(final IViewContainer container, final INaviView view) throws InternalTranslationException {
    Preconditions.checkNotNull(container, "IE00411: Module argument can not be null");
    Preconditions.checkNotNull(view, "IE00414: View argument can not be null");
    final Map<IAddress, INaviInstruction> instructions = new HashMap<IAddress, INaviInstruction>();
    for (final CCodeNode codeNode : view.getBasicBlocks()) {
        for (final INaviInstruction instruction : codeNode.getInstructions()) {
            instructions.put(instruction.getAddress(), instruction);
        }
    }
    final ReilFunction function = view.getContent().getReilCode();
    final OperandGraph operandGraph = OperandGraph.create(function.getGraph());
    final INaviView dfView = container.createView(String.format("Data flow view of '%s'", view.getName()), "");
    final Map<OperandGraphNode, INaviCodeNode> nodeMap = new HashMap<OperandGraphNode, INaviCodeNode>();
    final Map<INaviInstruction, CCodeNode> instructionMap = new HashMap<INaviInstruction, CCodeNode>();
    for (final OperandGraphNode operandGraphNode : operandGraph) {
        final ReilInstruction reilInstruction = operandGraphNode.getInstruction();
        final INaviInstruction instruction = instructions.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress()));
        if (instructionMap.containsKey(instruction)) {
            nodeMap.put(operandGraphNode, instructionMap.get(instruction));
            continue;
        }
        final CCodeNode codeNode = dfView.getContent().createCodeNode(null, Lists.newArrayList(instruction));
        codeNode.setColor(ConfigManager.instance().getColorSettings().getBasicBlocksColor());
        nodeMap.put(operandGraphNode, codeNode);
        instructionMap.put(instruction, codeNode);
    }
    for (final OperandGraphEdge edge : operandGraph.getEdges()) {
        final INaviCodeNode source = nodeMap.get(edge.getSource());
        final INaviCodeNode target = nodeMap.get(edge.getTarget());
        if (source.equals(target)) {
            continue;
        }
        dfView.getContent().createEdge(source, target, EdgeType.JUMP_UNCONDITIONAL);
    }
    return dfView;
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) HashMap(java.util.HashMap) ReilFunction(com.google.security.zynamics.reil.ReilFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) OperandGraph(com.google.security.zynamics.reil.algorithms.mono.OperandGraph) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) OperandGraphEdge(com.google.security.zynamics.reil.algorithms.mono.OperandGraphEdge) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) OperandGraphNode(com.google.security.zynamics.reil.algorithms.mono.OperandGraphNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 22 with INaviView

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

the class BreakpointHelpersTest method setUp.

@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
    final Database apiDatabase = new Database(database);
    final SQLProvider mockProvider = new MockSqlProvider();
    final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
    final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
    final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
    final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
    final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
    final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
    m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    m_module.load();
    m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
    m_mockDebugger.connect();
    m_debugger = new Debugger(m_mockDebugger);
    final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
    m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
    final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
    final INaviView naviView = new MockView(mockProvider);
    final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
    final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
    m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
    m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
    setM_functionNode(m_view.createFunctionNode(apiFunction));
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) View(com.google.security.zynamics.binnavi.API.disassembly.View) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 23 with INaviView

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

the class GroupNodeTest method testElements.

@Test
public void testElements() throws CouldntLoadDataException, PartialLoadException {
    final Database database = new Database(new MockDatabase());
    final SQLProvider mockProvider = new MockSqlProvider();
    final CModule mockModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
    final Module module = new Module(database, mockModule, nodeTagManager, viewTagManager);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final INaviView mockView = generator.generate(1, "", "", ViewType.NonNative, GraphType.FLOWGRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    view.load();
    final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, mockProvider);
    final CodeNode codeNode = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
    final CodeNode codeNode2 = view.createCodeNode(new Function(module, parentFunction), Lists.newArrayList(new Instruction(new MockInstruction())));
    final GroupNode node = view.createGroupNode("", Lists.newArrayList((ViewNode) codeNode2));
    final MockGroupNodeListener listener = new MockGroupNodeListener();
    final MockViewNodeListener listener2 = new MockViewNodeListener();
    node.addListener(listener);
    codeNode.addListener(listener2);
    node.addNode(codeNode);
    assertEquals(2, node.getElements().size());
    assertEquals(codeNode, node.getElements().get(1));
    assertEquals(node, codeNode.getParentGroup());
    assertEquals("addedElement;", listener.events);
    assertEquals("changedParentGroup;", listener2.events);
    node.removeNode(codeNode);
    assertEquals(1, node.getElements().size());
    assertEquals(null, codeNode.getParentGroup());
    assertEquals("addedElement;removedElement;", listener.events);
    assertEquals("changedParentGroup;changedParentGroup;", listener2.events);
    node.removeListener(listener);
}
Also used : CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 24 with INaviView

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

the class CGraphInliner method inlineFunction.

/**
   * Replaces a function node with the basic blocks of a function.
   * 
   * @param parent Parent window that is used to display error messages.
   * @param graph Graph where the inlining operation happens.
   * @param node The function node that is replaced by the basic blocks of the corresponding
   *        function.
   */
public static void inlineFunction(final JFrame parent, final ZyGraph graph, final INaviFunctionNode node) {
    Preconditions.checkNotNull(parent, "IE01743: Parent argument can not be null");
    Preconditions.checkNotNull(graph, "IE01744: Graph argument can not be null");
    Preconditions.checkNotNull(node, "IE01745: Node argument can not be null");
    final INaviView view = graph.getRawView();
    final INaviFunction function = node.getFunction();
    try {
        if (!function.isLoaded()) {
            function.load();
        }
        CInliningHelper.inlineFunctionNode(view, node);
        if (graph.getSettings().getLayoutSettings().getAutomaticLayouting()) {
            CGraphLayouter.refreshLayout(parent, graph);
        }
    } catch (final CouldntLoadDataException e) {
        exceptionDialog(parent, function, e);
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 25 with INaviView

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

the class CViewInserter method insertView.

/**
   * Asks the user for a view and inserts that view into a graph.
   *
   * @param parent Parent window used to display dialogs.
   * @param graph The graph where the view is inserted.
   * @param viewContainer The container that provides the views that can be inserted.
   */
public static void insertView(final JFrame parent, final ZyGraph graph, final IViewContainer viewContainer) {
    Preconditions.checkNotNull(parent, "IE00008: Parent argument can not be null");
    Preconditions.checkNotNull(graph, "IE00009: Graph argument can not be null");
    Preconditions.checkNotNull(viewContainer, "IE00010: View container argument can not be null");
    final CViewSelectionDialog dlg = new CViewSelectionDialog(parent, viewContainer);
    GuiHelper.centerChildToParent(parent, dlg, true);
    dlg.setVisible(true);
    final INaviView view = dlg.getView();
    if (view != null) {
        if (!view.isLoaded() && !loadView(parent, viewContainer, view)) {
            // View can not be loaded for some reason
            return;
        }
        com.google.security.zynamics.binnavi.disassembly.algorithms.CViewInserter.insertView(view, graph.getRawView());
        graph.updateViews();
        view.close();
    }
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) CViewSelectionDialog(com.google.security.zynamics.binnavi.Gui.InsertViewDialog.CViewSelectionDialog)

Aggregations

INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)121 Test (org.junit.Test)54 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)29 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)26 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)18 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)11 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)10 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)10 ArrayList (java.util.ArrayList)10 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)8 HashMap (java.util.HashMap)8 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)7 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 CProjectContainer (com.google.security.zynamics.binnavi.disassembly.CProjectContainer)7 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)7 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)7 MockTagManager (com.google.security.zynamics.binnavi.Tagging.MockTagManager)6