Search in sources :

Example 61 with INaviCodeNode

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

the class ViewGraphHelpersTest method setUp.

@Before
public void setUp() throws CouldntLoadDataException, LoadCancelledException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, PartialLoadException {
    final MockSqlProvider provider = new MockSqlProvider();
    final TagManager tagManager = new TagManager(new MockTagManager(TagType.NODE_TAG));
    final TagManager viewTagManager = new TagManager(new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "", "", TagType.VIEW_TAG, provider))), TagType.VIEW_TAG, provider));
    final Database database = new Database(new MockDatabase());
    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, provider);
    internalModule.load();
    final Module module = new Module(database, internalModule, tagManager, viewTagManager);
    final CModuleViewGenerator generator = new CModuleViewGenerator(provider, internalModule);
    final INaviView internalView = generator.generate(1, "My View", "My View Description", com.google.security.zynamics.zylib.disassembly.ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 1, 2, new HashSet<CTag>(), new HashSet<CTag>(), false);
    m_view = new View(module, internalView, tagManager, viewTagManager);
    m_view.load();
    final List<INaviInstruction> instructions = new ArrayList<INaviInstruction>();
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x123), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x124), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    instructions.add(new CInstruction(false, internalModule, new CAddress(0x125), "nop", new ArrayList<COperandTree>(), new byte[] { (byte) 0x90 }, "x86-32", provider));
    final INaviCodeNode codeNode = internalView.getContent().createCodeNode(null, instructions);
    final List<INaviViewNode> nodes1 = new ArrayList<INaviViewNode>();
    nodes1.add(codeNode);
    final List<INaviEdge> edges1 = new ArrayList<INaviEdge>();
    final CFunction internalFunction = new CFunction(internalModule, new MockView(nodes1, edges1, provider), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
    internalFunction.load();
    final Function function = new Function(module, internalFunction);
    final CFunctionNode functionNode = new CFunctionNode(0, internalFunction, 0, 0, 0, 0, Color.RED, false, false, null, new HashSet<CTag>(), provider);
    m_codeNode = new CodeNode(m_view, codeNode, tagManager);
    m_functionNode = new FunctionNode(m_view, functionNode, function, tagManager);
    m_textNode = new TextNode(m_view, new MockTextNode(), tagManager);
    final List<ViewNode> nodes = Lists.newArrayList(m_codeNode, m_functionNode, m_textNode);
    final List<ViewEdge> edges = Lists.newArrayList(new ViewEdge(new MockEdge(1, provider), nodes.get(0), nodes.get(0)));
    m_graph = new ViewGraph(nodes, edges);
}
Also used : MockEdge(com.google.security.zynamics.binnavi.disassembly.MockEdge) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) ArrayList(java.util.ArrayList) MockTagManager(com.google.security.zynamics.binnavi.Tagging.MockTagManager) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Tree(com.google.security.zynamics.zylib.types.trees.Tree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) MockTextNode(com.google.security.zynamics.binnavi.disassembly.MockTextNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) 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) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Before(org.junit.Before)

Example 62 with INaviCodeNode

use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode 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 63 with INaviCodeNode

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

the class CCodeNodeParser method addInstruction.

/**
   * Adds an instruction to a code node.
   *
   * @param node The code node where the instruction is added.
   * @param line The raw instruction data to add.
   */
