Search in sources :

Example 6 with IReference

use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.

the class BreakpointHelpersTest method setUp.

@Before
public void setUp() throws DebugExceptionWrapper, CouldntLoadDataException, LoadCancelledException, FileReadException {
    ConfigManager.instance().read();
    final CDatabase database = new CDatabase("", "", "", "", "", "", "", false, false);
    final Database apiDatabase = new Database(database);
    final SQLProvider mockProvider = new MockSqlProvider();
    final ITreeNode<CTag> nodeRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.NODE_TAG, mockProvider));
    final Tree<CTag> nodeTagTree = new Tree<CTag>(nodeRootNode);
    final TagManager nodeTagManager = new TagManager(new CTagManager(nodeTagTree, TagType.NODE_TAG, mockProvider));
    final ITreeNode<CTag> viewRootNode = new TreeNode<CTag>(new CTag(0, "", "", TagType.VIEW_TAG, mockProvider));
    final Tree<CTag> viewTagTree = new Tree<CTag>(viewRootNode);
    final TagManager viewTagManager = new TagManager(new CTagManager(viewTagTree, TagType.VIEW_TAG, mockProvider));
    m_module = new CModule(1, "", "", new Date(), new Date(), "00000000000000000000000000000000", "0000000000000000000000000000000000000000", 0, 0, new CAddress(0), new CAddress(0), null, null, Integer.MAX_VALUE, false, mockProvider);
    m_module.load();
    m_mockDebugger = new MockDebugger(m_moduleDebugSettings);
    m_mockDebugger.connect();
    m_debugger = new Debugger(m_mockDebugger);
    final INaviFunction parentFunction = m_module.getContent().getFunctionContainer().getFunctions().get(0);
    m_mockDebugger.setAddressTranslator(m_module, new CAddress(0), new CAddress(0x1000));
    final ViewContainer viewContainer = new Module(apiDatabase, m_module, nodeTagManager, viewTagManager);
    final INaviView naviView = new MockView(mockProvider);
    final Function apiFunction = new Function(ModuleFactory.get(), parentFunction);
    final COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, m_module.getTypeManager(), m_module.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(true, m_module, new CAddress(0x1234), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", mockProvider);
    m_view = new View(viewContainer, naviView, nodeTagManager, viewTagManager);
    m_node = m_view.createCodeNode(apiFunction, Lists.newArrayList(new Instruction(internalInstruction)));
    setM_functionNode(m_view.createFunctionNode(apiFunction));
}
Also used : MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) Instruction(com.google.security.zynamics.binnavi.API.disassembly.Instruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) ViewContainer(com.google.security.zynamics.binnavi.API.disassembly.ViewContainer) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Function(com.google.security.zynamics.binnavi.API.disassembly.Function) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) ITreeNode(com.google.security.zynamics.zylib.types.trees.ITreeNode) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) TreeNode(com.google.security.zynamics.zylib.types.trees.TreeNode) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) Database(com.google.security.zynamics.binnavi.API.disassembly.Database) IOperandTree(com.google.security.zynamics.zylib.disassembly.IOperandTree) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) Tree(com.google.security.zynamics.zylib.types.trees.Tree) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) View(com.google.security.zynamics.binnavi.API.disassembly.View) MockView(com.google.security.zynamics.binnavi.disassembly.MockView) Date(java.util.Date) MockDebugger(com.google.security.zynamics.binnavi.Debug.Debugger.MockDebugger) CDatabase(com.google.security.zynamics.binnavi.Database.CDatabase) CTagManager(com.google.security.zynamics.binnavi.Tagging.CTagManager) TagManager(com.google.security.zynamics.binnavi.API.disassembly.TagManager) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) Module(com.google.security.zynamics.binnavi.API.disassembly.Module) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) Before(org.junit.Before)

Example 7 with IReference

use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.

the class OperandTest method testConstructor.

@Test
public void testConstructor() {
    final MockModule mockModule = new MockModule();
    final COperandTreeNode rootNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode, childNode);
    final COperandTree tree = new COperandTree(rootNode, new MockSqlProvider(), mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final Operand operand = new Operand(tree);
    assertEquals("dword", operand.getRootNode().getValue());
    assertEquals(1, operand.getRootNode().getChildren().size());
    assertEquals("eax", operand.getRootNode().getChildren().get(0).getValue());
    assertEquals("eax", operand.toString());
}
Also used : MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) IReference(com.google.security.zynamics.zylib.disassembly.IReference) Test(org.junit.Test)

Example 8 with IReference

use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.

the class InstructionTest method testConstructor.

