// Task image policy: Friction animation tools remain available; its expression // code editor and ECMAScript execution are disabled. No agent text is logged. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static bool codeWindow(const QWidget *widget) { for (auto current = widget; current; current = current->parentWidget()) { const QString title = current->windowTitle(); const QString type = current->metaObject()->className(); if (title.startsWith("Expression", Qt::CaseInsensitive) || type.contains("ExpressionEditor") || type.contains("JSEditor")) return true; } return false; } static void blocked() { std::fputs("GUI-only task: expression scripting is disabled.\n", stderr); } class CodeEditorFilter : public QObject { public: using QObject::QObject; bool eventFilter(QObject *object, QEvent *event) override { if (event->type() == QEvent::Show) { if (auto menu = qobject_cast(object)) { for (auto action : menu->actions()) { if (action->text().contains("Expression", Qt::CaseInsensitive)) { action->setEnabled(false); action->setToolTip("Expression scripting is disabled; use keyframes."); } } } } auto widget = qobject_cast(object); if (!widget || !codeWindow(widget)) return false; switch (event->type()) { case QEvent::Show: { widget->setEnabled(false); auto window = widget->window(); window->setAttribute(Qt::WA_DontShowOnScreen, true); QPointer safeWindow(window); QTimer::singleShot(0, this, [safeWindow] { if (safeWindow) safeWindow->close(); }); blocked(); return true; } case QEvent::KeyPress: case QEvent::KeyRelease: case QEvent::InputMethod: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::Shortcut: case QEvent::ShortcutOverride: return true; default: return false; } } }; static void installFilter() { static QPointer filter; auto app = QCoreApplication::instance(); if (app && !filter) { filter = new CodeEditorFilter(app); app->installEventFilter(filter); } } int QCoreApplication::exec() { installFilter(); using Function = int (*)(); static auto original = reinterpret_cast(dlsym(RTLD_NEXT, "_ZN16QCoreApplication4execEv")); if (!original) std::abort(); return original(); } int QDialog::exec() { if (codeWindow(this)) { setEnabled(false); blocked(); return QDialog::Rejected; } using Function = int (*)(QDialog *); static auto original = reinterpret_cast(dlsym(RTLD_NEXT, "_ZN7QDialog4execEv")); if (!original) std::abort(); return original(this); } QJSValue QJSEngine::evaluate(const QString &program, const QString &, int) { installFilter(); // Friction's ordinary numeric sliders also call evaluate(text()). Parse // literal numbers directly, without executing ECMAScript, so normal GUI // coordinate/keyframe entry remains available. static const QRegularExpression number( QStringLiteral(R"(^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$)")); const QString text = program.trimmed(); if (number.match(text).hasMatch()) { bool ok = false; const double value = text.toDouble(&ok); if (ok && std::isfinite(value)) return QJSValue(value); } blocked(); return QJSValue(QJSValue::UndefinedValue); } QJSValue QJSValue::call(const QJSValueList &) { blocked(); return QJSValue(QJSValue::UndefinedValue); } QJSValue QJSValue::callWithInstance(const QJSValue &, const QJSValueList &) { blocked(); return QJSValue(QJSValue::UndefinedValue); } QJSValue QJSValue::callAsConstructor(const QJSValueList &) { blocked(); return QJSValue(QJSValue::UndefinedValue); }