use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLEdgeSaver method writeEdges.
/**
* Writes the edges of a view to the database.
*
* @param provider The SQL provider that provides the connection.
* @param edges The edges to write to the database.
*
* @throws SQLException Thrown if the edges could not be saved.
*/
public static void writeEdges(final SQLProvider provider, final List<INaviEdge> edges) throws SQLException {
Preconditions.checkNotNull(provider, "IE02253: Provider argument can not be null");
Preconditions.checkNotNull(edges, "IE02254: Edges argument can not be null");
for (final INaviEdge edge : edges) {
Preconditions.checkArgument(edge.inSameDatabase(provider), "IE02255: Edge list contains an edge that is not part of this database");
}
if (edges.isEmpty()) {
return;
}
final CConnection connection = provider.getConnection();
fillEdgesTable(connection, edges);
fillEdgepathsTable(connection, edges);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class PostgreSQLEdgeSaver method fillEdgepathsTable.
/**
* Writes the data from the edge objects to the edge paths table.
*
* @param connection Connection to a database.
* @param edges The edges to write.
*
* @throws SQLException Thrown if storing the edge paths failed.
*/
protected static void fillEdgepathsTable(final CConnection connection, final List<INaviEdge> edges) throws SQLException {
final String query = "INSERT INTO " + CTableNames.EDGE_PATHS_TABLE + "(edge_id, position, x, y) VALUES (?, ?, ?, ?)";
final PreparedStatement preparedStatement = connection.getConnection().prepareStatement(query);
try {
for (final INaviEdge edge : edges) {
for (final CBend bend : edge.getBends()) {
preparedStatement.setInt(1, edge.getId());
preparedStatement.setInt(2, edge.getBends().indexOf(bend));
preparedStatement.setDouble(3, bend.getX());
preparedStatement.setDouble(4, bend.getY());
preparedStatement.addBatch();
}
}
preparedStatement.executeBatch();
} catch (final SQLException exception) {
CUtilityFunctions.logException(exception);
CUtilityFunctions.logException(exception.getNextException());
} finally {
preparedStatement.close();
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CNodeDeleter method connectParentsWithChildren.
/**
* Creates edges to connect the parents of a node with its children.
*
* @param view The view where the edges are created.
* @param node The node at the center of edge creation.
*/
private static void connectParentsWithChildren(final INaviView view, final INaviViewNode node) {
final List<INaviEdge> incomingEdges = node.getIncomingEdges();
final List<? extends INaviViewNode> children = node.getChildren();
for (final INaviEdge incomingEdge : incomingEdges) {
if (incomingEdge.getSource() == node) {
continue;
}
for (final INaviViewNode child : children) {
if (child == node) {
continue;
}
// Avoid duplicate edges
if (!hasEdge(incomingEdge.getSource(), child, incomingEdge.getType())) {
view.getContent().createEdge(incomingEdge.getSource(), child, incomingEdge.getType());
}
}
}
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CUnInlinerTest method testOneBlock.
@Test
public void testOneBlock() {
final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
final List<INaviEdge> edges = new FilledList<INaviEdge>();
final INaviFunction mockFunction = new MockFunction();
final CCodeNode node = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
nodes.add(node);
final MockView view = new MockView(nodes, edges, m_provider);
CUnInliner.unInline(view, node);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviEdge in project binnavi by google.
the class CUnInlinerTest method testUninlineSingleBlockNested.
@Test
public void testUninlineSingleBlockNested() {
final List<INaviViewNode> nodes = new FilledList<INaviViewNode>();
final List<INaviEdge> edges = new FilledList<INaviEdge>();
final INaviFunction mockFunction = new MockFunction(m_provider);
final INaviFunction mockFunction2 = new MockFunction(m_provider);
final MockInstruction mi1 = new MockInstruction(0x123);
final MockInstruction mi2 = new MockInstruction(0x124);
final MockInstruction mi3 = new MockInstruction(0x125);
final CCodeNode parentNode = new CCodeNode(1, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode upperNode = new CCodeNode(2, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode inlinedNode = new CCodeNode(3, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
final CCodeNode lowerNode = new CCodeNode(4, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode childNode = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
upperNode.addInstruction(mi1, null);
inlinedNode.addInstruction(mi2, null);
lowerNode.addInstruction(mi3, null);
nodes.add(parentNode);
nodes.add(upperNode);
nodes.add(inlinedNode);
nodes.add(lowerNode);
nodes.add(childNode);
final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge enteringEdge = new CNaviViewEdge(1, upperNode, inlinedNode, EdgeType.ENTER_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge leavingEdge = new CNaviViewEdge(2, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge childEdge1 = new CNaviViewEdge(3, lowerNode, childNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
edges.add(parentEdge);
edges.add(enteringEdge);
edges.add(leavingEdge);
edges.add(childEdge1);
connect(parentNode, upperNode, parentEdge);
connect(upperNode, inlinedNode, enteringEdge);
connect(inlinedNode, lowerNode, leavingEdge);
connect(lowerNode, childNode, childEdge1);
final MockView view = new MockView(nodes, edges, m_provider);
CUnInliner.unInline(view, inlinedNode);
assertEquals(3, view.getNodeCount());
assertEquals(2, view.getEdgeCount());
assertEquals(EdgeType.ENTER_INLINED_FUNCTION, view.getGraph().getEdges().get(0).getType());
assertEquals(EdgeType.LEAVE_INLINED_FUNCTION, view.getGraph().getEdges().get(1).getType());
final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(2);
assertEquals(2, Iterables.size(cnode.getInstructions()));
assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
Aggregations