Search in sources :

Example 26 with CCodeNode

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

the class CReilViewCreator method create.

/**
   * Creates a REIL view from a view.
   * 
   * @param container The container in which the new REIL view is created.
   * @param view The view to be translated to REIL code.
   * 
   * @return The created REIL code view.
   * 
   * @throws InternalTranslationException Thrown if the view could not be translated to REIL code.
   * @throws CouldntLoadDataException
   */
public static INaviView create(final INaviModule container, final INaviView view) throws InternalTranslationException, CouldntLoadDataException {
    Preconditions.checkNotNull(container, "IE01768: Container argument can not be null");
    Preconditions.checkNotNull(view, "IE01769: View argument can not be null");
    final Map<IAddress, String> textMap = new HashMap<IAddress, String>();
    for (final CCodeNode node : view.getBasicBlocks()) {
        for (final INaviInstruction instruction : node.getInstructions()) {
            textMap.put(instruction.getAddress(), instruction.toString());
        }
    }
    final INaviView reilView = CReilViewCreator.create(container, view.getContent().getReilCode().getGraph());
    for (final CCodeNode node : reilView.getBasicBlocks()) {
        for (final INaviInstruction reilInstruction : node.getInstructions()) {
            if ((reilInstruction.getAddress().toLong() & 0xFF) == 0) {
                try {
                    node.getComments().appendLocalInstructionComment(reilInstruction, textMap.get(ReilHelpers.toNativeAddress(reilInstruction.getAddress())));
                } catch (final CouldntSaveDataException e) {
                    // Not possible for unsaved views.
                    CUtilityFunctions.logException(e);
                }
            }
        }
    }
    return reilView;
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) HashMap(java.util.HashMap) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 27 with CCodeNode

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

the class ViewTest method testGraph.

@Test
public void testGraph() {
    final List<INaviViewNode> nodes = new ArrayList<INaviViewNode>();
    final List<INaviEdge> edges = new ArrayList<INaviEdge>();
    final MutableDirectedGraph<INaviViewNode, INaviEdge> graph = new MutableDirectedGraph<INaviViewNode, INaviEdge>(nodes, edges);
    final int viewId = new BigInteger(31, new SecureRandom()).intValue();
    final INaviView internalView = new CView(viewId, internalModule, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, m_creationDate, m_modificationDate, graph, new HashSet<CTag>(), false, m_provider);
    final INaviFunction internalFunction = internalModule.getContent().getFunctionContainer().getFunctions().get(0);
    final CCodeNode codeNode = internalView.getContent().createCodeNode(internalFunction, Lists.newArrayList(new MockInstruction()));
    final CFunctionNode functionNode = internalView.getContent().createFunctionNode(internalFunction);
    @SuppressWarnings("unused") final CTextNode textNode = internalView.getContent().createTextNode(Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo")));
    @SuppressWarnings("unused") final CGroupNode groupNode = internalView.getContent().createGroupNode(internalView.getGraph().getNodes());
    internalView.getContent().createEdge(codeNode, functionNode, com.google.security.zynamics.zylib.gui.zygraph.edges.EdgeType.JUMP_UNCONDITIONAL);
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final MockViewListener listener = new MockViewListener();
    final View view = new View(module, internalView, tagManager, m_viewTagManager);
    view.addListener(listener);
    assertEquals(4, view.getGraph().getNodes().size());
    assertEquals(1, view.getGraph().getEdges().size());
    internalView.getContent().deleteNodes(internalView.getContent().getGraph().getNodes());
    assertEquals("deletedEdge;deletedNode;deletedNode;deletedNode;", listener.events);
}
Also used : ArrayList(java.util.ArrayList) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) SecureRandom(java.security.SecureRandom) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) 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) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) Test(org.junit.Test)

Example 28 with CCodeNode

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

the class CodeNodeTest method setUp.

@Before
public void setUp() {
    final Database database = new Database(new MockDatabase());
    final MockModule mockModule = new MockModule();
    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 MockView mockView = new MockView();
    final View view = new View(module, mockView, nodeTagManager, viewTagManager);
    final MockSqlProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
    final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    final CComment m_globalComment = new CComment(null, CommonTestObjects.TEST_USER_1, null, "Global Comment");
    final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, Lists.<IComment>newArrayList(m_globalComment), internalFunction, new HashSet<CTag>(), new MockSqlProvider());
    codeNode.addInstruction(new CInstruction(true, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider), null);
    m_node = new CodeNode(view, codeNode, nodeTagManager);
}
Also used : MockView(com.google.security.zynamics.binnavi.disassembly.MockView) DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) 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) Before(org.junit.Before)

Example 29 with CCodeNode

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

the class PostgreSQLNodeSaver method saveNodes.

