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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations