Search in sources :

Example 11 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class PluginLoader method loadPluginFiles.

/**
 * Loads all plugin files of a given directory.
 *
 * @param pluginPath The path to the plugins directory.
 * @param pluginFiles The plugin files to load.
 * @param descriptionUpdater Receives updates about the load progress. This argument can be null.
 *
 * @return The result of the load process.
 */
private static <T> LoadResult<T> loadPluginFiles(final String pluginPath, final Set<File> pluginFiles, final IStandardDescriptionUpdater descriptionUpdater) {
    final ArrayList<Pair<com.google.security.zynamics.binnavi.api2.plugins.IPlugin<T>, PluginStatus>> loadedPlugins = new ArrayList<>();
    final ArrayList<Pair<String, Throwable>> failedPlugins = new ArrayList<>();
    for (final File pluginFile : pluginFiles) {
        if (pluginFile.getName().endsWith(".jar")) {
            descriptionUpdater.next();
            descriptionUpdater.setDescription(String.format("Loading plugin JAR file '%s'", pluginFile.getName()));
            JarPluginLoader.processJarFile(pluginFile, loadedPlugins, failedPlugins);
        } else if (pluginFile.getName().endsWith(".class")) {
            descriptionUpdater.next();
            descriptionUpdater.setDescription(String.format("Loading plugin CLASS file '%s'", pluginFile.getName()));
            ClassPluginLoader.processClassFile(pluginPath, pluginFile, loadedPlugins, failedPlugins);
        }
    }
    return new LoadResult<T>(loadedPlugins, failedPlugins);
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 12 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class ZyEdgeBuilder method convertEdge.

/**
 * Creates a graph node from a raw edge.
 *
 * @param edge The raw edge that provides the underlying data.
 * @param sourceNode Source node of the edge.
 * @param targetNode Target node of the edge.
 * @param graph2D The graph object where the edge is created.
 * @param adjustColors Flag that indicates whether the initial color of all edges should be
 *        recalculated according to their type.
 *
 * @return The created YNode/NaviNode pair.
 */
public static Pair<Edge, NaviEdge> convertEdge(final INaviEdge edge, final NaviNode sourceNode, final NaviNode targetNode, final Graph2D graph2D, final boolean adjustColors) {
    // Build the edge label if necessary
    final ZyLabelContent content = ZyEdgeBuilder.buildContent(edge);
    // Create the edge realizer of the new edge
    final ZyEdgeRealizer<NaviEdge> realizer = new ZyEdgeRealizer<NaviEdge>(content, new CEdgeUpdater(edge));
    // Create the edge
    final Edge g2dEdge = graph2D.createEdge(sourceNode.getNode(), targetNode.getNode(), realizer);
    if (adjustColors) {
        EdgeInitializer.adjustColor(edge);
    }
    EdgeInitializer.initializeEdgeType(edge, realizer);
    graph2D.getRealizer(g2dEdge).setLineColor(edge.getColor());
    // Associate user data with the edge
    final NaviEdge zyEdge = new NaviEdge(sourceNode, targetNode, g2dEdge, realizer, edge);
    NaviNode.link(sourceNode, targetNode);
    final ZyEdgeData<NaviEdge> data = new ZyEdgeData<NaviEdge>(zyEdge);
    realizer.setUserData(data);
    return new Pair<Edge, NaviEdge>(g2dEdge, zyEdge);
}
Also used : ZyEdgeRealizer(com.google.security.zynamics.zylib.yfileswrap.gui.zygraph.realizers.ZyEdgeRealizer) ZyLabelContent(com.google.security.zynamics.zylib.gui.zygraph.realizers.ZyLabelContent) CEdgeUpdater(com.google.security.zynamics.binnavi.ZyGraph.Updaters.CEdgeUpdater) ZyEdgeData(com.google.security.zynamics.zylib.gui.zygraph.edges.ZyEdgeData) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) Edge(y.base.Edge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) NaviEdge(com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge) INaviEdge(com.google.security.zynamics.binnavi.disassembly.INaviEdge) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 13 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class MonoReilSolverResult method generateAddressToStateMapping.

