user selected process forgetting, and other small fixes

This commit is contained in:
Akash Mozumdar 2019-07-02 11:26:04 +05:30
parent c5c115c5da
commit 011a5418e9
9 changed files with 47 additions and 42 deletions

View File

@ -13,6 +13,8 @@ extern const char* CONFIRM_EXTENSION_OVERWRITE;
extern const char* EXTENSION_WRITE_ERROR; extern const char* EXTENSION_WRITE_ERROR;
extern const char* EXTEN_WINDOW_INSTRUCTIONS; extern const char* EXTEN_WINDOW_INSTRUCTIONS;
constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repeated Characters>Remove Repeated Phrases>Regex Filter>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines";
namespace namespace
{ {
struct Extension struct Extension

View File

@ -31,7 +31,7 @@ void TextThread::Stop()
timer = NULL; timer = NULL;
} }
void TextThread::AddSentence(std::wstring&& sentence) void TextThread::AddSentence(std::wstring sentence)
{ {
queuedSentences->emplace_back(std::move(sentence)); queuedSentences->emplace_back(std::move(sentence));
} }

View File

@ -17,7 +17,7 @@ public:
void Start(); void Start();
void Stop(); void Stop();
void AddSentence(std::wstring&& sentence); void AddSentence(std::wstring sentence);
void Push(BYTE* data, int length); void Push(BYTE* data, int length);
Synchronized<std::wstring> storage; Synchronized<std::wstring> storage;

View File

