reorganize extensions and remove thread linker (doesnt work very well)

This commit is contained in:
Akash Mozumdar 2018-12-17 20:48:14 -05:00
parent 86b2014a12
commit e7e81f09bf
16 changed files with 75 additions and 321 deletions

View File

@ -13,7 +13,6 @@ Compress-Archive -Force -DestinationPath Textractor -Path @(
"Google Translate.dll",
"Regex Filter.dll",
"Remove Repetition.dll",
"Thread Linker.dll",
"Extensions.txt"
)
@ -32,6 +31,5 @@ Compress-Archive -Force -DestinationPath Textractor -Path @(
"Google Translate.dll",
"Regex Filter.dll",
"Remove Repetition.dll",
"Thread Linker.dll",
"Extensions.txt"
)

View File

@ -4,15 +4,13 @@ find_qt5(Core Widgets)
cmake_policy(SET CMP0037 OLD)
add_library(Bing\ Translate SHARED bingtranslate/bingtranslate.cpp extensionimpl.cpp)
add_library(Copy\ to\ Clipboard SHARED copyclipboard/copyclipboard.cpp extensionimpl.cpp)
add_library(Extra\ Newlines SHARED extranewlines/extranewlines.cpp extensionimpl.cpp)
add_library(Google\ Translate SHARED googletranslate/googletranslate.cpp extensionimpl.cpp)
add_library(Regex\ Filter SHARED regexfilter/regexfilter.cpp regexfilter/window.cpp extensionimpl.cpp)
add_library(Remove\ Repetition SHARED removerepeat/removerepeat.cpp extensionimpl.cpp)
add_library(Thread\ Linker SHARED threadlinker/threadlinker.cpp threadlinker/window.cpp extensionimpl.cpp)
add_library(Bing\ Translate SHARED bingtranslate.cpp extensionimpl.cpp)
add_library(Copy\ to\ Clipboard SHARED copyclipboard.cpp extensionimpl.cpp)
add_library(Extra\ Newlines SHARED extranewlines.cpp extensionimpl.cpp)
add_library(Google\ Translate SHARED googletranslate.cpp extensionimpl.cpp)
add_library(Regex\ Filter SHARED regexfilter.cpp extensionimpl.cpp)
add_library(Remove\ Repetition SHARED removerepeat.cpp extensionimpl.cpp)
target_link_libraries(Bing\ Translate winhttp Qt5::Widgets)
target_link_libraries(Google\ Translate winhttp Qt5::Widgets)
target_link_libraries(Regex\ Filter Qt5::Widgets)
target_link_libraries(Thread\ Linker Qt5::Widgets)

View File

@ -1,4 +1,4 @@
#include "../extension.h"
#include "extension.h"
#include <winhttp.h>
#include <QInputDialog>
#include <QTimer>

View File

@ -1,4 +1,4 @@
#include "../extension.h"
#include "extension.h"
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{

View File

@ -1,4 +1,4 @@
#include "../extension.h"
#include "extension.h"
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{

View File

@ -1,4 +1,4 @@
#include "../extension.h"
#include "extension.h"
#include <winhttp.h>
#include <ctime>
#include <QInputDialog>

View File

@ -0,0 +1,64 @@
#include "extension.h"
#include <QMainWindow>
#include <QLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTimer>
std::wregex regex;
std::mutex m;
struct : QMainWindow {
void Initialize()
{
auto centralWidget = new QWidget(this);
auto layout = new QVBoxLayout(centralWidget);
auto input = new QLineEdit(centralWidget);
auto output = new QLabel(centralWidget);
output->setAlignment(Qt::AlignCenter);
layout->addWidget(input);
layout->addWidget(output);
connect(input, &QLineEdit::textEdited, [=](QString newRegex)
{
std::lock_guard l(m);
try { regex = newRegex.toStdWString(); }
catch (...) { return output->setText("Invalid regex"); }
output->setText("Currently filtering: " + newRegex);
});
QMainWindow::resize(350, 60);
QMainWindow::setCentralWidget(centralWidget);
QMainWindow::setWindowTitle("Regex Filter");
QMainWindow::show();
}
}*window = nullptr;
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
std::lock_guard l(m);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
QTimer::singleShot(0, [] { (window = new std::remove_pointer_t<decltype(window)>)->Initialize(); });
}
break;
case DLL_PROCESS_DETACH:
{
if (lpReserved == NULL) // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
{
delete window;
window = nullptr;
}
}
break;
}
return TRUE;
}
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
std::lock_guard l(m);
if (window == nullptr || sentenceInfo["hook address"] == -1) return false;
sentence = std::regex_replace(sentence, regex, L"");
return true;
}

View File

@ -1,31 +0,0 @@
#include "../extension.h"
#include "window.h"
#include <QTimer>
Window* w = nullptr;
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
QTimer::singleShot(0, [] { (w = new Window)->show(); });
}
break;
case DLL_PROCESS_DETACH:
{
if (lpReserved == NULL) delete w; // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
}
break;
}
return TRUE;
}
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
if (w == nullptr || sentenceInfo["hook address"] == -1) return false;
std::lock_guard l(w->m);
sentence = std::regex_replace(sentence, w->regex, L"");
return true;
}