/**
 * Collect lattice results and generate a map which associates a lattice result with each address.
 *
 * @param startInstruction The instruction where collecting the results is started.
 * @param trackIncoming Flag whether to start collecting immediately before or after the start
 *        instruction.
 *
 * @return The map which associates addresses with lattice results.
 */
@Override
public Map<IAddress, LatticeElementType> generateAddressToStateMapping(final IInstruction startInstruction, final boolean trackIncoming) {
    final Map<IAddress, LatticeElementType> addressToLatticeElementMap = new TreeMap<>();
    final Iterator<Pair<IInstructionGraphEdge, LatticeElementType>> iter = resultIterator();
    while (iter.hasNext()) {
        final Pair<IInstructionGraphEdge, LatticeElementType> edgeToLatticeElement = iter.next();
        if (edgeToLatticeElement.first().isInstructionExit()) {
            IAddress address;
            if (hasResult(edgeToLatticeElement.first())) {
                if (direction == AnalysisDirection.DOWN) {
                    address = graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress();
                } else {
                    address = graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress();
                }
                if (addressToLatticeElementMap.containsKey(address)) {
                    final ArrayList<LatticeElementType> combinelist = new ArrayList<>();
                    combinelist.add(edgeToLatticeElement.second());
                    combinelist.add(addressToLatticeElementMap.get(address));
                    addressToLatticeElementMap.put(address, lattice.combine(combinelist));
                } else {
                    addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
                }
            } else if (ReilHelpers.toNativeAddress(graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress()).equals(startInstruction.getAddress()) && (direction == AnalysisDirection.DOWN) && !trackIncoming) {
                address = graph.getSource(edgeToLatticeElement.first()).getReilInstruction().getAddress();
                addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
            } else if (ReilHelpers.toNativeAddress(graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress()).equals(startInstruction.getAddress()) && (direction == AnalysisDirection.UP) && trackIncoming) {
                address = graph.getDestination(edgeToLatticeElement.first()).getReilInstruction().getAddress();
                addressToLatticeElementMap.put(address, edgeToLatticeElement.second());
            }
        }
    }
    return addressToLatticeElementMap;
}
Also used : IInstructionGraphEdge(com.google.security.zynamics.reil.algorithms.mono2.common.instructiongraph.interfaces.IInstructionGraphEdge) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 14 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class OperandGraph method createInitialMap.

private static Map<ReilBlock, Pair<List<OperandGraphNode>, List<OperandGraphEdge>>> createInitialMap(final ReilGraph graph) {
    final Map<ReilBlock, Pair<List<OperandGraphNode>, List<OperandGraphEdge>>> graphMap = new HashMap<ReilBlock, Pair<List<OperandGraphNode>, List<OperandGraphEdge>>>();
    for (final ReilBlock block : graph) {
        final List<OperandGraphNode> nodes = new ArrayList<OperandGraphNode>();
        final List<OperandGraphEdge> edges = new ArrayList<OperandGraphEdge>();
        graphMap.put(block, new Pair<List<OperandGraphNode>, List<OperandGraphEdge>>(nodes, edges));
        final Map<String, OperandGraphNode> defines = new HashMap<String, OperandGraphNode>();
        for (final ReilInstruction instruction : block) {
            final Integer mnemonic = instruction.getMnemonicCode();
            OperandGraphNode firstNode = null;
            OperandGraphNode secondNode = null;
            if (ReilHelpers.usesFirstOperand(mnemonic)) {
                firstNode = create(instruction, 0, nodes, edges, defines);
            }
            if (ReilHelpers.usesSecondOperand(mnemonic)) {
                secondNode = create(instruction, 1, nodes, edges, defines);
            }
            if (ReilHelpers.writesThirdOperand(mnemonic)) {
                final OperandGraphNode node = new OperandGraphNode(instruction, 2);
                nodes.add(node);
                defines.put(instruction.getThirdOperand().getValue(), node);
                if (firstNode != null) {
                    final OperandGraphEdge edge = new OperandGraphEdge(firstNode, node);
                    edges.add(edge);
                    OperandGraphNode.link(firstNode, node);
                }
                if (secondNode != null) {
                    final OperandGraphEdge edge = new OperandGraphEdge(secondNode, node);
                    edges.add(edge);
                    OperandGraphNode.link(secondNode, node);
                }
            }
        }
    }
    return graphMap;
}
Also used : ReilInstruction(com.google.security.zynamics.reil.ReilInstruction) HashMap(java.util.HashMap) ReilBlock(com.google.security.zynamics.reil.ReilBlock) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.google.security.zynamics.zylib.general.Pair)

