mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
add universal links to thread linker
This commit is contained in:
parent
085bec6d5b
commit
fb9fb5d54a
@ -105,7 +105,7 @@ namespace
|
|||||||
return { threadParam[1].toUInt(nullptr, 16), threadParam[2].toULongLong(nullptr, 16), threadParam[3].toULongLong(nullptr, 16), threadParam[4].toULongLong(nullptr, 16) };
|
return { threadParam[1].toUInt(nullptr, 16), threadParam[2].toULongLong(nullptr, 16), threadParam[3].toULongLong(nullptr, 16), threadParam[4].toULongLong(nullptr, 16) };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<InfoForExtension, 10> GetSentenceInfo(TextThread& thread)
|
std::array<InfoForExtension, 20> GetSentenceInfo(TextThread& thread)
|
||||||
{
|
{
|
||||||
void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text)
|
void (*AddText)(int64_t, const wchar_t*) = [](int64_t number, const wchar_t* text)
|
||||||
{
|
{
|
||||||
@ -126,6 +126,9 @@ namespace
|
|||||||
{ "hook address", (int64_t)thread.tp.addr },
|
{ "hook address", (int64_t)thread.tp.addr },
|
||||||
{ "text handle", thread.handle },
|
{ "text handle", thread.handle },
|
||||||
{ "text name", (int64_t)thread.name.c_str() },
|
{ "text name", (int64_t)thread.name.c_str() },
|
||||||
|
{ "add sentence", (int64_t)AddSentence },
|
||||||
|
{ "add text", (int64_t)AddText },
|
||||||
|
{ "get selected process id", (int64_t)GetSelectedProcessId },
|
||||||
{ "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence },
|
{ "void (*AddSentence)(int64_t number, const wchar_t* sentence)", (int64_t)AddSentence },
|
||||||
{ "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText },
|
{ "void (*AddText)(int64_t number, const wchar_t* text)", (int64_t)AddText },
|
||||||
{ "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId },
|
{ "DWORD (*GetSelectedProcessId)()", (int64_t)GetSelectedProcessId },
|
||||||
|
@ -56,7 +56,7 @@ private:
|
|||||||
|
|
||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
static auto _ = GetSelectedProcessId = (DWORD(*)())sentenceInfo["DWORD (*GetSelectedProcessId)()"];
|
static auto _ = GetSelectedProcessId = (DWORD(*)())sentenceInfo["get selected process id"];
|
||||||
if (sentenceInfo["text number"] == 0) return false;
|
if (sentenceInfo["text number"] == 0) return false;
|
||||||
if (/*sentenceInfo["current select"] && */!regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"]))
|
if (/*sentenceInfo["current select"] && */!regex) if (auto processName = GetModuleFilename(sentenceInfo["process id"]))
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "qtcommon.h"
|
#include "qtcommon.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
|
#include "ui_threadlinker.h"
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
extern const char* THREAD_LINKER;
|
extern const char* THREAD_LINKER;
|
||||||
@ -9,7 +10,9 @@ extern const char* THREAD_LINK_FROM;
|
|||||||
extern const char* THREAD_LINK_TO;
|
extern const char* THREAD_LINK_TO;
|
||||||
extern const char* HEXADECIMAL;
|
extern const char* HEXADECIMAL;
|
||||||
|
|
||||||
std::unordered_map<int64_t, std::unordered_set<int64_t>> linkedTextHandles;
|
std::unordered_map<int64_t, std::unordered_set<int64_t>> links;
|
||||||
|
std::unordered_set<int64_t> universalLinks, empty;
|
||||||
|
bool separateSentences = true; // allow user to change?
|
||||||
concurrency::reader_writer_lock m;
|
concurrency::reader_writer_lock m;
|
||||||
|
|
||||||
class Window : public QDialog, Localizer
|
class Window : public QDialog, Localizer
|
||||||
@ -17,15 +20,11 @@ class Window : public QDialog, Localizer
|
|||||||
public:
|
public:
|
||||||
Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
|
Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
|
||||||
{
|
{
|
||||||
connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
|
ui.setupUi(this);
|
||||||
connect(&unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
|
ui.linkButton->setText(LINK);
|
||||||
|
ui.unlinkButton->setText(UNLINK);
|
||||||
layout.addWidget(&linkList);
|
connect(ui.linkButton, &QPushButton::clicked, this, &Window::Link);
|
||||||
layout.addLayout(&buttons);
|
connect(ui.unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
|
||||||
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
|
||||||
buttons.addWidget(&linkButton);
|
|
||||||
buttons.addWidget(&unlinkButton);
|
|
||||||
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
|
|
||||||
|
|
||||||
setWindowTitle(THREAD_LINKER);
|
setWindowTitle(THREAD_LINKER);
|
||||||
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
|
||||||
@ -35,23 +34,25 @@ private:
|
|||||||
void Link()
|
void Link()
|
||||||
{
|
{
|
||||||
bool ok1, ok2, ok3, ok4;
|
bool ok1, ok2, ok3, ok4;
|
||||||
int from = QInputDialog::getText(this, THREAD_LINK_FROM, HEXADECIMAL, QLineEdit::Normal, "", &ok1, Qt::WindowCloseButtonHint).toInt(&ok2, 16);
|
QString fromInput = QInputDialog::getText(this, THREAD_LINK_FROM, HEXADECIMAL, QLineEdit::Normal, "X", &ok1, Qt::WindowCloseButtonHint);
|
||||||
int to = QInputDialog::getText(this, THREAD_LINK_TO, HEXADECIMAL, QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
|
int from = fromInput.toInt(&ok2, 16),
|
||||||
if (ok1 && ok2 && ok3 && ok4)
|
to = QInputDialog::getText(this, THREAD_LINK_TO, HEXADECIMAL, QLineEdit::Normal, "", &ok3, Qt::WindowCloseButtonHint).toInt(&ok4, 16);
|
||||||
|
if (ok1 && (ok2 || fromInput == "X") && ok3 && ok4)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(m);
|
std::scoped_lock lock(m);
|
||||||
if (linkedTextHandles[from].insert(to).second) linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
|
if ((ok2 ? links[from] : universalLinks).insert(to).second)
|
||||||
|
ui.linkList->addItem((ok2 ? QString::number(from, 16) : "X") + "->" + QString::number(to, 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unlink()
|
void Unlink()
|
||||||
{
|
{
|
||||||
if (linkList.currentItem())
|
if (ui.linkList->currentItem())
|
||||||
{
|
{
|
||||||
QStringList link = linkList.currentItem()->text().split("->");
|
QStringList link = ui.linkList->currentItem()->text().split("->");
|
||||||
linkList.takeItem(linkList.currentRow());
|
ui.linkList->takeItem(ui.linkList->currentRow());
|
||||||
std::scoped_lock lock(m);
|
std::scoped_lock lock(m);
|
||||||
linkedTextHandles[link[0].toInt(nullptr, 16)].erase(link[1].toInt(nullptr, 16));
|
(link[0] == "X" ? universalLinks : links[link[0].toInt(nullptr, 16)]).erase(link[1].toInt(nullptr, 16));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,17 +61,16 @@ private:
|
|||||||
if (event->key() == Qt::Key_Delete) Unlink();
|
if (event->key() == Qt::Key_Delete) Unlink();
|
||||||
}
|
}
|
||||||
|
|
||||||
QHBoxLayout layout{ this };
|
Ui::LinkWindow ui;
|
||||||
QVBoxLayout buttons;
|
|
||||||
QListWidget linkList{ this };
|
|
||||||
QPushButton linkButton{ LINK, this }, unlinkButton{ UNLINK, this };
|
|
||||||
} window;
|
} window;
|
||||||
|
|
||||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||||
{
|
{
|
||||||
concurrency::reader_writer_lock::scoped_lock_read readLock(m);
|
concurrency::reader_writer_lock::scoped_lock_read readLock(m);
|
||||||
auto links = linkedTextHandles.find(sentenceInfo["text number"]);
|
auto action = separateSentences ? sentenceInfo["add sentence"] : sentenceInfo["add text"];
|
||||||
if (links != linkedTextHandles.end()) for (auto link : links->second)
|
auto it = links.find(sentenceInfo["text number"]);
|
||||||
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(link, sentence.c_str());
|
for (const auto& linkSet : { it != links.end() ? it->second : empty, universalLinks })
|
||||||
|
for (auto link : linkSet)
|
||||||
|
((void(*)(int64_t, const wchar_t*))action)(link, sentence.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
47
extensions/threadlinker.ui
Normal file
47
extensions/threadlinker.ui
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>LinkWindow</class>
|
||||||
|
<widget class="QDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="linkList"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout">
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="unlinkButton">
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="linkButton">
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
2
text.cpp
2
text.cpp
@ -222,7 +222,7 @@ This file must be encoded in Unicode (UTF-16 Little Endian).)";
|
|||||||
const char* THREAD_LINKER = u8"Thread Linker";
|
const char* THREAD_LINKER = u8"Thread Linker";
|
||||||
const char* LINK = u8"Link";
|
const char* LINK = u8"Link";
|
||||||
const char* UNLINK = u8"Unlink";
|
const char* UNLINK = u8"Unlink";
|
||||||
const char* THREAD_LINK_FROM = u8"Thread number to link from";
|
const char* THREAD_LINK_FROM = u8"Thread number to link from (or X to link from all threads)";
|
||||||
const char* THREAD_LINK_TO = u8"Thread number to link to";
|
const char* THREAD_LINK_TO = u8"Thread number to link to";
|
||||||
const char* HEXADECIMAL = u8"Hexadecimal";
|
const char* HEXADECIMAL = u8"Hexadecimal";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user