Search in sources :

Example 6 with INaviFunction

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

the class PostgreSQLFunctionsLoader method parseFunctionInformation.

/**
   * This function parses a {@link ResultSet result set} from a database query and generates a
   * {@link List} of {@link INaviFunction} from it.
   *
   * @param resultSet The {@link ResultSet} in which the result from the database query is stored.
   * @param provider The {@link SQLProvider} to access the database with.
   * @param module The {@link INaviModule} to which the {@link INaviFunction function(s)} are
   *        associated.
   *
   * @return A {@link List} of {@link INaviFunction functions} parsed from the {@link ResultSet
   *         resultSet}.
   *
   * @throws SQLException if the {@link ResultSet} could not be parsed.
   * @throws CouldntLoadDataException if the associated comments could not be loaded from the
   *         database.
   */
private static List<INaviFunction> parseFunctionInformation(final ResultSet resultSet, final SQLProvider provider, final INaviModule module) throws SQLException, CouldntLoadDataException {
    final List<INaviFunction> functions = Lists.newArrayList();
    final Map<Integer, INaviFunction> commentIdToFunction = new HashMap<Integer, INaviFunction>();
    try {
        while (resultSet.next()) {
            final IAddress address = PostgreSQLHelpers.loadAddress(resultSet, "address");
            final String name = resultSet.getString("name");
            final String originalName = resultSet.getString("original_name");
            Integer globalCommentId = resultSet.getInt("global_comment");
            if (resultSet.wasNull()) {
                globalCommentId = null;
            }
            final String description = resultSet.getString("description");
            final FunctionType type = FunctionType.valueOf(resultSet.getString("type").toUpperCase());
            final String parentModuleName = resultSet.getString("parent_module_name");
            final int parentModuleId = resultSet.getInt("parent_module_id");
            final IAddress parentModuleFunction = resultSet.wasNull() ? null : PostgreSQLHelpers.loadAddress(resultSet, "parent_module_function");
            final Integer nodeCount = resultSet.getInt("bbcount");
            final Integer edgeCount = resultSet.getInt("edgeCount");
            final Integer indegree = resultSet.getInt("incount");
            final Integer outdegree = resultSet.getInt("outcount");
            Integer stackFrameId = resultSet.getInt("stack_frame");
            if (resultSet.wasNull()) {
                stackFrameId = null;
            }
            Integer prototypeId = resultSet.getInt("prototype");
            if (resultSet.wasNull()) {
                prototypeId = null;
            }
            final INaviView view = ViewManager.get(provider).getView(resultSet.getInt("view_id"));
            final BaseType stackFrame = stackFrameId == null ? null : module.getTypeManager().getBaseType(stackFrameId);
            if (stackFrameId != null) {
                module.getTypeManager().setStackFrame(stackFrame);
            }
            final BaseType prototype = prototypeId == null ? null : module.getTypeManager().getBaseType(prototypeId);
            final CFunction function = new CFunction(module, view, address, name, originalName, description, indegree, outdegree, nodeCount, edgeCount, type, parentModuleName, parentModuleId, parentModuleFunction, stackFrame, prototype, provider);
            if (globalCommentId != null) {
                commentIdToFunction.put(globalCommentId, function);
            }
            functions.add(function);
        }
    } finally {
        resultSet.close();
    }
    if (!commentIdToFunction.isEmpty()) {
        final HashMap<Integer, ArrayList<IComment>> commentIdToComments = PostgreSQLCommentFunctions.loadMultipleCommentsById(provider, commentIdToFunction.keySet());
        for (final Entry<Integer, ArrayList<IComment>> commentIdToComment : commentIdToComments.entrySet()) {
            CommentManager.get(provider).initializeGlobalFunctionComment(commentIdToFunction.get(commentIdToComment.getKey()), commentIdToComment.getValue());
        }
    }
    return functions;
}
Also used : HashMap(java.util.HashMap) FunctionType(com.google.security.zynamics.zylib.disassembly.FunctionType) ArrayList(java.util.ArrayList) CFunction(com.google.security.zynamics.binnavi.disassembly.CFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction)

Example 7 with INaviFunction

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

the class CReferenceFinder method fetchReferenceMap.