@ -18,7 +18,8 @@ extern const char* SETTINGS;
extern const char* EXTENSIONS; extern const char* EXTENSIONS;
extern const char* SELECT_PROCESS; extern const char* SELECT_PROCESS;
extern const char* ATTACH_INFO; extern const char* ATTACH_INFO;
extern const char* SEARCH_GAME; extern const char* SELECT_PROCESS_INFO;
extern const char* FROM_COMPUTER;
extern const char* PROCESSES; extern const char* PROCESSES;
extern const char* CODE_INFODUMP; extern const char* CODE_INFODUMP;
extern const char* HOOK_SEARCH_UNSTABLE_WARNING; extern const char* HOOK_SEARCH_UNSTABLE_WARNING;
@ -53,7 +54,7 @@ MainWindow::MainWindow(QWidget *parent) :
extenWindow(new ExtenWindow(this)) extenWindow(new ExtenWindow(this))
{ {
ui->setupUi(this); ui->setupUi(this);
for (auto [text, slot] : Array<std::tuple<QString, void(MainWindow::*)()>>{ for (auto [text, slot] : Array<std::tuple<const char*, void(MainWindow::*)()>>{
{ ATTACH, &MainWindow::AttachProcess }, { ATTACH, &MainWindow::AttachProcess },
{ LAUNCH, &MainWindow::LaunchProcess }, { LAUNCH, &MainWindow::LaunchProcess },
{ DETACH, &MainWindow::DetachProcess }, { DETACH, &MainWindow::DetachProcess },
@ -66,9 +67,8 @@ MainWindow::MainWindow(QWidget *parent) :
{ EXTENSIONS, &MainWindow::Extensions } { EXTENSIONS, &MainWindow::Extensions }
}) })
{ {
auto button = new QPushButton(ui->processFrame); auto button = new QPushButton(text, ui->processFrame);
connect(button, &QPushButton::clicked, this, slot); connect(button, &QPushButton::clicked, this, slot);
button->setText(text);
ui->processLayout->addWidget(button); ui->processLayout->addWidget(button);
} }
ui->processLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); ui->processLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
@ -154,7 +154,6 @@ void MainWindow::ProcessConnected(DWORD processId)
QTextFile(GAME_SAVE_FILE, QIODevice::WriteOnly | QIODevice::Append).write((process + "\n").toUtf8()); QTextFile(GAME_SAVE_FILE, QIODevice::WriteOnly | QIODevice::Append).write((process + "\n").toUtf8());
QStringList allProcesses = QString(QTextFile(HOOK_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); QStringList allProcesses = QString(QTextFile(HOOK_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts);
// Can't use QFileInfo::absoluteFilePath since hook save file has '\\' as path separator
auto hookList = std::find_if(allProcesses.rbegin(), allProcesses.rend(), [&](QString hookList) { return hookList.contains(process); }); auto hookList = std::find_if(allProcesses.rbegin(), allProcesses.rend(), [&](QString hookList) { return hookList.contains(process); });
if (hookList != allProcesses.rend()) if (hookList != allProcesses.rend())
for (auto hookInfo : hookList->split(" , ")) for (auto hookInfo : hookList->split(" , "))
@ -173,7 +172,7 @@ void MainWindow::ProcessDisconnected(DWORD processId)
void MainWindow::ThreadAdded(TextThread& thread) void MainWindow::ThreadAdded(TextThread& thread)
{ {
std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId); std::wstring threadCode = Util::GenerateCode(thread.hp, thread.tp.processId);
QString ttString = TextThreadString(thread) + S(thread.name) + " (" + S(threadCode) + ")"; QString ttString = TextThreadString(thread) + S(FormatString(L"(%s)", threadCode));
bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode; bool savedMatch = savedThreadCtx == thread.tp.ctx && savedThreadCtx2 == thread.tp.ctx2 && savedThreadCode == threadCode;
if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0; if (savedMatch) savedThreadCtx = savedThreadCtx2 = savedThreadCode[0] = 0;
QMetaObject::invokeMethod(this, [this, ttString, savedMatch] QMetaObject::invokeMethod(this, [this, ttString, savedMatch]
@ -209,13 +208,13 @@ bool MainWindow::SentenceReceived(TextThread& thread, std::wstring& sentence)
QString MainWindow::TextThreadString(TextThread& thread) QString MainWindow::TextThreadString(TextThread& thread)
{ {
return QString("%1:%2:%3:%4:%5: ").arg( return QString("%1:%2:%3:%4:%5: %6 ").arg(
QString::number(thread.handle, 16), QString::number(thread.handle, 16),
QString::number(thread.tp.processId, 16), QString::number(thread.tp.processId, 16),
QString::number(thread.tp.addr, 16), QString::number(thread.tp.addr, 16),
QString::number(thread.tp.ctx, 16), QString::number(thread.tp.ctx, 16),
QString::number(thread.tp.ctx2, 16) QString::number(thread.tp.ctx2, 16)
).toUpper(); ).toUpper().arg(S(thread.name));
} }
ThreadParam MainWindow::ParseTextThreadString(QString ttString) ThreadParam MainWindow::ParseTextThreadString(QString ttString)
@ -233,9 +232,8 @@ std::array<InfoForExtension, 10> MainWindow::GetMiscInfo(TextThread& thread)
{ {
void(*AddSentence)(MainWindow*, int64_t, const wchar_t*) = [](MainWindow* This, int64_t number, const wchar_t* sentence) void(*AddSentence)(MainWindow*, int64_t, const wchar_t*) = [](MainWindow* This, int64_t number, const wchar_t* sentence)
{ {
std::wstring copy = sentence;
// pointer from Host::GetThread may not stay valid unless on main thread // pointer from Host::GetThread may not stay valid unless on main thread
QMetaObject::invokeMethod(This, [=]() mutable { if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(std::move(copy)); }); QMetaObject::invokeMethod(This, [number, sentence = std::wstring(sentence)] { if (TextThread* thread = Host::GetThread(number)) thread->AddSentence(sentence); });
}; };
return return
@ -252,6 +250,18 @@ std::array<InfoForExtension, 10> MainWindow::GetMiscInfo(TextThread& thread)
} }; } };
} }
std::optional<std::wstring> MainWindow::UserSelectedProcess()
{
QStringList savedProcesses = QString::fromUtf8(QTextFile(GAME_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts);
std::reverse(savedProcesses.begin(), savedProcesses.end());
savedProcesses.removeDuplicates();
savedProcesses.insert(1, FROM_COMPUTER);
QString process = QInputDialog::getItem(this, SELECT_PROCESS, SELECT_PROCESS_INFO, savedProcesses, 0, true, &ok, Qt::WindowCloseButtonHint);
if (process == FROM_COMPUTER) process = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, SELECT_PROCESS, "C:\\", PROCESSES));
if (ok && process.contains('\\')) return S(process);
return {};
}
void MainWindow::AttachProcess() void MainWindow::AttachProcess()
{ {
QMultiHash<QString, DWORD> allProcesses; QMultiHash<QString, DWORD> allProcesses;
@ -267,14 +277,9 @@ void MainWindow::AttachProcess()
void MainWindow::LaunchProcess() void MainWindow::LaunchProcess()
{ {
QStringList savedProcesses = QString::fromUtf8(QTextFile(GAME_SAVE_FILE, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts); std::wstring process;
std::reverse(savedProcesses.begin(), savedProcesses.end()); if (auto selected = UserSelectedProcess()) process = selected.value();
savedProcesses.removeDuplicates(); else return;
savedProcesses.push_back(SEARCH_GAME);
std::wstring process = S(QInputDialog::getItem(this, SELECT_PROCESS, "", savedProcesses, 0, true, &ok, Qt::WindowCloseButtonHint));
if (!ok) return;
if (S(process) == SEARCH_GAME) process = S(QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, SELECT_PROCESS, "C:\\", PROCESSES)));
if (process.find(L'\\') == std::wstring::npos) return;
std::wstring path = std::wstring(process).erase(process.rfind(L'\\')); std::wstring path = std::wstring(process).erase(process.rfind(L'\\'));
PROCESS_INFORMATION info = {}; PROCESS_INFORMATION info = {};
@ -317,16 +322,16 @@ void MainWindow::DetachProcess()
void MainWindow::ForgetProcess() void MainWindow::ForgetProcess()
{ {
if (auto processName = Util::GetModuleFilename(GetSelectedProcessId())) std::optional<std::wstring> processName = Util::GetModuleFilename(GetSelectedProcessId());
{ if (!processName) processName = UserSelectedProcess();
for (auto file : { GAME_SAVE_FILE, HOOK_SAVE_FILE })
{
QStringList lines = QString::fromUtf8(QTextFile(file, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts);
lines.erase(std::remove_if(lines.begin(), lines.end(), [&](auto line) { return line.contains(S(processName.value())); }), lines.end());
QTextFile(file, QIODevice::WriteOnly | QIODevice::Truncate).write(lines.join("\n").toUtf8());
}
}
DetachProcess(); DetachProcess();
if (!processName) return;
for (auto file : { GAME_SAVE_FILE, HOOK_SAVE_FILE })
{
QStringList lines = QString::fromUtf8(QTextFile(file, QIODevice::ReadOnly).readAll()).split("\n", QString::SkipEmptyParts);
lines.erase(std::remove_if(lines.begin(), lines.end(), [&](auto line) { return line.contains(S(processName.value())); }), lines.end());
QTextFile(file, QIODevice::WriteOnly | QIODevice::Truncate).write(lines.join("\n").append("\n").toUtf8());
}
} }
void MainWindow::AddHook() void MainWindow::AddHook()
@ -432,11 +437,7 @@ void MainWindow::FindHooks()
{ {
auto input = new QLineEdit(QString::number(value, 16), &dialog); auto input = new QLineEdit(QString::number(value, 16), &dialog);
layout.addRow(label, input); layout.addRow(label, input);
connect(input, &QLineEdit::textEdited, [&value](QString input) connect(input, &QLineEdit::textEdited, [&value](QString text) { if (uintptr_t newValue = text.toULongLong(&ok, 16); ok) value = newValue; });
{
bool ok;
if (uintptr_t newValue = input.toULongLong(&ok, 16); ok) value = newValue;
});
} }
QLineEdit filterInput(".", &dialog); QLineEdit filterInput(".", &dialog);
layout.addRow(HOOK_SEARCH_FILTER, &filterInput); layout.addRow(HOOK_SEARCH_FILTER, &filterInput);

View File

@ -31,6 +31,7 @@ private:
ThreadParam ParseTextThreadString(QString ttString); ThreadParam ParseTextThreadString(QString ttString);
DWORD GetSelectedProcessId(); DWORD GetSelectedProcessId();
std::array<InfoForExtension, 10> GetMiscInfo(TextThread& thread); std::array<InfoForExtension, 10> GetMiscInfo(TextThread& thread);
std::optional<std::wstring> UserSelectedProcess();
void AttachProcess(); void AttachProcess();
void LaunchProcess(); void LaunchProcess();
void DetachProcess(); void DetachProcess();

View File

@ -80,7 +80,7 @@ private:
QWidget centralWidget{ this }; QWidget centralWidget{ this };
QHBoxLayout layout{ &centralWidget }; QHBoxLayout layout{ &centralWidget };
QPlainTextEdit scriptEditor{ std::string(std::istreambuf_iterator<char>(std::ifstream(LUA_SAVE_FILE, std::ios::in)), {}).c_str(), &centralWidget }; QPlainTextEdit scriptEditor{ S(std::string(std::istreambuf_iterator<char>(std::ifstream(LUA_SAVE_FILE, std::ios::in)), {})), &centralWidget };
QPushButton loadButton{ LOAD_LUA_SCRIPT, &centralWidget }; QPushButton loadButton{ LOAD_LUA_SCRIPT, &centralWidget };
} window; } window;

View File

@ -28,7 +28,6 @@ constexpr auto CONFIG_FILE = u8"Textractor.ini";
// Misc // Misc
constexpr auto DEFAULT_EXTENSIONS = u8"Remove Repeated Characters>Remove Repeated Phrases>Regex Filter>Copy to Clipboard>Bing Translate>Extra Window>Extra Newlines";
constexpr auto WINDOW = u8"Window"; constexpr auto WINDOW = u8"Window";
// EOF // EOF

View File

@ -22,4 +22,5 @@
struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } }; struct QTextFile : QFile { QTextFile(QString name, QIODevice::OpenMode mode) : QFile(name) { open(mode | QIODevice::Text); } };
inline std::wstring S(const QString& S) { return { S.toStdWString() }; } inline std::wstring S(const QString& S) { return { S.toStdWString() }; }
inline QString S(const std::string& S) { return QString::fromStdString(S); }
inline QString S(const std::wstring& S) { return QString::fromStdWString(S); } inline QString S(const std::wstring& S) { return QString::fromStdWString(S); }

View File

@ -19,7 +19,8 @@ const char* EXTENSIONS = u8"Extensions";
const char* SELECT_PROCESS = u8"Select process"; const char* SELECT_PROCESS = u8"Select process";
const char* ATTACH_INFO = u8R"(If you don't see the process you want to attach, try running with admin rights const char* ATTACH_INFO = u8R"(If you don't see the process you want to attach, try running with admin rights
You can also type in the process id)"; You can also type in the process id)";
const char* SEARCH_GAME = u8"Select from computer"; const char* SELECT_PROCESS_INFO = u8"If you manually type in the process file name, please use the absolute path";
const char* FROM_COMPUTER = u8"Select from computer";
const char* PROCESSES = u8"Processes (*.exe)"; const char* PROCESSES = u8"Processes (*.exe)";
const char* CODE_INFODUMP = u8R"(Search for text const char* CODE_INFODUMP = u8R"(Search for text
S[codepage#]text S[codepage#]text
@ -207,7 +208,7 @@ Kaynak kodu GKLv3 koruması altında proje ana sayfasında mevcut
SELECT_PROCESS = u8"Seleccionar procreso"; SELECT_PROCESS = u8"Seleccionar procreso";
ATTACH_INFO = u8R"(Si no ves el proceso que quieras adjuntar, ejecuta este programa como administrador ATTACH_INFO = u8R"(Si no ves el proceso que quieras adjuntar, ejecuta este programa como administrador
También puedes escribir la ID del proceso)"; También puedes escribir la ID del proceso)";
SEARCH_GAME = u8"Seleccionar desde computadora"; FROM_COMPUTER = u8"Seleccionar desde computadora";
PROCESSES = u8"Procesos (*.exe)"; PROCESSES = u8"Procesos (*.exe)";
SAVE_SETTINGS = u8"Guardar opciones"; SAVE_SETTINGS = u8"Guardar opciones";
EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arrrastra y suelta la extension (.dll) aquí desde tu computadora para añadirlos EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arrrastra y suelta la extension (.dll) aquí desde tu computadora para añadirlos
@ -271,7 +272,7 @@ Clic y arrastra los bordes de la ventana para moverla, o en la esquina inferior
SELECT_PROCESS = u8"选择进程"; SELECT_PROCESS = u8"选择进程";
ATTACH_INFO = u8R"(如果没看见想要附加的进程,尝试使用管理员权限运行 ATTACH_INFO = u8R"(如果没看见想要附加的进程,尝试使用管理员权限运行
ID)"; ID)";
SEARCH_GAME = u8"从计算机中选择"; FROM_COMPUTER = u8"从计算机中选择";
PROCESSES = u8"进程 (*.exe)"; PROCESSES = u8"进程 (*.exe)";
SAVE_SETTINGS = u8"保存设置"; SAVE_SETTINGS = u8"保存设置";
EXTEN_WINDOW_INSTRUCTIONS = u8R"(从计算机拖拽扩展 (.dll) 文件到这里来添加 EXTEN_WINDOW_INSTRUCTIONS = u8R"(从计算机拖拽扩展 (.dll) 文件到这里来添加
@ -337,7 +338,7 @@ Clic y arrastra los bordes de la ventana para moverla, o en la esquina inferior
SELECT_PROCESS = u8"Выберете процесс"; SELECT_PROCESS = u8"Выберете процесс";
ATTACH_INFO = u8R"(Если вы не видите процесс, к которому хотите присоединить, попробуйте запуск с правами администратора ATTACH_INFO = u8R"(Если вы не видите процесс, к которому хотите присоединить, попробуйте запуск с правами администратора
Вы также можете ввести id процесса)"; Вы также можете ввести id процесса)";
SEARCH_GAME = u8"Найти в проводнике"; FROM_COMPUTER = u8"Найти в проводнике";
PROCESSES = u8"Процессы (*.exe)"; PROCESSES = u8"Процессы (*.exe)";
SAVE_SETTINGS = u8"Сохранить настройки"; SAVE_SETTINGS = u8"Сохранить настройки";
EXTEN_WINDOW_INSTRUCTIONS = u8R"(Перетащите сюда (.dll) файлы расширений из проводника для их добавления EXTEN_WINDOW_INSTRUCTIONS = u8R"(Перетащите сюда (.dll) файлы расширений из проводника для их добавления
@ -442,7 +443,7 @@ end)";
SELECT_PROCESS = u8"Pilih Proses"; SELECT_PROCESS = u8"Pilih Proses";
ATTACH_INFO = u8R"(Jika kamu tidak dapat melihat proses yang akan ditempelkan, coba menjalankan dengan mode administrator ATTACH_INFO = u8R"(Jika kamu tidak dapat melihat proses yang akan ditempelkan, coba menjalankan dengan mode administrator
Kamu juga dapat mengetik process id game yang akan ditempel)"; Kamu juga dapat mengetik process id game yang akan ditempel)";
SEARCH_GAME = u8"Pilih dari komputer"; FROM_COMPUTER = u8"Pilih dari komputer";
PROCESSES = u8"Proses (*.exe)"; PROCESSES = u8"Proses (*.exe)";
SAVE_SETTINGS = u8"Simpan pengaturan"; SAVE_SETTINGS = u8"Simpan pengaturan";
EXTEN_WINDOW_INSTRUCTIONS = u8R"(Drag and drop file ekstensi (.dll) kedalam sini dari komputer kamu untuk menambah ekstensi EXTEN_WINDOW_INSTRUCTIONS = u8R"(Drag and drop file ekstensi (.dll) kedalam sini dari komputer kamu untuk menambah ekstensi
@ -507,7 +508,7 @@ Klik dan tarik pinggiran jendela untuk memindahkan, atau sudut kanan bawah untuk
EXTENSIONS = u8"Extensões"; EXTENSIONS = u8"Extensões";
SELECT_PROCESS = u8"Selecionar Processo"; SELECT_PROCESS = u8"Selecionar Processo";
ATTACH_INFO = u8R"(Se você não encontrar o processo o qual deseja anexar a, tente iniciar com permissão de Administrador. Você também pode digitar a ID do processo)"; ATTACH_INFO = u8R"(Se você não encontrar o processo o qual deseja anexar a, tente iniciar com permissão de Administrador. Você também pode digitar a ID do processo)";
SEARCH_GAME = u8"Busque no Computador"; FROM_COMPUTER = u8"Busque no Computador";
PROCESSES = u8"Executaveis (*.exe)"; PROCESSES = u8"Executaveis (*.exe)";
SAVE_SETTINGS = u8"Salvar opções"; SAVE_SETTINGS = u8"Salvar opções";
EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arraste e solte a extensão (.dll) aqui para adicioná-la. EXTEN_WINDOW_INSTRUCTIONS = u8R"(Arraste e solte a extensão (.dll) aqui para adicioná-la.