| Line | Branch | Decision | Call | Exec | Source |
|---|---|---|---|---|---|
| 1 | #include "AuthenticatorExtension.h" | ||||
| 2 | |||||
| 3 | #define LOGGER_NAME "Authenticator Extension" | ||||
| 4 | |||||
| 5 | #include <QUrl> | ||||
| 6 | #include <QThread> | ||||
| 7 | #include <QPointer> | ||||
| 8 | #include <QApplication> | ||||
| 9 | #include <QDesktopServices> | ||||
| 10 | #include <QtCore/private/qhooks_p.h> | ||||
| 11 | |||||
| 12 | #include "Logging.h" | ||||
| 13 | #include "HooksManager.h" | ||||
| 14 | |||||
| 15 | using namespace CLO3D; | ||||
| 16 | |||||
| 17 | // TODO: | ||||
| 18 | // - Class for qHookData, constructionQueue, loginDialog | ||||
| 19 | // - Intercept other HTTP(S) calls | ||||
| 20 | |||||
| 21 | ✗ | extern "C" CLO3D_EXTENSION_ENTRY BaseExtension* create() { | |||
| 22 | ✗ | return new AuthenticatorExtension(); | |||
| 23 | } | ||||
| 24 | |||||
| 25 | QWidget* loginDialog; | ||||
| 26 | QObject* authenticationProcessor; | ||||
| 27 | QVector<QPointer<QObject>> constructionQueue; | ||||
| 28 | |||||
| 29 | ✗ | bool isObjectOfClass(const QObject* object, const QString& className) { | |||
| 30 | ✗ | return className == object->metaObject()->className(); | |||
| 31 | } | ||||
| 32 | |||||
| 33 | ✗ | void AuthenticatorExtension::install() { | |||
| 34 | ✗ | qtHookData[QHooks::AddQObject] = reinterpret_cast<quintptr>(+[](QObject *object) { | |||
| 35 | ✗ | for (int i = 0; i < constructionQueue.size(); i++) { | |||
| 36 | ✗ | if (auto pointer = constructionQueue.at(i)) { | |||
| 37 | ✗ | if (QObject* obj = pointer.data()) { | |||
| 38 | ✗ | if (!authenticationProcessor && isObjectOfClass(obj, "AuthenticationProcessor")) { | |||
| 39 | ✗ | authenticationProcessor = obj; | |||
| 40 | ✗ | } else if (!loginDialog && isObjectOfClass(obj, "CloUICommon::LoginDialog")) { | |||
| 41 | ✗ | loginDialog = qobject_cast<QWidget*>(obj); | |||
| 42 | } | ||||
| 43 | } | ||||
| 44 | ✗ | constructionQueue.removeAt(i); | |||
| 45 | ✗ | i--; | |||
| 46 | ✗ | } | |||
| 47 | } | ||||
| 48 | ✗ | constructionQueue.append(QPointer(object)); | |||
| 49 | ✗ | }); | |||
| 50 | ✗ | HooksManager::addBefore<&QApplication::exec>([](const HookHandle& handle) { | |||
| 51 | ✗ | loginDialog->dumpObjectInfo(); | |||
| 52 | ✗ | authenticationProcessor->dumpObjectInfo(); | |||
| 53 | |||||
| 54 | ✗ | LOG_INFO("Skipping logging in"); | |||
| 55 | ✗ | QMetaObject::invokeMethod(authenticationProcessor, "SucceedAuthentication"); | |||
| 56 | ✗ | QMetaObject::invokeMethod(loginDialog, "SignInWithCloset"); | |||
| 57 | |||||
| 58 | ✗ | qtHookData[QHooks::AddQObject] = 0; | |||
| 59 | ✗ | handle.remove(); | |||
| 60 | ✗ | }); | |||
| 61 | ✗ | HooksManager::addIgnoreConditionally<&QDesktopServices::openUrl>([](const HookHandle &handle, bool& ignore, bool ret, const QUrl &url) { | |||
| 62 | ✗ | if (url.toString().startsWith("https://style.clo-set.com/en/account/signin?productId=40")) { | |||
| 63 | ✗ | LOG_INFO("Bypassing login URL: {}", url.toString().toStdString()); | |||
| 64 | ✗ | ignore = true; | |||
| 65 | ✗ | ret = true; | |||
| 66 | } | ||||
| 67 | ✗ | }); | |||
| 68 | ✗ | } | |||
| 69 |