Search in sources :

Example 1 with MockOperandTreeNode

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

the class OperandExpressionTest method testReferences.

@Test
public void testReferences() throws CouldntSaveDataException, CouldntDeleteException {
    final MockOperandExpressionListener listener = new MockOperandExpressionListener();
    final MockOperandTreeNode node = new MockOperandTreeNode();
    final OperandExpression expression = new OperandExpression(node);
    expression.addListener(listener);
    final Reference reference1 = expression.addReference(new Address(0x123), ReferenceType.CALL_VIRTUAL);
    final Reference reference2 = expression.addReference(new Address(0x124), ReferenceType.DATA);
    final List<Reference> references = expression.getReferences();
    assertEquals(2, references.size());
    assertEquals(reference1, references.get(0));
    assertEquals(reference2, references.get(1));
    assertEquals("addedReference;addedReference;", listener.events);
    expression.deleteReference(reference1);
    assertEquals(1, expression.getReferences().size());
    assertEquals("addedReference;addedReference;removedReference;", listener.events);
    expression.removeListener(listener);
}
Also used : MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) Address(com.google.security.zynamics.binnavi.API.disassembly.Address) Reference(com.google.security.zynamics.binnavi.API.disassembly.Reference) OperandExpression(com.google.security.zynamics.binnavi.API.disassembly.OperandExpression) Test(org.junit.Test)

Example 2 with MockOperandTreeNode

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

the class TypeManagerExpensiveTests method testCreateTypeSubstitution.

private void testCreateTypeSubstitution(final INaviModule module) throws CouldntSaveDataException, CouldntLoadDataException, CouldntDeleteException {
    final TypeManager manager = module.getTypeManager();
    final BaseType baseType = manager.createAtomicType(TypeName, 32, true);
    final INaviOperandTreeNode treeNode = new MockOperandTreeNode();
    final int offset = 0;
    final CAddress address = new CAddress(0x1000);
    final TypeSubstitution substitution = manager.createTypeSubstitution(treeNode, baseType, 0, offset, address);
    Assert.assertEquals(substitution.getAddress(), address);
    Assert.assertTrue(substitution.getBaseType() == baseType);
    Assert.assertTrue(substitution.getOffset() == offset);
    Assert.assertTrue(substitution.getOperandTreeNode() == treeNode);
    Assert.assertTrue(substitution.getExpressionId() == treeNode.getId());
    final List<RawTypeSubstitution> substitutions = getProvider().loadTypeSubstitutions(module);
    final List<RawTypeSubstitution> foundSubstitutions = findRawTypeSubstitutions(substitutions, treeNode.getId());
    Assert.assertTrue(foundSubstitutions.size() == 1);
    final RawTypeSubstitution foundSubstitution = foundSubstitutions.get(0);
    matchTypeSubstitution(substitution, foundSubstitution);
    manager.deleteType(baseType);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 3 with MockOperandTreeNode

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

the class TypeManagerTest method testNotifySubstitutionCreated.

@Test
public void testNotifySubstitutionCreated() throws CouldntSaveDataException {
    final TypeSubstitutionChangedEventCollector events = new TypeSubstitutionChangedEventCollector();
    typeManager.addListener(events);
    final IAddress address = new CAddress(0x1000);
    final TypeSubstitution substitution = typeManager.createTypeSubstitution(new MockOperandTreeNode(), typeSystem.intType, 0, 0, address);
    final TypeSubstitutionChangedEventCollector expectedEvents = new TypeSubstitutionChangedEventCollector();
    expectedEvents.substitutionsAdded(Sets.newHashSet(substitution));
    Assert.assertEquals(expectedEvents, events);
}
Also used : MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 4 with MockOperandTreeNode

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

the class TypeManagerTest method testNotifySubstitutionUpdated.

@Test
public void testNotifySubstitutionUpdated() throws CouldntSaveDataException {
    final IAddress address = new CAddress(0x1000);
    final INaviOperandTreeNode node = new MockOperandTreeNode();
    final TypeSubstitution substitution = typeManager.createTypeSubstitution(node, typeSystem.intType, 0, 0, address);
    final TypeSubstitutionChangedEventCollector events = new TypeSubstitutionChangedEventCollector();
    typeManager.addListener(events);
    typeManager.updateTypeSubstitution(node, substitution, typeSystem.uintType, new ArrayList<TypeMember>(), 0);
    typeManager.updateTypeSubstitution(node, typeSystem.uintType.getId(), new Integer[0], 0);
    final TypeSubstitutionChangedEventCollector expectedEvents = new TypeSubstitutionChangedEventCollector();
    expectedEvents.substitutionsChanged(Sets.newHashSet(substitution));
    expectedEvents.substitutionsChanged(Sets.newHashSet(substitution));
    Assert.assertEquals(expectedEvents, events);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 5 with MockOperandTreeNode

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

the class TypeManagerTest method testNotifySubstitutionDeleted.

@Test
public void testNotifySubstitutionDeleted() throws CouldntDeleteException, CouldntSaveDataException {
    final CAddress address = new CAddress(0x1000);
    final INaviOperandTreeNode node = new MockOperandTreeNode();
    final TypeSubstitution substitution = typeManager.createTypeSubstitution(node, typeSystem.intType, 0, 0, address);
    final TypeSubstitutionChangedEventCollector events = new TypeSubstitutionChangedEventCollector();
    typeManager.addListener(events);
    typeManager.deleteTypeSubstitution(node);
    final TypeSubstitutionChangedEventCollector expectedEvents = new TypeSubstitutionChangedEventCollector();
    expectedEvents.substitutionsDeleted(Sets.newHashSet(substitution));
    Assert.assertEquals(expectedEvents, events);
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) MockOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Aggregations

MockOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.MockOperandTreeNode)14 Test (org.junit.Test)13 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)12 INaviOperandTreeNode (com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode)3 OperandExpression (com.google.security.zynamics.binnavi.API.disassembly.OperandExpression)2 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)2 Address (com.google.security.zynamics.binnavi.API.disassembly.Address)1 Reference (com.google.security.zynamics.binnavi.API.disassembly.Reference)1