use of com.google.security.zynamics.zylib.types.lists.FilledList 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.zylib.types.lists.FilledList in project binnavi by google.
the class PushfTranslatorTest method testPushL08.
@Test
public void testPushL08() throws InternalTranslationException, InterpreterException {
interpreter.setRegister("esp", BigInteger.valueOf(0x2000), OperandSize.DWORD, ReilRegisterStatus.DEFINED);
interpreter.setRegister("CF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
interpreter.setRegister("PF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
interpreter.setRegister("AF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
interpreter.setRegister("ZF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
interpreter.setRegister("SF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
interpreter.setRegister("OF", BigInteger.valueOf(1), OperandSize.BYTE, ReilRegisterStatus.DEFINED);
final List<MockOperandTree> operands = new FilledList<MockOperandTree>();
final IInstruction instruction = new MockInstruction("pushf", operands);
translator.translate(environment, instruction, instructions);
interpreter.interpret(TestHelpers.createMapping(instructions), BigInteger.valueOf(0x100));
assertEquals(BigInteger.valueOf(0x1FFC), interpreter.getVariableValue("esp"));
assertEquals(BigInteger.valueOf(4L), BigInteger.valueOf(interpreter.getMemorySize()));
assertEquals(0x8D7, interpreter.readMemoryWord(0x1FFC));
assertEquals(8, TestHelpers.filterNativeRegisters(interpreter.getDefinedRegisters()).size());
}
use of com.google.security.zynamics.zylib.types.lists.FilledList in project binnavi by google.
the class CProjectContainerTest method testGetViewsWithAddresses.
@Test
public void testGetViewsWithAddresses() throws CouldntLoadDataException {
final CProjectContainer container = new CProjectContainer(m_database, m_project);
@SuppressWarnings("unused") final INaviView view = container.createView("view1", "information");
final UnrelocatedAddress address = new UnrelocatedAddress(new MockAddress());
final IFilledList<UnrelocatedAddress> addresses = new FilledList<UnrelocatedAddress>();
addresses.add(address);
try {
container.getViewsWithAddresses(null, true);
fail();
} catch (final NullPointerException e) {
}
// assertNull(container.getViewsWithAddresses(addresses, true));
}
use of com.google.security.zynamics.zylib.types.lists.FilledList in project binnavi by google.
the class CBreakpointFunctionsTest method test6removeFunctions.
@Test
public void test6removeFunctions() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
final MockFunction mockFunction = new MockFunction();
final INaviModule mockModule = mockFunction.getModule();
CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), mockFunction);
final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234)))));
@SuppressWarnings("unused") final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234))));
debuggerProvider.addDebugger(debugger);
final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
assertEquals(1, tableModel.getRowCount());
final IFilledList<Pair<IDebugger, INaviFunction>> targets = new FilledList<Pair<IDebugger, INaviFunction>>();
final Pair<IDebugger, INaviFunction> targetPair = new Pair<IDebugger, INaviFunction>(debugger, mockFunction);
targets.add(targetPair);
assertEquals(1, targets.size());
CBreakpointRemoveFunctions.removeBreakpoints(targets);
@SuppressWarnings("unused") final BreakpointManager manager = debugger.getBreakpointManager();
assertEquals(0, tableModel.getRowCount());
}
use of com.google.security.zynamics.zylib.types.lists.FilledList in project binnavi by google.
the class CBreakpointFunctionsTest method test7setBreakpoints.
@Test
public void test7setBreakpoints() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
final MockFunction mockFunction = new MockFunction();
final INaviModule mockModule = mockFunction.getModule();
CFunctionContainerHelper.addFunction(mockModule.getContent().getFunctionContainer(), mockFunction);
final DebugTargetSettings target = new ModuleTargetSettings(mockModule);
final DebuggerProvider debuggerProvider = new DebuggerProvider(target);
final MockDebugger debugger = new MockDebugger(new ModuleTargetSettings(mockModule));
debugger.getBreakpointManager().addBreakpoints(BreakpointType.REGULAR, Sets.newHashSet(new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234)))));
@SuppressWarnings("unused") final Breakpoint breakPoint = debugger.getBreakpointManager().getBreakpoint(BreakpointType.REGULAR, new BreakpointAddress(mockModule, new UnrelocatedAddress(new CAddress(0x1234))));
// CBreakpointAddress address = new CBreakpointAddress(mockModule, new CUnrelocatedAddress(new
// CAddress(0x2c9)));
debuggerProvider.addDebugger(debugger);
final CBreakpointTableModel tableModel = new CBreakpointTableModel(debuggerProvider);
assertEquals(1, tableModel.getRowCount());
final IFilledList<Pair<IDebugger, INaviFunction>> targets = new FilledList<Pair<IDebugger, INaviFunction>>();
final Pair<IDebugger, INaviFunction> targetPair = new Pair<IDebugger, INaviFunction>(debugger, mockFunction);
targets.add(targetPair);
CBreakpointRemoveFunctions.removeBreakpoints(targets);
assertEquals(0, tableModel.getRowCount());
CBreakpointSetFunctions.setBreakpoints(targets);
assertEquals(1, tableModel.getRowCount());
}
Aggregations