use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testAppendLocalInstructionCommentSync.
@Test
public void testAppendLocalInstructionCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(3);
final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(3);
final List<IComment> oneBefore = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
final List<IComment> twoBefore = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction()) == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
assertEquals(oneBefore, twoBefore);
databaseOnecodeNode.getComments().appendLocalInstructionComment(databaseOnecodeNode.getLastInstruction(), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL INSTRUCTION COMMENT)");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOnecodeNode.getComments().getLocalInstructionComment(databaseOnecodeNode.getLastInstruction());
final List<IComment> twoAfter = databaseTwocodeNode.getComments().getLocalInstructionComment(databaseTwocodeNode.getLastInstruction());
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class PostgreSQLNotificationProviderTest method testEditGlobalCodeNodeCommentSync.
@Test
public void testEditGlobalCodeNodeCommentSync() throws CouldntSaveDataException, CouldntLoadDataException, InterruptedException {
final INaviCodeNode databaseOnecodeNode = databaseOneView.getContent().getBasicBlocks().get(1);
final INaviCodeNode databaseTwocodeNode = databaseTwoView.getContent().getBasicBlocks().get(1);
final List<IComment> oneBefore = databaseOnecodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoBefore = databaseTwocodeNode.getComments().getGlobalCodeNodeComment() == null ? new ArrayList<IComment>() : databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertEquals(oneBefore, twoBefore);
databaseOnecodeNode.getComments().appendGlobalCodeNodeComment(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) BEFORE ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneAfter = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoAfter = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertNotNull(oneAfter);
assertNotNull(twoAfter);
assertEquals(oneBefore.size() + 1, oneAfter.size());
assertEquals(twoBefore.size() + 1, twoAfter.size());
assertEquals(oneAfter, twoAfter);
final int oneTwoSize = oneAfter.size();
final int twoTwoSize = twoAfter.size();
databaseOnecodeNode.getComments().editGlobalCodeNodeComment(Iterables.getLast(databaseOnecodeNode.getComments().getGlobalCodeNodeComment()), " TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ");
// database one to two over the PostgreSQL back end.
synchronized (lock) {
lock.await(1000, TimeUnit.MILLISECONDS);
}
final List<IComment> oneThree = databaseOnecodeNode.getComments().getGlobalCodeNodeComment();
final List<IComment> twoThree = databaseTwocodeNode.getComments().getGlobalCodeNodeComment();
assertEquals(oneTwoSize, oneThree.size());
assertEquals(twoTwoSize, twoThree.size());
assertEquals(oneThree, twoThree);
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(oneThree).getComment());
assertEquals(" TEST NOTIFICATION PROVIDER TESTS (GLOBAL CODE NODE COMMENT) AFTER ", Iterables.getLast(twoThree).getComment());
}
use of com.google.security.zynamics.binnavi.disassembly.INaviCodeNode in project binnavi by google.
the class CUnInlinerTest method testUninlineSingleBlock.
@Test
public void testUninlineSingleBlock() {
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 upperNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CCodeNode inlinedNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction2, new HashSet<CTag>(), m_provider);
final CCodeNode lowerNode = new CCodeNode(0, 0, 0, 0, 0, Color.RED, Color.RED, false, true, null, mockFunction, new HashSet<CTag>(), m_provider);
final CTextNode textNode = new CTextNode(0, 0, 0, 0, 0, Color.RED, false, true, new HashSet<CTag>(), null, m_provider);
upperNode.addInstruction(mi1, null);
inlinedNode.addInstruction(mi2, null);
lowerNode.addInstruction(mi3, null);
nodes.add(upperNode);
nodes.add(inlinedNode);
nodes.add(textNode);
nodes.add(lowerNode);
final CNaviViewEdge enteringEdge = new CNaviViewEdge(0, 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(0, inlinedNode, lowerNode, EdgeType.LEAVE_INLINED_FUNCTION, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
final CNaviViewEdge textEdge = new CNaviViewEdge(0, textNode, inlinedNode, EdgeType.TEXTNODE_EDGE, 0, 0, 0, 0, Color.BLACK, false, true, null, new FilledList<CBend>(), m_provider);
edges.add(enteringEdge);
edges.add(leavingEdge);
edges.add(textEdge);
connect(upperNode, inlinedNode, enteringEdge);
connect(inlinedNode, lowerNode, leavingEdge);
connect(textNode, inlinedNode, textEdge);
final MockView view = new MockView(nodes, edges, m_provider);
CUnInliner.unInline(view, inlinedNode);
assertEquals(1, view.getNodeCount());
assertEquals(0, view.getEdgeCount());
final INaviCodeNode cnode = (INaviCodeNode) view.getGraph().getNodes().get(0);
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.INaviCodeNode 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.INaviCodeNode in project binnavi by google.
the class PostgreSQLEdgeLoader method initializeGlobalComment.
/**
* Initializes the global comment for an edge.
*
* @param edge The edge whose global comment is initialized.
* @param globalComments The global comment to set.
*/
private static void initializeGlobalComment(final CNaviViewEdge edge, final ArrayList<IComment> globalComments, final SQLProvider provider) {
final INaviViewNode source = edge.getSource();
final INaviViewNode target = edge.getTarget();
if ((source instanceof INaviCodeNode) && (target instanceof IAddressNode)) {
CommentManager.get(provider).initializeGlobalEdgeComment(edge, globalComments);
} else if ((source instanceof INaviFunctionNode) && (target instanceof IAddressNode)) {
CommentManager.get(provider).initializeGlobalEdgeComment(edge, globalComments);
}
}
Aggregations