use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CUnInlinerTest method testUninlineSingleBlockConnectNeighbors.
@Test
public void testUninlineSingleBlockConnectNeighbors() {
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 childNode1 = new CCodeNode(5, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode childNode2 = new CCodeNode(6, 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(childNode1);
nodes.add(childNode2);
final CNaviViewEdge parentEdge = new CNaviViewEdge(0, parentNode, upperNode, EdgeType.JUMP_UNCONDITIONAL, 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, childNode1, EdgeType.JUMP_CONDITIONAL_FALSE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge childEdge2 = new CNaviViewEdge(4, lowerNode, childNode2, EdgeType.JUMP_CONDITIONAL_TRUE, 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);
edges.add(childEdge2);
connect(parentNode, upperNode, parentEdge);
connect(upperNode, inlinedNode, enteringEdge);
connect(inlinedNode, lowerNode, leavingEdge);
connect(lowerNode, childNode1, childEdge1);
connect(lowerNode, childNode2, childEdge2);
final MockView view = new MockView(nodes, edges, m_provider);
CUnInliner.unInline(view, inlinedNode);
assertEquals(4, view.getNodeCount());
assertEquals(3, view.getEdgeCount());
assertEquals(EdgeType.JUMP_UNCONDITIONAL, view.getGraph().getEdges().get(0).getType());
assertEquals(EdgeType.JUMP_CONDITIONAL_FALSE, view.getGraph().getEdges().get(1).getType());
assertEquals(EdgeType.JUMP_CONDITIONAL_TRUE, view.getGraph().getEdges().get(2).getType());
final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(3);
assertEquals(2, Iterables.size(cnode.getInstructions()));
assertEquals(mi1.toString(), Iterables.get(cnode.getInstructions(), 0).toString());
assertEquals(mi3.toString(), Iterables.get(cnode.getInstructions(), 1).toString());
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class CViewInserterTest method test.
@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
ConfigManager.instance().read();
final INaviModule mockModule = new MockModule();
final MockSqlProvider mockProvider = new MockSqlProvider();
final CUserManager userManager = CUserManager.get(mockProvider);
final IUser user = userManager.addUser(" VIEW INSERTER USER ");
userManager.setCurrentActiveUser(user);
final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
view.load();
final MockFunction mockFunction = new MockFunction(mockProvider);
final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
@SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
final MockInstruction instruction1 = new MockInstruction();
final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
@SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
final CTextNode tnode1 = view.getContent().createTextNode(comments);
@SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
gnode1.appendComment("TEST GROUP NODE COMMENT 1");
final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
view2.load();
CViewInserter.insertView(view, view2);
final List<INaviViewNode> nodes = view2.getGraph().getNodes();
assertEquals(view2.getNodeCount(), 6);
assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class ZyGraphTest method testAddedEdgeCheckColor.
@Test
public void testAddedEdgeCheckColor() {
final Pair<CNaviViewEdge, com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge> p = createEdgeForAddedEdgeTests();
final CNaviViewEdge edge = p.first();
final com.google.security.zynamics.binnavi.yfileswrap.zygraph.NaviEdge cnn = p.second();
assertEquals(edge.getColor(), cnn.getRealizerLineColor());
edge.setColor(Color.GREEN);
assertEquals(Color.GREEN, edge.getColor());
assertEquals(edge.getColor(), cnn.getRealizerLineColor());
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class PostgreSQLGlobalEdgeCommentTests method appendGlobalEdgeComment4.
@Test
public void appendGlobalEdgeComment4() throws CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException, CPartialLoadException {
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final List<IComment> storedComments = edge.getGlobalComment() == null ? new ArrayList<IComment>() : edge.getGlobalComment();
final IComment lastComment = storedComments.isEmpty() ? null : Iterables.getLast(storedComments);
final String firstCommentString = " PASS GLOBAL EDGE COMMENT WITHOUT PARENT ID ";
final int firstCommentId = getProvider().appendGlobalEdgeComment(edge, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, lastComment, firstCommentString);
final String secondCommentString = " PASS GLOBAL EDGE COMMENT WITH PARENT ID ";
final int secondCommentId = getProvider().appendGlobalEdgeComment(edge, secondCommentString, user.getUserId());
final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
assertNotNull(commentsFromDatabase);
assertEquals(storedComments.size() + 2, commentsFromDatabase.size());
assertTrue(commentsFromDatabase.contains(firstComment));
assertTrue(commentsFromDatabase.contains(secondComment));
final CNaviViewEdge callgraphEdge = (CNaviViewEdge) loadCallGraphEdge(getKernel32Module());
getProvider().appendGlobalEdgeComment(callgraphEdge, " PASS GLOBAL CALLGRAPH EDGE COMMENT WITHOUT PARENT ID ", user.getUserId());
}
use of com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge in project binnavi by google.
the class View method createEdge.
// ! Creates a new edge.
/**
* Creates an edge in the view.
*
* @param source The source node of the edge.
* @param target The target node of the edge.
* @param edgeType The edge type of the edge.
*
* @return The created edge.
*/
public ViewEdge createEdge(final ViewNode source, final ViewNode target, final EdgeType edgeType) {
Preconditions.checkNotNull(source, "Error: Source argument can not be null");
Preconditions.checkNotNull(target, "Error: Target argument can not be null");
Preconditions.checkNotNull(edgeType, "Error: Edge type argument can not be null");
final CNaviViewEdge newEdge = naviView.getContent().createEdge(source.getNative(), target.getNative(), edgeType.getNative());
return cachedEdges.get(newEdge);
}
Aggregations