use of y.base.Node in project binnavi by google.
the class ZyGraphFactory method generateTestGraph.
public static ZyGraph generateTestGraph() throws FileReadException, CouldntLoadDataException, LoadCancelledException, CouldntSaveDataException {
ConfigManager.instance().read();
final MockDatabase database = new MockDatabase();
final SQLProvider provider = new MockSqlProvider();
final CModule module = new CModule(1, "", "", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
final ZyGraphViewSettings settings = new ZyGraphViewSettings(new CallGraphSettingsConfigItem());
settings.getLayoutSettings().setDefaultGraphLayout(LayoutStyle.CIRCULAR);
database.getContent().addModule(module);
final MockDatabaseManager manager = new MockDatabaseManager();
manager.addDatabase(database);
module.load();
final CView m_view = module.getContent().getViewContainer().createView("name", "description");
final LinkedHashMap<Node, NaviNode> nodeMap = new LinkedHashMap<Node, NaviNode>();
final ZyGraph2DView g2dView = new ZyGraph2DView();
final LinkedHashMap<Edge, NaviEdge> edgeMap = new LinkedHashMap<Edge, NaviEdge>();
final Node node1 = g2dView.getGraph2D().createNode();
final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode1, childNode1);
final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
COperandTreeNode.link(rootNode2, childNode2);
final COperandTree operand1 = new COperandTree(rootNode1, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operand2 = new COperandTree(rootNode2, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final ArrayList<COperandTree> operands1 = Lists.newArrayList(operand1, operand2);
final List<INaviInstruction> instructions1 = Lists.newArrayList((INaviInstruction) new MockInstruction(new CAddress(0x123456), "mov", operands1, null, module));
final INaviCodeNode rawNode1 = m_view.getContent().createCodeNode(null, instructions1);
final ZyLabelContent content = ZyCodeNodeBuilder.buildContent(rawNode1, settings, null);
nodeMap.put(node1, new NaviNode(node1, new ZyNormalNodeRealizer<NaviNode>(content), rawNode1));
final Node node2 = g2dView.getGraph2D().createNode();
final List<INaviInstruction> instructions2 = Lists.newArrayList((INaviInstruction) new MockInstruction());
final INaviCodeNode rawNode2 = m_view.getContent().createCodeNode(null, instructions2);
final ZyLabelContent content2 = ZyCodeNodeBuilder.buildContent(rawNode2, settings, null);
nodeMap.put(node2, new NaviNode(node2, new ZyNormalNodeRealizer<NaviNode>(content2), rawNode2));
rawNode2.setColor(Color.RED);
rawNode2.setVisible(false);
final CTag tag = new CTag(0, "Tag", "Description", TagType.NODE_TAG, new MockSqlProvider());
rawNode2.tagNode(tag);
final Node node3 = g2dView.getGraph2D().createNode();
final String mnemonicName = "call";
final List<COperandTree> operandTrees = new ArrayList<COperandTree>();
final int type = ExpressionType.REGISTER.ordinal();
final CReference reference = new CReference(new CAddress(0x123), ReferenceType.CALL_DIRECT);
final List<IReference> referencea = new ArrayList<IReference>();
referencea.add(reference);
final COperandTreeNode root = new COperandTreeNode(0, type, "eax", null, referencea, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
final COperandTree operandTree = new COperandTree(root, provider, module.getTypeManager(), module.getContent().getTypeInstanceContainer());
operandTrees.add(0, operandTree);
final List<INaviInstruction> instructions3 = Lists.newArrayList((INaviInstruction) new MockInstruction(mnemonicName, operandTrees, m_globalComment));
final INaviCodeNode rawNode3 = m_view.getContent().createCodeNode(null, instructions3);
final ZyLabelContent content3 = ZyCodeNodeBuilder.buildContent(rawNode3, settings, null);
nodeMap.put(node3, new NaviNode(node3, new ZyNormalNodeRealizer<NaviNode>(content3), rawNode3));
final Edge edge = g2dView.getGraph2D().createEdge(node1, node2);
final INaviEdge rawEdge = m_view.getContent().createEdge(rawNode1, rawNode2, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge, new NaviEdge(nodeMap.get(node1), nodeMap.get(node2), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge));
final Edge edge2 = g2dView.getGraph2D().createEdge(node2, node3);
final INaviEdge rawEdge2 = m_view.getContent().createEdge(rawNode2, rawNode3, EdgeType.JUMP_UNCONDITIONAL);
edgeMap.put(edge2, new NaviEdge(nodeMap.get(node2), nodeMap.get(node3), edge, new ZyEdgeRealizer<NaviEdge>(new ZyLabelContent(null), null), rawEdge2));
return new ZyGraph(m_view, nodeMap, edgeMap, settings, g2dView);
}
use of y.base.Node in project binnavi by google.
the class ProximityNodeCreator method createProximityNode.
/**
* Creates a proximity browsing node.
*
* @param graph The graph where the proximity node is added to.
* @param attachedNode The graph node the proximity node is attached to.
* @param degree The edge degree of the attached node (this is the number shown in the proximity
* node).
* @param isIncoming True, to signal that the proximity node is incoming. False, if it is
* outcoming.
*
* @param <NodeType> Raw node type of the real (e.g. not proximity nodes) nodes in the graph.
*
* @return The created proximity node.
*/
public static <NodeType extends IViewNode<?>> ZyProximityNode<?> createProximityNode(final Graph2D graph, final ZyGraphNode<?> attachedNode, final int degree, final boolean isIncoming) {
Preconditions.checkNotNull(graph, "Graph argument can not be null");
Preconditions.checkNotNull(attachedNode, "Target node argument can not be null");
final ZyLabelContent labelcontent = new ZyLabelContent(null);
labelcontent.addLineContent(new ZyLineContent(String.valueOf(degree), new Font("New Courier", Font.PLAIN, 12), null));
final ZyProximityNodeRealizer<NodeType> r = new ZyProximityNodeRealizer<NodeType>(labelcontent);
final Node node = graph.createNode(r);
@SuppressWarnings("unchecked") final ZyProximityNode<NodeType> infoNode = new ZyProximityNode<NodeType>(node, r, (ZyGraphNode<NodeType>) attachedNode, isIncoming);
final ZyNodeData<ZyProximityNode<NodeType>> data = new ZyNodeData<ZyProximityNode<NodeType>>(infoNode);
r.setUserData(data);
return infoNode;
}
use of y.base.Node in project binnavi by google.
the class TypeDependenceGraph method deleteMember.
// Deletes all member relations from the graph.
private ImmutableSet<BaseType> deleteMember(final BaseType containingType, final BaseType memberType) {
final Node containingTypeNode = containedRelationMap.get(containingType);
final Node memberTypeNode = containedRelationMap.get(memberType);
final Edge memberEdge = memberTypeNode.getEdgeTo(containingTypeNode);
containedRelation.removeEdge(memberEdge);
return determineDependentTypes(containingType);
}
use of y.base.Node in project binnavi by google.
the class TypeDependenceGraph method willCreateCycle.
/**
* Tests if adding a member of type memberType to containingType would create a cyclic type
* declaration.
*
* @param containingType The base type that contains memberType.
* @param memberType The base type of a member contained in containingType.
* @return Returns whether adding memberType to containingType would create a cyclic type
* declaration.
*/
public boolean willCreateCycle(final BaseType containingType, final BaseType memberType) {
Preconditions.checkNotNull(containingType, "Error: Containing type can not be null.");
Preconditions.checkNotNull(memberType, "Error: Member type can not be null.");
if (containingType == memberType) {
return true;
}
// 0) The pre-condition is that the existing graph is cycle free.
// 1) Contained types is the set of types that are explicitly and implicitly contained within
// the structure this member belongs to.
// 2) The intersection of this set and all types that are contained by parentType must be empty.
// TODO(jannewger): instead of creating a copy, the implementation for determining dependent
// types should be parameterizable whether to include the contained type or not.
final Set<BaseType> containedTypes = Sets.newHashSet(determineDependentTypes(containingType));
containedTypes.remove(containingType);
final Node startNode = containedRelationMap.get(memberType);
final Queue<Edge> edgesToVisit = new LinkedList<Edge>();
for (final EdgeCursor ec = startNode.inEdges(); ec.ok(); ec.next()) {
edgesToVisit.add((Edge) ec.current());
}
final Set<Node> visitednodes = new HashSet<Node>();
while (!edgesToVisit.isEmpty()) {
final Edge currentEdge = edgesToVisit.poll();
final Node nextNode = currentEdge.source();
final BaseType baseType = containedRelationMap.inverse().get(nextNode);
if (containedTypes.contains(baseType)) {
return true;
}
if (!visitednodes.contains(nextNode)) {
for (final EdgeCursor ec = nextNode.inEdges(); ec.ok(); ec.next()) {
edgesToVisit.add((Edge) ec.current());
}
}
visitednodes.add(nextNode);
}
return false;
}
use of y.base.Node in project binnavi by google.
the class TypeDependenceGraph method initializeMembers.
/**
* Initializes a set of members in the type dependence graph. This function is supposed to be used
* on database load only. The reason for this class is reduction of database load time. This is
* due to the normal mechanism of adding a member where the type system ensures consistency. On
* load time we assume that the data from the database is sane and will bail out otherwise.
*
* @param members The {@link ImmutableCollection collection} of {@link TypeMember type members} to
* add to the dependence graph.
*/
private void initializeMembers(final ImmutableCollection<TypeMember> members) {
Preconditions.checkNotNull(members, "Error: members argument can not be null.");
for (TypeMember typeMember : members) {
final Node memberTypeNode = containedRelationMap.get(typeMember.getBaseType());
final Node parentNode = containedRelationMap.get(typeMember.getParentType());
containedRelation.createEdge(memberTypeNode, parentNode);
}
if (!Cycles.findCycle(containedRelation, true).isEmpty()) {
throw new IllegalStateException("Error: Dependence graph has cycles after initialization.");
}
}
Aggregations