Search in sources :

Example 1 with TypeInstance

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

the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingAppendComment.

@Test
public void testTypeInstanceCommentParsingAppendComment() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
    final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
    MockPGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " 3333");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
    assertNotNull(result);
    final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
    assertNotNull(container);
    final TypeInstance instance = container.getInstance();
    assertEquals(fakeInstance.getId(), instance.getId());
    assertEquals(CommentOperation.APPEND, container.getOperation());
    assertEquals(new Integer(3333), container.getCommentId());
}
Also used : TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 2 with TypeInstance

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

the class PostgreSQLNotificationParserTest method testTypeInstanceCommentParsingDeleteComment.

@Test
public void testTypeInstanceCommentParsingDeleteComment() throws CouldntSaveDataException, CouldntLoadDataException {
    final INaviModule module = new MockModule(provider, Lists.newArrayList(mockView), Lists.newArrayList(mockFunction));
    module.getContent().getSections().createSection("A", new CAddress(0), new CAddress(1234), SectionPermission.READ, null);
    final TypeInstance fakeInstance = module.getContent().getTypeInstanceContainer().createInstance("TYPE INSTANCE", null, module.getTypeManager().getTypes().get(0), module.getContent().getSections().getSection(0), 0);
    final PGNotification notification = new MockPGNotification("comment_changes", "bn_type_instances UPDATE 1 " + fakeInstance.getId() + " null");
    final CommentNotification result = PostgreSQLCommentNotificationParser.processTypeInstanceCommentNotification(notification, provider);
    assertNotNull(result);
    final TypeInstanceCommentNotificationContainer container = (TypeInstanceCommentNotificationContainer) result;
    assertNotNull(container);
    final TypeInstance instance = container.getInstance();
    assertEquals(fakeInstance.getId(), instance.getId());
    assertEquals(CommentOperation.DELETE, container.getOperation());
    assertNull(container.getCommentId());
}
Also used : TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) CommentNotification(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) PGNotification(org.postgresql.PGNotification) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) Test(org.junit.Test)

Example 3 with TypeInstance

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

the class PostgreSQLTypeInstanceFunctionsTests method createTypeInstanceReference5.

@Test
public void createTypeInstanceReference5() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException, CPartialLoadException {
    module.load();
    final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstances().get(0);
    final TypeInstanceAddress address1 = typeInstance.getAddress();
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction(new CAddress("1001929", 16));
    final INaviView view = module.getContent().getViewContainer().getView(function);
    view.load();
    final INaviInstruction instruction = view.getBasicBlocks().get(1).getInstructions().iterator().next();
    Assert.assertNotNull(typeInstance);
    provider.createTypeInstanceReference(typeInstance.getModule().getConfiguration().getId(), instruction.getAddress().toLong(), instruction.getOperandPosition(instruction.getOperands().get(0)), instruction.getOperands().get(0).getNodes().get(0).getId(), typeInstance.getId());
    view.close();
    module.close();
    module.load();
    view.load();
    final TypeInstance typeInstance2 = module.getContent().getTypeInstanceContainer().getTypeInstance(typeInstance.getAddress());
    Assert.assertEquals(address1, typeInstance2.getAddress());
    final List<TypeInstanceReference> references = module.getContent().getTypeInstanceContainer().getReferences(typeInstance2);
    Assert.assertTrue(!references.isEmpty());
    Assert.assertEquals(instruction.getAddress(), references.get(0).getAddress());
    Assert.assertEquals(instruction.getOperandPosition(instruction.getOperands().get(0)), references.get(0).getPosition());
    Assert.assertEquals(instruction.getOperands().get(0).getNodes().get(0).getId(), references.get(0).getTreeNode().get().getId());
    Assert.assertEquals(typeInstance.getId(), references.get(0).getTypeInstance().getId());
}
Also used : TypeInstanceAddress(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceAddress) INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) TypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference) RawTypeInstanceReference(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress) INaviInstruction(com.google.security.zynamics.binnavi.disassembly.INaviInstruction) Test(org.junit.Test)

Example 4 with TypeInstance

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

the class PostgreSQLTypeInstanceFunctionsTests method deleteTypeInstanceTest3.

@Test
public void deleteTypeInstanceTest3() throws CouldntDeleteException, CouldntLoadDataException, LoadCancelledException {
    module.load();
    final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstances().get(0);
    provider.deleteTypeInstance(module.getConfiguration().getId(), typeInstance.getId());
    module.close();
    module.load();
    Assert.assertFalse(module.getContent().getTypeInstanceContainer().getTypeInstances().contains(typeInstance));
}
Also used : RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) Test(org.junit.Test)

Example 5 with TypeInstance

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

the class PostgreSQLTypeInstanceFunctionsTests method createTypeInstance6.

@Test
public void createTypeInstance6() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    final String typeInstanceName = " TYPE INSTANCE NAME ";
    module.load();
    final Section section = module.getContent().getSections().getSections().get(0);
    final BaseType type = module.getTypeManager().getTypes().get(0);
    final int typeInstanceId = provider.createTypeInstance(module.getConfiguration().getId(), typeInstanceName, null, type.getId(), section.getId(), 0);
    module.close();
    module.load();
    final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstanceById(typeInstanceId);
    Assert.assertEquals(typeInstanceId, typeInstance.getId());
    Assert.assertEquals(typeInstanceName, typeInstance.getName());
    Assert.assertEquals(module, typeInstance.getModule());
    Assert.assertEquals(section.getId(), typeInstance.getSection().getId());
}
Also used : BaseType(com.google.security.zynamics.binnavi.disassembly.types.BaseType) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) Section(com.google.security.zynamics.binnavi.disassembly.types.Section) Test(org.junit.Test)

Aggregations

TypeInstance (com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)14 Test (org.junit.Test)9 RawTypeInstance (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance)7 TypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceReference)5 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)4 TypeInstanceCommentNotificationContainer (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)3 RawTypeInstanceReference (com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstanceReference)3 TypeInstanceAddress (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceAddress)3 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)3 CommentNotification (com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.interfaces.CommentNotification)2 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)2 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)2 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)2 CommentOperation (com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation)1 BaseType (com.google.security.zynamics.binnavi.disassembly.types.BaseType)1 Section (com.google.security.zynamics.binnavi.disassembly.types.Section)1 TypeInstanceContainer (com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceContainer)1 FormattedCharacterBuffer (com.google.security.zynamics.zylib.gui.CodeDisplay.FormattedCharacterBuffer)1 Color (java.awt.Color)1