private void addInstruction(final CCodeNode node, final InstructionLine line) {
    final CInstruction instruction = InstructionConverter.createInstruction(line, sqlProvider);
    InstructionCache.get(sqlProvider).addInstruction(instruction);
    localCommentIdToInstruction.put(line.getLocalInstructionCommentId(), new Pair<INaviInstruction, INaviCodeNode>(instruction, node));
    globalCommentIdToInstruction.put(line.getGlobalInstructionComment(), instruction);
    localCommentIdToCodeNode.put(line.getLocalNodeCommentId(), node);
    globalCommentIdToCodeNode.put(line.getGlobalNodeCommentId(), node);
    node.addInstruction(instruction, null);
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 64 with INaviCodeNode

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

the class CCodeNodeParser method parse.

/**
   * Takes the information from the components passed into the constructor and creates a list of
   * nodes from that information.
   *
   * @return The list of nodes created by the parser.
   *
   * @throws ParserException Thrown if the instruction data could not be loaded.
   * @throws CPartialLoadException Thrown if not all necessary modules are loaded.
   */
public List<CCodeNode> parse() throws ParserException, CPartialLoadException {
    // it to point to the proper data.
    if (!dataProvider.next()) {
        return new ArrayList<CCodeNode>();
    }
    // Generate the nodes from the raw data.
    while (true) {
        if (dataProvider.isAfterLast()) {
            if (currentNode != null) {
                nodes.add(currentNode);
            }
            break;
        }
        nodes.add(extractNode(dataProvider));
    }
    final HashSet<Integer> allComments = Sets.newHashSet();
    allComments.addAll(localCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToCodeNode.keySet());
    allComments.addAll(globalCommentIdToInstruction.keySet());
    allComments.addAll(localCommentIdToInstruction.keySet());
    try {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = sqlProvider.loadMultipleCommentsById(allComments);
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            if (localCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                localCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeLocalCodeNodeComment(commentIdToComment.getValue());
            }
            if (globalCommentIdToCodeNode.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToCodeNode.get(commentIdToComment.getKey()).getComments().initializeGlobalCodeNodeComment(commentIdToComment.getValue());
            }
            if (localCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                final Pair<INaviInstruction, INaviCodeNode> instructionToCodeNode = localCommentIdToInstruction.get(commentIdToComment.getKey());
                instructionToCodeNode.second().getComments().initializeLocalInstructionComment(instructionToCodeNode.first(), commentIdToComment.getValue());
            }
            if (globalCommentIdToInstruction.containsKey(commentIdToComment.getKey())) {
                globalCommentIdToInstruction.get(commentIdToComment.getKey()).initializeGlobalComment(commentIdToComment.getValue());
            }
        }
    } catch (final CouldntLoadDataException exception) {
        throw new CPartialLoadException("Error: Comments could not be loaded.", null);
    }
    return nodes;
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CPartialLoadException(com.google.security.zynamics.binnavi.Database.Exceptions.CPartialLoadException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) ArrayList(java.util.ArrayList) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 65 with INaviCodeNode

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

the class PostgreSQLEdgeFunctions method deleteGlobalEdgeComment.

/**
   * This function deletes a global edge comment from the database.
   *
   * @param provider The provider to access the database.
   * @param edge The edge to which the comment is associated.
   * @param commentId The comment id of the comment to be deleted.
   * @param userId The user id of the currently active user.
   *
   * @throws CouldntDeleteException if the comment could not be deleted from the database.
   */
public static void deleteGlobalEdgeComment(final AbstractSQLProvider provider, final INaviEdge edge, final Integer commentId, final Integer userId) throws CouldntDeleteException {
    Preconditions.checkNotNull(provider, "IE00505: provider argument can not be null");
    Preconditions.checkNotNull(edge, "IE00506: codeNode argument can not be null");
    Preconditions.checkNotNull(commentId, "IE00507: comment argument can not be null");
    Preconditions.checkNotNull(userId, "IE00508: userId argument can not be null");
    final String function = " { ? = call delete_global_edge_comment(?, ?, ?, ?, ?, ?) } ";
    try {
        final CallableStatement deleteCommentFunction = provider.getConnection().getConnection().prepareCall(function);
        try {
            deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
            deleteCommentFunction.setInt(2, getModuleId(edge.getSource()));
            deleteCommentFunction.setInt(3, getModuleId(edge.getTarget()));
            deleteCommentFunction.setObject(4, ((INaviCodeNode) edge.getSource()).getAddress().toBigInteger(), Types.BIGINT);
            deleteCommentFunction.setObject(5, ((INaviCodeNode) edge.getTarget()).getAddress().toBigInteger(), Types.BIGINT);
            deleteCommentFunction.setInt(6, commentId);
            deleteCommentFunction.setInt(7, userId);
            deleteCommentFunction.execute();
            deleteCommentFunction.getInt(1);
            if (deleteCommentFunction.wasNull()) {
                throw new IllegalArgumentException("Error: the comment id returned from the database was null");
            }
        } finally {
            deleteCommentFunction.close();
        }
    } catch (SQLException | MaybeNullException exception) {
        throw new CouldntDeleteException(exception);
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Aggregations

INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)70 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)25 Test (org.junit.Test)23 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)21 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)18 INaviFunctionNode (com.google.security.zynamics.binnavi.disassembly.INaviFunctionNode)17 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)14 ArrayList (java.util.ArrayList)13 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)12 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)9 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)9 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)9 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)9 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)8 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)8 CodeNodeCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)6 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)5 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)5