@Test
public void testConstructor() throws CouldntLoadDataException, LoadCancelledException {
    final SQLProvider provider = new MockSqlProvider();
    final CModule internalModule = new CModule(123, "Name", "Comment", new Date(), new Date(), "12345678123456781234567812345678", "1234567812345678123456781234567812345678", 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 COperandTreeNode rootNode1 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "eax", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode rootNode2 = new COperandTreeNode(1, IOperandTree.NODE_TYPE_REGISTER_ID, "ebx", null, new ArrayList<IReference>(), provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand1 = new COperandTree(rootNode1, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, provider, internalModule.getTypeManager(), internalModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands = Lists.newArrayList(operand1, operand2);
    final CInstruction internalInstruction = new CInstruction(false, internalModule, new CAddress(0x123), "mov", operands, new byte[] { 1, 2, 3 }, "x86-32", provider);
    final Instruction instruction = new Instruction(internalInstruction);
    assertEquals(0x123, instruction.getAddress().toLong());
    assertEquals(null, instruction.getComment());
    assertArrayEquals(new byte[] { 1, 2, 3 }, instruction.getData());
    assertEquals("mov", instruction.getMnemonic());
    assertEquals(2, instruction.getOperands().size());
    assertEquals("eax", instruction.getOperands().get(0).getRootNode().getChildren().get(0).getValue());
    assertEquals("ebx", instruction.getOperands().get(1).getRootNode().getChildren().get(0).getValue());
    assertEquals("123  mov eax, ebx", instruction.toString());
    assertEquals("x86-32", instruction.getArchitecture());
}
Also used : DebuggerTemplate(com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) SQLProvider(com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider) Date(java.util.Date) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) IReference(com.google.security.zynamics.zylib.disassembly.IReference) CModule(com.google.security.zynamics.binnavi.disassembly.Modules.CModule) Test(org.junit.Test)

Example 9 with IReference

use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.

the class CResultColorTest method testSecond.

@Test
public void testSecond() throws InternalTranslationException {
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final MockModule mockModule = new MockModule(mockProvider);
    // str 6, , t0
    final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_IMMEDIATE_INT_ID, "6", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode1, childNode1);
    final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode2, childNode2);
    final COperandTreeNode rootNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode3, childNode3);
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand3 = new COperandTree(rootNode3, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands1 = Lists.newArrayList(operand1, operand2, operand3);
    final INaviInstruction instruction1 = new CInstruction(false, mockModule, new CAddress(1), "str", operands1, new byte[0], "REIL", mockProvider);
    // str t0, , t1
    final COperandTreeNode rootNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode4, childNode4);
    final COperandTreeNode rootNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode5, childNode5);
    final COperandTreeNode rootNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode6, childNode6);
    final COperandTree operand4 = new COperandTree(rootNode4, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand5 = new COperandTree(rootNode5, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand6 = new COperandTree(rootNode6, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands2 = Lists.newArrayList(operand4, operand5, operand6);
    final INaviInstruction instruction2 = new CInstruction(false, mockModule, new CAddress(2), "str", operands2, new byte[0], "REIL", mockProvider);
    // str t1, , t2
    final COperandTreeNode rootNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode7, childNode7);
    final COperandTreeNode rootNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode8, childNode8);
    final COperandTreeNode rootNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t2", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode9, childNode9);
    final COperandTree operand7 = new COperandTree(rootNode7, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand8 = new COperandTree(rootNode8, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand9 = new COperandTree(rootNode9, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands3 = Lists.newArrayList(operand7, operand8, operand9);
    final INaviInstruction instruction3 = new CInstruction(false, mockModule, new CAddress(3), "str", operands3, new byte[0], "REIL", mockProvider);
    final INaviView view = mockModule.getContent().getViewContainer().createView("", "");
    final List<INaviInstruction> instructions = Lists.newArrayList(instruction1, instruction2, instruction3);
    view.getContent().createCodeNode(null, instructions);
    final RegisterTrackingOptions options = new RegisterTrackingOptions(true, new HashSet<String>(), false, AnalysisDirection.UP);
    final CTrackingResult results = CTracking.track(view, instruction3, "t2", options);
    for (final CInstructionResult result : results.getResults()) {
        if (result.getInstruction() == instruction1) {
            assertEquals(Color.RED, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction2) {
            assertEquals(Color.CYAN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction3) {
            assertEquals(Color.GREEN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        }
    }
}
Also used : RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTrackingResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CTrackingResult) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CInstructionResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CInstructionResult) IReference(com.google.security.zynamics.zylib.disassembly.IReference) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 10 with IReference

use of com.google.security.zynamics.zylib.disassembly.IReference in project binnavi by google.

the class CResultColorTest method testFirst.

@Test
public void testFirst() throws InternalTranslationException {
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final MockModule mockModule = new MockModule(mockProvider);
    // str 6, , t1
    final COperandTreeNode rootNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode1 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_IMMEDIATE_INT_ID, "6", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode1, childNode1);
    final COperandTreeNode rootNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode2 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode2, childNode2);
    final COperandTreeNode rootNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode3 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode3, childNode3);
    final COperandTree operand1 = new COperandTree(rootNode1, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand2 = new COperandTree(rootNode2, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand3 = new COperandTree(rootNode3, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands1 = Lists.newArrayList(operand1, operand2, operand3);
    final INaviInstruction instruction1 = new CInstruction(false, mockModule, new CAddress(1), "str", operands1, new byte[0], "REIL", mockProvider);
    // str 5, , t0
    final COperandTreeNode rootNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode4 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_IMMEDIATE_INT_ID, "5", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode4, childNode4);
    final COperandTreeNode rootNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode5 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SYMBOL_ID, ",", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode5, childNode5);
    final COperandTreeNode rootNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode6 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode6, childNode6);
    final COperandTree operand4 = new COperandTree(rootNode4, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand5 = new COperandTree(rootNode5, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand6 = new COperandTree(rootNode6, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands2 = Lists.newArrayList(operand4, operand5, operand6);
    final INaviInstruction instruction2 = new CInstruction(false, mockModule, new CAddress(2), "str", operands2, new byte[0], "REIL", mockProvider);
    // add t0, t1, t2
    final COperandTreeNode rootNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode7 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t0", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode7, childNode7);
    final COperandTreeNode rootNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode8 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t1", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode8, childNode8);
    final COperandTreeNode rootNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_SIZE_PREFIX_ID, "b4", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTreeNode childNode9 = new COperandTreeNode(-1, IOperandTree.NODE_TYPE_REGISTER_ID, "t2", null, new ArrayList<IReference>(), mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    COperandTreeNode.link(rootNode9, childNode9);
    final COperandTree operand7 = new COperandTree(rootNode7, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand8 = new COperandTree(rootNode8, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final COperandTree operand9 = new COperandTree(rootNode9, mockProvider, mockModule.getTypeManager(), mockModule.getContent().getTypeInstanceContainer());
    final List<COperandTree> operands3 = Lists.newArrayList(operand7, operand8, operand9);
    final INaviInstruction instruction3 = new CInstruction(false, mockModule, new CAddress(3), "add", operands3, new byte[0], "REIL", mockProvider);
    final INaviView view = mockModule.getContent().getViewContainer().createView("", "");
    final List<INaviInstruction> instructions = Lists.newArrayList(instruction1, instruction2, instruction3);
    view.getContent().createCodeNode(null, instructions);
    final RegisterTrackingOptions options = new RegisterTrackingOptions(true, new HashSet<String>(), false, AnalysisDirection.UP);
    final CTrackingResult results = CTracking.track(view, instruction3, "t2", options);
    for (final CInstructionResult result : results.getResults()) {
        if (result.getInstruction() == instruction1) {
            assertEquals(Color.RED, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction2) {
            assertEquals(Color.CYAN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        } else if (result.getInstruction() == instruction3) {
            assertEquals(Color.GREEN, CResultColor.determineBackgroundColor(instruction3, "t2", result));
        }
    }
}
Also used : RegisterTrackingOptions(com.google.security.zynamics.reil.algorithms.mono2.registertracking.RegisterTrackingOptions) COperandTreeNode(com.google.security.zynamics.binnavi.disassembly.COperandTreeNode) CInstruction(com.google.security.zynamics.binnavi.disassembly.CInstruction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) CTrackingResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CTrackingResult) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) COperandTree(com.google.security.zynamics.binnavi.disassembly.COperandTree) CInstructionResult(com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CInstructionResult) IReference(com.google.security.zynamics.zylib.disassembly.IReference) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Aggregations

IReference (com.google.security.zynamics.zylib.disassembly.IReference)17 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)11 Test (org.junit.Test)11 COperandTreeNode (com.google.security.zynamics.binnavi.disassembly.COperandTreeNode)10 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)8 CInstruction (com.google.security.zynamics.binnavi.disassembly.CInstruction)6 SQLProvider (com.google.security.zynamics.binnavi.Database.Interfaces.SQLProvider)5 CModule (com.google.security.zynamics.binnavi.disassembly.Modules.CModule)5 Date (java.util.Date)5 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)4 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)4 DebuggerTemplate (com.google.security.zynamics.binnavi.debug.debugger.DebuggerTemplate)3 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)3 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 ArrayList (java.util.ArrayList)3 MockDatabase (com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase)2 CInstructionResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CInstructionResult)2 CTrackingResult (com.google.security.zynamics.binnavi.Gui.GraphWindows.BottomPanel.RegisterTracker.CTrackingResult)2 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)2