Search in sources :

Example 6 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 7 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 8 with TypeInstance

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

the class PostgreSQLCommentNotificationParser method processTypeInstanceCommentNotification.

/**
   * Parses the {@link PGNotification notifications} from the PostgreSQL database back end for
   * {@link TypeInstance type instance} comments by using a regular expression.
   *
   * @param notification The {@link PGNotification} from the PostgreSQL database server.
   * @param provider The {@link SQLProvider} which is used to communicate with the database.
   */
static CommentNotification processTypeInstanceCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = TYPE_INSTANCE_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer typeInstanceId = Integer.parseInt(matcher.group(4));
    final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
    final INaviModule module = provider.findModule(moduleId);
    if (module == null || !module.isLoaded()) {
        return null;
    }
    final TypeInstance instance = module.getContent().getTypeInstanceContainer().getTypeInstanceById(typeInstanceId);
    if (instance == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new TypeInstanceCommentNotificationContainer(instance, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) TypeInstanceCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.TypeInstanceCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance)

Example 9 with TypeInstance

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

the class PostgreSQLTypeInstanceFunctionsTests method setTypeInstanceNameTest4.

@Test
public void setTypeInstanceNameTest4() throws CouldntSaveDataException, CouldntLoadDataException, LoadCancelledException {
    module.load();
    final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstances().get(0);
    final TypeInstanceAddress address = typeInstance.getAddress();
    provider.setTypeInstanceName(module.getConfiguration().getId(), typeInstance.getId(), " SUPER NEW NAME ");
    module.close();
    module.load();
    final TypeInstance loadedInstance = module.getContent().getTypeInstanceContainer().getTypeInstance(address);
    Assert.assertEquals(" SUPER NEW NAME ", loadedInstance.getName());
}
Also used : TypeInstanceAddress(com.google.security.zynamics.binnavi.disassembly.types.TypeInstanceAddress) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) Test(org.junit.Test)

Example 10 with TypeInstance

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

the class PostgreSQLTypeInstanceFunctionsTests method loadSingleTypeInstanceTest3.

@Test
public void loadSingleTypeInstanceTest3() throws CouldntLoadDataException, LoadCancelledException {
    module.load();
    final TypeInstance typeInstance = module.getContent().getTypeInstanceContainer().getTypeInstances().get(0);
    final RawTypeInstance rawTypeInstance = provider.loadTypeInstance(module, typeInstance.getId());
    Assert.assertEquals(typeInstance.getId(), rawTypeInstance.getId());
    Assert.assertEquals(typeInstance.getBaseType().getId(), rawTypeInstance.getTypeId());
}
Also used : RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) RawTypeInstance(com.google.security.zynamics.binnavi.disassembly.types.RawTypeInstance) TypeInstance(com.google.security.zynamics.binnavi.disassembly.types.TypeInstance) 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