Example 15 with Pair

use of com.google.security.zynamics.zylib.general.Pair in project binnavi by google.

the class PostgreSQLCallgraphLoader method loadNodes.

/**
 * Loads the nodes of a call graph.
 *
 * @param connection Connection to the database.
 * @param callgraphId ID of the call graph view to load.
 * @param functions List of functions in the module whose call graph is loaded.
 *
 * @return <Call graph nodes, Call graph node IDs => Call graph nodes>
 *
 * @throws SQLException Thrown if loading the nodes failed.
 */
private static Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>> loadNodes(final CConnection connection, final int callgraphId, final Collection<INaviFunction> functions) throws SQLException {
    // TODO: Simplify the return value of this method.
    // For performance reasons, we need a quick way to look up functions by their address.
    final Map<IAddress, INaviFunction> functionMap = getFunctionMap(functions);
    final List<ICallgraphNode> nodes = new ArrayList<ICallgraphNode>();
    final String nodeQuery = "SELECT nodes.id, function FROM " + CTableNames.NODES_TABLE + " AS nodes JOIN " + CTableNames.FUNCTION_NODES_TABLE + " AS function_nodes ON nodes.id = function_nodes.node_id WHERE nodes.view_id = " + callgraphId;
    final ResultSet nodeResult = connection.executeQuery(nodeQuery, true);
    final HashMap<Integer, CCallgraphNode> nodeMap = new HashMap<Integer, CCallgraphNode>();
    try {
        while (nodeResult.next()) {
            final int nodeId = nodeResult.getInt("id");
            final IAddress functionAddress = PostgreSQLHelpers.loadAddress(nodeResult, "function");
            final INaviFunction function = functionMap.get(functionAddress);
            final CCallgraphNode cgnode = new CCallgraphNode(function);
            nodeMap.put(nodeId, cgnode);
            nodes.add(cgnode);
        }
    } finally {
        nodeResult.close();
    }
    return new Pair<List<ICallgraphNode>, Map<Integer, CCallgraphNode>>(nodes, nodeMap);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CCallgraphNode(com.google.security.zynamics.binnavi.disassembly.CCallgraphNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) ICallgraphNode(com.google.security.zynamics.binnavi.disassembly.ICallgraphNode) ResultSet(java.sql.ResultSet) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Pair(com.google.security.zynamics.zylib.general.Pair)

Aggregations

Pair (com.google.security.zynamics.zylib.general.Pair)55 ArrayList (java.util.ArrayList)26 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)7 RelocatedAddress (com.google.security.zynamics.binnavi.disassembly.RelocatedAddress)7 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)6 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)6 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)6 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)6 IDebugger (com.google.security.zynamics.binnavi.debug.debugger.interfaces.IDebugger)4 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)4 Test (org.junit.Test)4 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)3 Breakpoint (com.google.security.zynamics.binnavi.debug.models.breakpoints.Breakpoint)3 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)3 MemoryModule (com.google.security.zynamics.binnavi.debug.models.processmanager.MemoryModule)3 INaviCodeNode (com.google.security.zynamics.binnavi.disassembly.INaviCodeNode)3 ReilBlock (com.google.security.zynamics.reil.ReilBlock)3 ReilInstruction (com.google.security.zynamics.reil.ReilInstruction)3 BigInteger (java.math.BigInteger)3 HashSet (java.util.HashSet)3