use of com.google.security.zynamics.binnavi.disassembly.MockFunction in project binnavi by google.
the class CCodeNodeParserTest method testSameOperandTwice.
@Test
public void testSameOperandTwice() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: jz eax
// 00000001: jg eax
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1 = new MockCodeNodeData();
instruction1.nodeId = 0;
instruction1.expressionId = 0;
instruction1.expressionType = 5;
instruction1.operandPosition = 0;
instruction1.symbol = "eax";
final MockCodeNodeData instruction2 = new MockCodeNodeData();
instruction2.address = new CAddress(BigInteger.ONE);
instruction2.nodeId = 1;
instruction2.expressionId = 0;
instruction2.expressionType = 5;
instruction2.operandPosition = 0;
instruction2.symbol = "eax";
cnProvider.data.add(instruction1);
cnProvider.data.add(instruction2);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(2, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
assertEquals(1, Iterables.size(result.get(1).getInstructions()));
}
use of com.google.security.zynamics.binnavi.disassembly.MockFunction in project binnavi by google.
the class CCodeNodeParserTest method testSingleInstruction.
@Test
public void testSingleInstruction() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// nop
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
cnProvider.data.add(new MockCodeNodeData());
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
}
use of com.google.security.zynamics.binnavi.disassembly.MockFunction in project binnavi by google.
the class CCodeNodeParserTest method testMultipleOperands.
@Test
public void testMultipleOperands() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: mov eax, ebx
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1a = new MockCodeNodeData();
instruction1a.mnemonic = "mov";
instruction1a.nodeId = 0;
instruction1a.expressionId = 0;
instruction1a.expressionType = 5;
instruction1a.operandPosition = 0;
instruction1a.symbol = "eax";
final MockCodeNodeData instruction1b = new MockCodeNodeData();
instruction1b.mnemonic = "mov";
instruction1b.nodeId = 0;
instruction1b.expressionId = 1;
instruction1b.expressionType = 5;
instruction1b.operandPosition = 1;
instruction1b.symbol = "ebx";
cnProvider.data.add(instruction1a);
cnProvider.data.add(instruction1b);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
final INaviInstruction instruction = Iterables.getFirst(result.get(0).getInstructions(), null);
assertEquals("mov", instruction.getMnemonic());
assertEquals("dword", instruction.getOperands().get(0).getRootNode().getValue());
assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
assertEquals("dword", instruction.getOperands().get(1).getRootNode().getValue());
assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
}
use of com.google.security.zynamics.binnavi.disassembly.MockFunction in project binnavi by google.
the class CCodeNodeParserTest method testReference.
@Test
public void testReference() throws ParserException, CPartialLoadException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
// 00000000: jz 123
final MockCodeNodeProvider cnProvider = new MockCodeNodeProvider();
final MockCodeNodeData instruction1 = new MockCodeNodeData();
instruction1.reference = new CReference(new CAddress(BigInteger.valueOf(123)), ReferenceType.CONDITIONAL_TRUE);
instruction1.nodeId = 0;
instruction1.expressionId = 0;
instruction1.expressionType = 2;
instruction1.operandPosition = 0;
instruction1.immediate = "123";
cnProvider.data.add(instruction1);
final MockSqlProvider provider = new MockSqlProvider();
final MockModule module = new MockModule();
CFunctionContainerHelper.addFunction(module.getContent().getFunctionContainer(), new MockFunction(0));
final CCodeNodeParser p = new CCodeNodeParser(cnProvider, Lists.newArrayList(module), provider);
final List<CCodeNode> result = p.parse();
assertEquals(1, result.size());
assertEquals(1, Iterables.size(result.get(0).getInstructions()));
}
use of com.google.security.zynamics.binnavi.disassembly.MockFunction 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());
}
Aggregations