disabled default native messaging registry key installation

This commit is contained in:
fourtf 2018-04-12 00:09:16 +02:00
parent 444242f3fe
commit 0d2f0b3890
3 changed files with 32 additions and 29 deletions

View file

@ -1,5 +1,7 @@
#include "application.hpp" #include "application.hpp"
#include "singletons/nativemessagingmanager.hpp"
#include "singletons/pathmanager.hpp" #include "singletons/pathmanager.hpp"
#include "util/networkmanager.hpp"
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <QApplication> #include <QApplication>
@ -7,20 +9,17 @@
#include <QLibrary> #include <QLibrary>
#include <QStringList> #include <QStringList>
#include <iostream>
#include "util/networkmanager.hpp"
#ifdef USEWINSDK #ifdef USEWINSDK
#include "util/nativeeventhelper.hpp" #include "util/nativeeventhelper.hpp"
#endif #endif
#include "fstream" #include <fstream>
#include <iostream>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include "fcntl.h" #include <fcntl.h>
#include "io.h" #include <io.h>
#include "stdio.h" #include <stdio.h>
#endif #endif
void runNativeMessagingHost(); void runNativeMessagingHost();
@ -90,15 +89,6 @@ int runGui(int argc, char *argv[])
_exit(0); _exit(0);
} }
void writeByteArray(QByteArray a)
{
char *data = a.data();
uint32_t size;
size = a.size();
std::cout.write(reinterpret_cast<char *>(&size), 4);
std::cout.write(data, a.size());
}
void runNativeMessagingHost() void runNativeMessagingHost()
{ {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
@ -106,7 +96,9 @@ void runNativeMessagingHost()
_setmode(_fileno(stdout), _O_BINARY); _setmode(_fileno(stdout), _O_BINARY);
#endif #endif
// std::ofstream xd("C:\\users\\daniel\\desktop\\xd.lmao"); std::ofstream xD("C:\Users\daniel\Desktop\1");
auto &nmm = chatterino::singletons::NativeMessagingManager::getInstance();
while (true) { while (true) {
char size_c[4]; char size_c[4];
@ -122,11 +114,12 @@ void runNativeMessagingHost()
std::cin.read(b, size); std::cin.read(b, size);
*(b + size) = '\0'; *(b + size) = '\0';
// xd << b; nmm.writeByteArray("{\"a\":1}");
// xd.flush();
nmm.sendToGuiProcess(QByteArray(b, size));
nmm.writeByteArray("{\"a\":2}");
free(b); free(b);
// writeByteArray(QString("{\"xd\":1}").toUtf8());
} }
} }

View file

@ -8,17 +8,14 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
//#ifdef USEWINSDK
//#include <windows.h>
//#pragma comment(lib, "Advapi32.lib")
//#endif
#include <boost/interprocess/ipc/message_queue.hpp> #include <boost/interprocess/ipc/message_queue.hpp>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QProcess> #include <QProcess>
#endif #endif
#include <iostream>
#define EXTENSION_ID "aeicjepmjkgmbeohnchmpfjbpchogmjn" #define EXTENSION_ID "aeicjepmjkgmbeohnchmpfjbpchogmjn"
#define MESSAGE_SIZE 1024 #define MESSAGE_SIZE 1024
@ -37,6 +34,16 @@ NativeMessagingManager &NativeMessagingManager::getInstance()
return manager; return manager;
} }
void NativeMessagingManager::writeByteArray(QByteArray a)
{
char *data = a.data();
uint32_t size;
size = a.size();
std::cout.write(reinterpret_cast<char *>(&size), 4);
std::cout.write(data, a.size());
std::cout.flush();
}
void NativeMessagingManager::registerHost() void NativeMessagingManager::registerHost()
{ {
// create manifest // create manifest
@ -61,11 +68,13 @@ void NativeMessagingManager::registerHost()
file.write(document.toJson()); file.write(document.toJson());
file.flush(); file.flush();
#ifdef XD
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
// clang-format off // clang-format off
QProcess::execute("REG ADD \"HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.chatterino.chatterino\" /ve /t REG_SZ /d \"" + manifestPath + "\" /f"); QProcess::execute("REG ADD \"HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\com.chatterino.chatterino\" /ve /t REG_SZ /d \"" + manifestPath + "\" /f");
// clang-format on // clang-format on
#endif #endif
#endif
} }
void NativeMessagingManager::openGuiMessageQueue() void NativeMessagingManager::openGuiMessageQueue()
@ -86,7 +95,7 @@ void NativeMessagingManager::sendToGuiProcess(const QByteArray &array)
try { try {
messageQueue.try_send(array.data(), array.size(), 1); messageQueue.try_send(array.data(), array.size(), 1);
} catch (ipc::interprocess_exception &ex) { } catch (ipc::interprocess_exception &ex) {
// rip qDebug() << "send to gui process:" << ex.what();
} }
} }
@ -107,7 +116,7 @@ void NativeMessagingManager::ReceiverThread::run()
QString text = QString::fromUtf8(buf, retSize); QString text = QString::fromUtf8(buf, retSize);
qDebug() << text; qDebug() << text;
} catch (ipc::interprocess_exception &ex) { } catch (ipc::interprocess_exception &ex) {
// rip qDebug() << "received from gui process:" << ex.what();
} }
} }
} }

View file

@ -18,6 +18,7 @@ public:
void run() override; void run() override;
}; };
void writeByteArray(QByteArray a);
void registerHost(); void registerHost();
void openGuiMessageQueue(); void openGuiMessageQueue();
void sendToGuiProcess(const QByteArray &array); void sendToGuiProcess(const QByteArray &array);