use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class ZyFunctionNodeBuilder method buildNameLine.
/**
* Builds the name line of a function node.
*
* @param node The function node which provides the raw data.
* @param content The node content object where the name line is added.
* @param showFunctionInformation True, to show function information in the node. False, to hide
* it.
*/
private static void buildNameLine(final INaviFunctionNode node, final ZyLabelContent content, final boolean showFunctionInformation) {
final INaviFunction function = node.getFunction();
String informationString = "";
if (function.getBasicBlockCount() > 0) {
final StringBuilder builder = new StringBuilder();
builder.append(" (");
builder.append(function.getBasicBlockCount());
builder.append(" basic block");
if (function.getBasicBlockCount() > 1) {
builder.append('s');
}
if (function.getEdgeCount() > 0) {
builder.append(", ");
builder.append(function.getEdgeCount());
builder.append(" edge");
if (function.getEdgeCount() > 1) {
builder.append('s');
}
}
builder.append(')');
informationString = builder.toString();
}
final ZyLineContent nameLine = new ZyLineContent(function.getName() + informationString, NORMAL_FONT, null);
content.addLineContent(nameLine);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CNodeFunctions method splitAfter.
/**
* Splits a node.
*
* @param view View the node belongs to.
* @param originalNode Node to split.
* @param instruction Instruction after which the node is split.
*/
public static void splitAfter(final INaviView view, final INaviCodeNode originalNode, final INaviInstruction instruction) {
final Iterable<INaviInstruction> oldInstructions = originalNode.getInstructions();
if (instruction == Iterables.getLast(oldInstructions)) {
return;
}
// Step I: Find out what instructions belong to the new upper block and what
// instructions belong to the new lower block.
final List<INaviInstruction> upperInstructions = new ArrayList<INaviInstruction>();
final List<INaviInstruction> lowerInstructions = new ArrayList<INaviInstruction>();
List<INaviInstruction> currentInstructions = upperInstructions;
for (final INaviInstruction oldInstruction : oldInstructions) {
currentInstructions.add(oldInstruction);
if (oldInstruction == instruction) {
currentInstructions = lowerInstructions;
}
}
// Step II: Create the two new code nodes.
INaviFunction parentFunction = null;
try {
parentFunction = originalNode.getParentFunction();
} catch (final MaybeNullException e) {
// No parent function
}
final INaviCodeNode newNode1 = view.getContent().createCodeNode(parentFunction, upperInstructions);
final INaviCodeNode newNode2 = view.getContent().createCodeNode(parentFunction, lowerInstructions);
newNode1.setColor(originalNode.getColor());
newNode1.setBorderColor(originalNode.getBorderColor());
newNode2.setColor(originalNode.getColor());
// Step III: Transfer node comments and instruction comments from the old node
// to the new nodes.
transferLocalCodeNodeComments(originalNode, newNode1, newNode2);
// Step IV: Connect the two new nodes.
view.getContent().createEdge(newNode1, newNode2, EdgeType.JUMP_UNCONDITIONAL);
for (final INaviEdge incomingEdge : originalNode.getIncomingEdges()) {
view.getContent().createEdge(incomingEdge.getSource(), newNode1, incomingEdge.getType());
}
for (final INaviEdge outgoingEdge : originalNode.getOutgoingEdges()) {
view.getContent().createEdge(newNode2, outgoingEdge.getTarget(), outgoingEdge.getType());
}
// Step VI: Get rid of the old node.
view.getContent().deleteNode(originalNode);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class CMenuBuilder method addSelectionMenus.
/**
* Adds menus related to node selection to a given node context menu.
*
* @param menu The node context menu to extend.
* @param graph The graph the clicked node belongs to.
* @param node The clicked node.
*/
public static void addSelectionMenus(final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
final JMenu selectionMenu = new JMenu("Selection");
selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
if (graph.getSelectedNodes().size() > 0) {
selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
}
if (node.getRawNode() instanceof INaviCodeNode) {
try {
final INaviFunction parentFunction = ((INaviCodeNode) node.getRawNode()).getParentFunction();
selectionMenu.add(CActionProxy.proxy(new CActionSelectSameParentFunction(graph, parentFunction)));
} catch (final MaybeNullException exception) {
// Obviously we can not select nodes of the same parent function if there
// is no parent function.
}
} else if (node.getRawNode() instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
selectionMenu.add(CActionProxy.proxy(new CActionSelectSameFunctionType(graph, function.getType())));
}
menu.add(selectionMenu);
menu.addSeparator();
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class ViewNodeTest method setUp.
@Before
public void setUp() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, FileReadException {
ConfigManager.instance().read();
final MockSqlProvider provider = new MockSqlProvider();
final Database database = new Database(new MockDatabase());
final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), CommonTestObjects.MD5, CommonTestObjects.SHA1, 55, 66, new CAddress(0x555), new CAddress(0x666), new DebuggerTemplate(1, "Mock Debugger", "localhaus", 88, provider), null, Integer.MAX_VALUE, false, provider);
internalModule.load();
final CTagManager mockTagManager = new CTagManager(new Tree<CTag>(new TreeNode<CTag>(new CTag(1, "Root", "", TagType.NODE_TAG, provider))), TagType.NODE_TAG, provider);
m_nodeTagManager = new TagManager(mockTagManager);
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final CFunction parentFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final Function function = new Function(ModuleFactory.get(), parentFunction);
final Module module = new Module(database, internalModule, m_nodeTagManager, viewTagManager) {
@Override
public Function getFunction(final INaviFunction internalFunction) {
return function;
}
@Override
public boolean isLoaded() {
return true;
}
};
final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "", "", "", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final ITreeNode<CTag> tag = mockTagManager.addTag(mockTagManager.getRootTag(), "Initial Tag");
m_initialTag = m_nodeTagManager.getRootTags().get(0);
final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
final CFunctionNode node = internalView.getContent().createFunctionNode(internalFunction);
node.setColor(Color.MAGENTA);
node.setX(10);
node.setY(20);
node.tagNode(tag.getObject());
m_view = module.getViews().get(2);
m_node = (FunctionNode) m_view.getGraph().getNodes().get(0);
final CFunctionNode node2 = internalView.getContent().createFunctionNode(internalFunction);
internalView.getContent().createEdge(node, node2, EdgeType.INTER_MODULE);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviFunction in project binnavi by google.
the class FunctionNodeTest method testSetComment.
@Test
public void testSetComment() throws CouldntLoadDataException, CouldntLoadDataException, com.google.security.zynamics.binnavi.API.disassembly.CouldntLoadDataException, LoadCancelledException {
final MockSqlProvider provider = new MockSqlProvider();
final Database database = new Database(new MockDatabase());
final CModule internalModule = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, provider);
internalModule.load();
final CFunction internalFunction = new CFunction(internalModule, new MockView(), new CAddress(0x123), "Mock Function", "Mock Function", "Mock Description", 0, 0, 0, 0, FunctionType.NORMAL, "", 0, null, null, null, provider);
final CView internalView = internalModule.getContent().getViewContainer().createView("", "");
@SuppressWarnings("unused") final CFunctionNode internalFunctionNode = internalView.getContent().createFunctionNode(internalFunction);
final TagManager nodeTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.NODE_TAG));
final TagManager viewTagManager = new TagManager(new MockTagManager(com.google.security.zynamics.binnavi.Tagging.TagType.VIEW_TAG));
final Function function = new Function(ModuleFactory.get(), internalFunction);
final Module module = new Module(database, internalModule, nodeTagManager, viewTagManager) {
@Override
public Function getFunction(final INaviFunction internalFunction) {
return function;
}
@Override
public boolean isLoaded() {
return true;
}
};
module.load();
final View view = module.getViews().get(2);
final FunctionNode node = (FunctionNode) view.getGraph().getNodes().get(0);
final MockFunctionNodeListener listener = new MockFunctionNodeListener();
node.addListener(listener);
final ArrayList<IComment> comment = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Fark"));
node.initializeComment(comment);
assertEquals("initializedComment;", listener.events);
assertEquals(comment, node.getComment());
node.removeListener(listener);
}
Aggregations