/**
   * Fetch for outgoing code references of a tree node and all of its children.
   * 
   * @param node The start node of the search.
   * @param instruction The instruction the operand tree belongs to.
   * @param functions The map of code references.
   */
private static void fetchReferenceMap(final IOperandTreeNode node, final INaviInstruction instruction, final Map<INaviInstruction, INaviFunction> functions) {
    final List<IReference> references = node.getReferences();
    for (final IReference reference : references) {
        if (ReferenceType.isCodeReference(reference.getType())) {
            final IAddress target = reference.getTarget();
            final INaviFunction function = instruction.getModule().getContent().getFunctionContainer().getFunction(target);
            if (function != null) {
                functions.put(instruction, function);
            }
        }
    }
    for (final IOperandTreeNode child : node.getChildren()) {
        fetchReferenceMap(child, instruction, functions);
    }
}
Also used : IReference(com.google.security.zynamics.zylib.disassembly.IReference) IOperandTreeNode(com.google.security.zynamics.zylib.disassembly.IOperandTreeNode) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress)

Example 8 with INaviFunction

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

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

the class CGraphInliner method inlineAll.

/**
   * Inlines all function calls of a given graph.
   * 
   * @param parent Parent window used for dialogs.
   * @param container Contains the functions to be inlined.
   * @param graph Graph where the inline operation takes place.
   */
public static void inlineAll(final JFrame parent, final IViewContainer container, final ZyGraph graph) {
    Preconditions.checkNotNull(parent, "IE02285: Parent argument can not be null");
    Preconditions.checkNotNull(container, "IE02286: Container argument can not be null");
    Preconditions.checkNotNull(graph, "IE02287: Graph Argument can not be null");
    final MutableDirectedGraph<INaviViewNode, INaviEdge> mutableGraph = (MutableDirectedGraph<INaviViewNode, INaviEdge>) graph.getRawView().getGraph();
    final List<INaviViewNode> nodes = mutableGraph.getNodes();
    final HashMap<INaviInstruction, INaviFunction> instructionToFunctionMap = new HashMap<INaviInstruction, INaviFunction>();
    for (final INaviViewNode iNaviViewNode : nodes) {
        if (iNaviViewNode instanceof INaviCodeNode) {
            instructionToFunctionMap.putAll(CReferenceFinder.getCodeReferenceMap((INaviCodeNode) iNaviViewNode));
        }
    }
    for (final INaviInstruction iNaviInstruction : instructionToFunctionMap.keySet()) {
        INaviCodeNode updatedNode = null;
        for (final INaviViewNode iNaviViewNode2 : graph.getRawView().getGraph().getNodes()) {
            final INaviCodeNode codeNode = (INaviCodeNode) iNaviViewNode2;
            if (codeNode.hasInstruction(iNaviInstruction)) {
                updatedNode = codeNode;
            }
        }
        if (updatedNode != null) {
            inlineFunctionSilently(parent, container, graph, updatedNode, iNaviInstruction, instructionToFunctionMap.get(iNaviInstruction));
        } else {
            throw new IllegalStateException("IE01174: Graph final has been rendered final to an final inconsitant state");
        }
    }
}
Also used : INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) HashMap(java.util.HashMap) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) MutableDirectedGraph(com.google.security.zynamics.zylib.types.graphs.MutableDirectedGraph) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction)

Example 10 with INaviFunction

use of com.google.security.zynamics.binnavi.disassembly.INaviFunction 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)

Aggregations

INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)94 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)39 Test (org.junit.Test)38 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)26 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)20 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)16 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)16 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)14 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)14 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)12 ArrayList (java.util.ArrayList)12 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)11 MockView (com.google.security.zynamics.binnavi.disassembly.MockView)10 CCodeNode (com.google.security.zynamics.binnavi.disassembly.CCodeNode)9 FilledList (com.google.security.zynamics.zylib.types.lists.FilledList)9 HashMap (java.util.HashMap)9 CFunctionNode (com.google.security.zynamics.binnavi.disassembly.CFunctionNode)8 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 INaviEdge (com.google.security.zynamics.binnavi.disassembly.INaviEdge)8