View File

@ -1,24 +0,0 @@
#include "window.h"
#include "ui_window.h"
#include <QLabel>
Window::Window(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Window)
{
ui->setupUi(this);
}
Window::~Window()
{
delete ui;
}
void Window::on_regexInput_textEdited(const QString& newRegex)
{
QLabel* info = findChild<QLabel*>("info");
std::lock_guard<std::mutex> l(m);
try { regex = newRegex.toStdWString(); }
catch (...) { return findChild<QLabel*>("info")->setText("Invalid regex"); }
findChild<QLabel*>("info")->setText("Currently filtering: " + newRegex);
}

View File

@ -1,29 +0,0 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "common.h"
#include <QMainWindow>
#include <QString>
namespace Ui
{
class Window;
}
class Window : public QMainWindow
{
Q_OBJECT
public:
explicit Window(QWidget *parent = nullptr);
~Window();
Ui::Window* ui;
std::mutex m;
std::wregex regex;
private slots:
void on_regexInput_textEdited(const QString& regex);
};
#endif // WINDOW_H

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Window</class>
<widget class="QMainWindow" name="Window">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>60</height>
</rect>
</property>
<property name="windowTitle">
<string>Regex Filter</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="regexInput"/>
</item>
<item>
<widget class="QLabel" name="info">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -1,4 +1,4 @@
#include "../extension.h"
#include "extension.h"
void RemoveRepeatedChars(std::wstring& sentence)
{

View File

@ -1,37 +0,0 @@
#include "../extension.h"
#include "window.h"
#include <QTimer>
Window* w = nullptr;
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
{
QTimer::singleShot(0, [] { (w = new Window)->show(); });
}
break;
case DLL_PROCESS_DETACH:
{
if (lpReserved == NULL) delete w; // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
}
break;
}
return TRUE;
}
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
if (w == nullptr) return false;
std::lock_guard l(w->m);
static std::unordered_map<int64_t, std::wstring> queuedWritesByHandle;
int64_t textHandle = sentenceInfo["text handle"];
for (auto linkedHandle : w->linkedTextHandles[textHandle]) queuedWritesByHandle[linkedHandle] += L"\r\n" + sentence;
if (queuedWritesByHandle[textHandle].empty()) return false;
sentence += queuedWritesByHandle[textHandle];
queuedWritesByHandle[textHandle].clear();
return true;
}

View File

@ -1,37 +0,0 @@
#include "window.h"
#include "ui_window.h"
#include <QInputDialog>
Window::Window(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Window)
{
ui->setupUi(this);
threadLinkList = findChild<QListWidget*>("threadLinkList");
}
Window::~Window()
{
delete ui;
}
void Window::on_linkButton_clicked()
{
bool ok1, ok2, ok3, ok4;
int from = QInputDialog::getText(this, "Link From", "Thread number to link from?", QLineEdit::Normal, "", &ok1, Qt::WindowCloseButtonHint).toInt(&ok2, 16);
int to = QInputDialog::getText(this, "Link To", "Thread number to link to?", QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
if (ok1 && ok2 && ok3 && ok4)
{
std::lock_guard l(m);
linkedTextHandles[from].insert(to);
threadLinkList->addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
}
}
void Window::on_unlinkButton_clicked()
{
std::lock_guard l(m);
QStringList link = threadLinkList->currentItem()->text().split("->");
threadLinkList->takeItem(threadLinkList->currentRow());
linkedTextHandles[link[0].toInt(nullptr, 16)].erase(link[1].toInt(nullptr, 16));
}

View File

@ -1,33 +0,0 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "common.h"
#include <QMainWindow>
#include <QListWidget>
namespace Ui
{
class Window;
}
class Window : public QMainWindow
{
Q_OBJECT
public:
explicit Window(QWidget *parent = nullptr);
~Window();
Ui::Window* ui;
std::mutex m;
std::unordered_map<int64_t, std::unordered_multiset<int64_t>> linkedTextHandles;
private slots:
void on_linkButton_clicked();
void on_unlinkButton_clicked();
private:
QListWidget* threadLinkList;
};
#endif // WINDOW_H

View File

@ -1,79 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Window</class>
<widget class="QMainWindow" name="Window">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Thread Linker</string>
</property>
<property name="styleSheet">
<string notr="true">
QObject
{
font: 10pt &quot;MS Shell Dlg 2&quot;;
}
#textOutput
{
font: 13pt &quot;MS Shell Dlg 2&quot;;
}
QPushButton, QComboBox
{
padding-top: 3px;
padding-bottom: 3px;
padding-right: 5px;
padding-left: 5px;
text-align: left;
}
</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout">
<item>
<widget class="QListWidget" name="threadLinkList">
</widget>
</item>
<item>
<layout class="QVBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="linkButton">
<property name="text">
<string>Link</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="unlinkButton">
<property name="text">
<string>Unlink</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>