Search in sources :

Example 21 with INaviModule

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

the class PostgreSQLViewLoader method checkArguments.

/**
   * Checks arguments for validity.
   * 
   * @param provider The provider argument to check.
   * @param view The view argument to check.
   * @param modules The modules argument to check.
   * @param nodeTagManager The node tag manager argument to check.
   */
private static void checkArguments(final AbstractSQLProvider provider, final INaviView view, final List<INaviModule> modules, final CTagManager nodeTagManager) {
    Preconditions.checkNotNull(provider, "IE00619: Provider argument can not be null");
    Preconditions.checkNotNull(view, "IE00620: View argument can not be null");
    Preconditions.checkArgument(view.inSameDatabase(provider), "IE00621: View is not part of this database");
    Preconditions.checkNotNull(modules, "IE00622: Modules argument can not be null");
    for (final INaviModule module : modules) {
        Preconditions.checkNotNull(module, "IE00623: Modules list contains a null element");
        Preconditions.checkArgument(module.inSameDatabase(provider), "IE00624: Module is not part of this database");
    }
    Preconditions.checkNotNull(nodeTagManager, "IE00625: Node tag manager argument can not be null");
    Preconditions.checkArgument(nodeTagManager.inSameDatabase(provider), "IE00626: Node tag manager is not part of this database");
}
Also used : INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule)

Example 22 with INaviModule

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

the class PostgreSQLCommentNotificationParser method processNodeLocalNodeCommentNotification.

/**
   * Parses the {@link PGNotification} notifications from the PostgreSQL database back end for local
   * code node comments by using a regular expression. If the regular expression matches the
   * supplied {@link PGNotification} notification, it is determined if the code node in the
   * notification is currently loaded, and if a {@link CommentNotificationContainer} with the
   * gathered data from the notification is returned.
   *
   * @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 processNodeLocalNodeCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = NODE_LOCAL_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer moduleId = Integer.parseInt(matcher.group(3));
    final Integer nodeId = Integer.parseInt(matcher.group(4));
    final Integer commentId = matcher.group(6).equals("null") ? null : Integer.parseInt(matcher.group(6));
    final INaviModule module = provider.findModule(moduleId);
    if (!module.isLoaded()) {
        return null;
    }
    final INaviCodeNode codeNode = (INaviCodeNode) NodeCache.get(provider).getNodeById(nodeId);
    if (codeNode == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new CodeNodeCommentNotificationContainer(codeNode, operation, CommentScope.LOCAL, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) INaviCodeNode(com.google.security.zynamics.binnavi.disassembly.INaviCodeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) CodeNodeCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.CodeNodeCommentNotificationContainer)

Example 23 with INaviModule

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

the class PostgreSQLCommentNotificationParser method processFunctionCommentNotification.

/**
   * Parses the notifications from the database back end for function comments by using a regular
   * expression. If the regular expression matches the supplied {@link PGNotification} notification,
   * a {@link CommentNotificationContainer} is build with the data from the notification.
   *
   * @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 processFunctionCommentNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = FUNCTION_PATTERN.matcher(notification.getParameter());
    if (!matcher.find()) {
        return null;
    }
    final Integer notificationModuleId = Integer.parseInt(matcher.group(3));
    final IAddress notificationFunctionAddress = new CAddress(new BigInteger(matcher.group(4)));
    final Integer commentId = matcher.group(5).equals("null") ? null : Integer.parseInt(matcher.group(5));
    final INaviModule module = provider.findModule(notificationModuleId);
    if ((module == null) || !module.isLoaded()) {
        return null;
    }
    final INaviFunction function = module.getContent().getFunctionContainer().getFunction(notificationFunctionAddress);
    if (function == null) {
        return null;
    }
    final CommentOperation operation = commentId == null ? CommentOperation.DELETE : CommentOperation.APPEND;
    return new FunctionCommentNotificationContainer(function, operation, commentId);
}
Also used : BigInteger(java.math.BigInteger) CommentOperation(com.google.security.zynamics.binnavi.disassembly.CommentManager.CommentOperation) FunctionCommentNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.FunctionCommentNotificationContainer) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) BigInteger(java.math.BigInteger) INaviFunction(com.google.security.zynamics.binnavi.disassembly.INaviFunction) IAddress(com.google.security.zynamics.zylib.disassembly.IAddress) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 24 with INaviModule

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

the class PostgreSQLTypesNotificationParser method informExpressionTypesNotification.

/**
   * Informs about necessary state changes related to {@link TypeSubstitution type substitutions}.
   *
   * @param container The {@link TypesNotificationContainer} holding the parsed
   *        {@link PGNotification notification} information.
   * @param provider The {@link SQLProvider} used to access the database with.
   *
   * @throws CouldntLoadDataException if the required information could not be loaded from the
   *         database.
   */
