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");
}
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);
}
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);
}
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.");
}
}
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);
}
Aggregations