/**
   * Saves the nodes to the nodes table. As a side effect, this function also fills index lists that
   * store the indices into the nodes list for all node types. TODO: This method should probably be
   * split into two methods.
   *
   * @param provider Provides the connection to the database.
   * @param newViewId ID of the new view that is being saved.
   * @param nodes The nodes to save.
   * @param functionNodeIndices Index into the nodes list that identifies the function nodes.
   * @param codeNodeIndices Index into the nodes list that identifies the code nodes.
   * @param textNodeIndices Index into the nodes list that identifies the text nodes.
   * @param groupNodeIndices Index into the nodes list that identifies the group nodes.
   * @param groupNodeMap Maps between node IDs and group node objects.
   * @return The ID of the first node saved to the database.
   * @throws SQLException Thrown if saving the nodes failed.
   */
private static int saveNodes(final AbstractSQLProvider provider, final int newViewId, final List<INaviViewNode> nodes, final List<Integer> functionNodeIndices, final List<Integer> codeNodeIndices, final List<Integer> textNodeIndices, final List<Integer> groupNodeIndices, final BiMap<Integer, INaviGroupNode> groupNodeMap) throws SQLException {
    final String query = "INSERT INTO " + CTableNames.NODES_TABLE + "( view_id, parent_id, type, x, y, width, height, color, bordercolor, " + " selected, visible) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    final PreparedStatement preparedStatement = provider.getConnection().getConnection().prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
    int counter = 0;
    for (final INaviViewNode node : nodes) {
        String nodeType = null;
        if (node instanceof CCodeNode) {
            nodeType = CODE;
            codeNodeIndices.add(counter);
        } else if (node instanceof CFunctionNode) {
            nodeType = FUNCTION;
            functionNodeIndices.add(counter);
        } else if (node instanceof INaviGroupNode) {
            nodeType = GROUP;
            groupNodeIndices.add(counter);
            groupNodeMap.put(counter, (INaviGroupNode) node);
        } else if (node instanceof CTextNode) {
            nodeType = TEXT;
            textNodeIndices.add(counter);
        }
        counter++;
        preparedStatement.setInt(1, newViewId);
        preparedStatement.setNull(2, Types.INTEGER);
        preparedStatement.setObject(3, nodeType, Types.OTHER);
        preparedStatement.setDouble(4, node.getX());
        preparedStatement.setDouble(5, node.getY());
        preparedStatement.setDouble(6, node.getWidth());
        preparedStatement.setDouble(7, node.getHeight());
        preparedStatement.setInt(8, node.getColor().getRGB());
        preparedStatement.setInt(9, node.getBorderColor().getRGB());
        preparedStatement.setBoolean(10, node.isSelected());
        preparedStatement.setBoolean(11, node.isVisible());
        preparedStatement.addBatch();
    }
    preparedStatement.executeBatch();
    final ResultSet resultSet = preparedStatement.getGeneratedKeys();
    int lastId = 0;
    try {
        while (resultSet.next()) {
            if (resultSet.isFirst()) {
                lastId = resultSet.getInt(1);
                break;
            }
        }
    } finally {
        preparedStatement.close();
        resultSet.close();
    }
    return lastId;
}
Also used : CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) ResultSet(java.sql.ResultSet) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) PreparedStatement(java.sql.PreparedStatement) INaviGroupNode(com.google.security.zynamics.binnavi.disassembly.INaviGroupNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode)

Example 30 with CCodeNode

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

the class CGraphDebuggerTest method testGetDebugger2.

@Test
public void testGetDebugger2() {
    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 ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Mock Comment"));
    final INaviCodeNode codeNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, false, comments, function, new HashSet<CTag>(), new MockSqlProvider());
    codeNode.addInstruction(new CInstruction(true, module, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", m_provider), null);
    assertEquals(m_debugger, CGraphDebugger.getDebugger(debuggerProvider, Iterables.getFirst(codeNode.getInstructions(), null)));
}
Also used : IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) 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) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) DebuggerProvider(com.google.security.zynamics.binnavi.debug.debugger.DebuggerProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) Test(org.junit.Test)

Aggregations

CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)38 Test (org.junit.Test)23 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)16 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)13 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)13 MockFunction (com.google.security.zynamics.binnavi.disassembly.MockFunction)12 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)11 ArrayList (java.util.ArrayList)11 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)10 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)9 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)9 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)8 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)7 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)7 MockInstruction (com.google.security.zynamics.binnavi.disassembly.MockInstruction)7 NaviNode (com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviNode)7 MockCodeNodeProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockCodeNodeProvider)6 CCodeNodeParser (com.google.security.zynamics.binnavi.Database.NodeParser.CCodeNodeParser)6 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)6