private void informExpressionTypesNotification(final TypesNotificationContainer container, final SQLProvider provider) throws CouldntLoadDataException {
    final INaviModule module = provider.findModule(container.getModuleId());
    final TypeManager typeManager = module.getTypeManager();
    final INaviOperandTreeNode node = findOperandTreeNode(provider, container.getModuleId(), new CAddress(container.getAddress().get()), container.position().get(), container.expressionId().get());
    if (node == null) {
        return;
    }
    if (container.getDatabaseOperation().equals("INSERT")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.initializeTypeSubstitution(node, rawSubstitution);
    } else if (container.getDatabaseOperation().equals("UPDATE")) {
        final RawTypeSubstitution rawSubstitution = provider.loadTypeSubstitution(module, container.getAddress().get(), container.position().get(), container.expressionId().get());
        typeManager.updateTypeSubstitution(node, rawSubstitution.getBaseTypeId(), rawSubstitution.getPath(), rawSubstitution.getOffset());
    } else if (container.getDatabaseOperation().equals("DELETE")) {
        typeManager.removeTypeSubstitutionInstance(node.getTypeSubstitution());
    } else {
        throw new IllegalStateException("Error: the database operation " + container.getDatabaseOperation() + " is currently not supported.");
    }
}
Also used : INaviOperandTreeNode(com.google.security.zynamics.binnavi.disassembly.INaviOperandTreeNode) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) TypeManager(com.google.security.zynamics.binnavi.disassembly.types.TypeManager) RawTypeSubstitution(com.google.security.zynamics.binnavi.disassembly.types.RawTypeSubstitution) CAddress(com.google.security.zynamics.zylib.disassembly.CAddress)

Example 25 with INaviModule

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

the class PostgreSQLViewNotificationParser method parseModuleViewNotification.

/**
   * Parser for a bn_module_views notification. The function uses the moduleViewNotificationPattern
   * to parse the incoming {@link PGNotification} into a {@link ViewNotificationContainer}.
   *
   * @param notification The {@link PGNotification} to parse.
   * @param provider The {@link SQLProvider} to access the database.
   *
   * @return A {@link ViewNotificationContainer} with the parsed information.
   */
private ViewNotificationContainer parseModuleViewNotification(final PGNotification notification, final SQLProvider provider) {
    final Matcher matcher = moduleViewNotificationPattern.matcher(notification.getParameter());
    if (!matcher.find()) {
        throw new IllegalStateException("IE02743: compiled pattern: " + moduleViewNotificationPattern.toString() + " did not match notification: " + notification.getParameter());
    }
    final Integer viewId = Integer.parseInt(matcher.group(3));
    final Optional<INaviView> view = Optional.fromNullable(ViewManager.get(provider).getView(viewId));
    final Optional<Integer> moduleId = Optional.fromNullable(Integer.parseInt(matcher.group(4)));
    final Optional<INaviModule> module = Optional.fromNullable(provider.findModule(moduleId.get()));
    final String databaseOperation = matcher.group(2);
    return new ViewNotificationContainer(viewId, view, moduleId, module, Optional.<INaviProject>absent(), databaseOperation);
}
Also used : INaviView(com.google.security.zynamics.binnavi.disassembly.views.INaviView) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) Matcher(java.util.regex.Matcher) ViewNotificationContainer(com.google.security.zynamics.binnavi.Database.PostgreSQL.Notifications.containers.ViewNotificationContainer)

Aggregations

INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)180 Test (org.junit.Test)105 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)69 INaviFunction (com.google.security.zynamics.binnavi.disassembly.INaviFunction)39 CAddress (com.google.security.zynamics.zylib.disassembly.CAddress)39 INaviView (com.google.security.zynamics.binnavi.disassembly.views.INaviView)29 UnrelocatedAddress (com.google.security.zynamics.binnavi.disassembly.UnrelocatedAddress)28 IAddress (com.google.security.zynamics.zylib.disassembly.IAddress)28 MockModule (com.google.security.zynamics.binnavi.disassembly.Modules.MockModule)24 BreakpointAddress (com.google.security.zynamics.binnavi.debug.models.breakpoints.BreakpointAddress)22 ArrayList (java.util.ArrayList)19 INaviInstruction (com.google.security.zynamics.binnavi.disassembly.INaviInstruction)18 CView (com.google.security.zynamics.binnavi.disassembly.views.CView)13 BigInteger (java.math.BigInteger)13 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)12 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)11 CTagManager (com.google.security.zynamics.binnavi.Tagging.CTagManager)11 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)9 CAddressSpace (com.google.security.zynamics.binnavi.disassembly.AddressSpaces.CAddressSpace)9 COperandTree (com.google.security.zynamics.binnavi.disassembly.COperandTree)9