forked from Public-Mirror/Textractor
refactor
This commit is contained in:
parent
effb005376
commit
3b9ca65e39
@ -7,15 +7,12 @@ std::optional<Extension> LoadExtension(QString file)
|
||||
// Extension file format: {NUMBER}_{NAME}.dll and exports "OnNewSentence"
|
||||
QRegularExpressionMatch parsedFile = QRegularExpression("^(\\d+)_(.+).dll$").match(file);
|
||||
if (!parsedFile.hasMatch()) return {};
|
||||
|
||||
HMODULE module = GetModuleHandleW(file.toStdWString().c_str());
|
||||
if (!module) module = LoadLibraryW(file.toStdWString().c_str());
|
||||
if (!module) return {};
|
||||
|
||||
auto callback = (wchar_t*(*)(const wchar_t*, const InfoForExtension*))GetProcAddress(module, "OnNewSentence");
|
||||
FARPROC callback = GetProcAddress(module, "OnNewSentence");
|
||||
if (!callback) return {};
|
||||
|
||||
return Extension{ parsedFile.captured(1).toInt(), parsedFile.captured(2), callback };
|
||||
return Extension{ parsedFile.captured(1).toInt(), parsedFile.captured(2), (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback };
|
||||
}
|
||||
|
||||
std::shared_mutex extenMutex;
|
||||
@ -27,7 +24,6 @@ std::set<Extension> LoadExtensions()
|
||||
QStringList files = QDir().entryList();
|
||||
for (auto file : files)
|
||||
if (auto extension = LoadExtension(file)) newExtensions.insert(extension.value());
|
||||
|
||||
std::unique_lock<std::shared_mutex> extenLock(extenMutex);
|
||||
return extensions = newExtensions;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ namespace
|
||||
//delete i.second; // Artikash 7/24/2018: FIXME: Qt GUI updates on another thread, so I can't delete this yet.
|
||||
removedThreads.push_back(i.first);
|
||||
}
|
||||
for (auto i : removedThreads) textThreadsByParams.erase(i);
|
||||
for (auto thread : removedThreads) textThreadsByParams.erase(thread);
|
||||
}
|
||||
|
||||
void RegisterProcess(DWORD pid, HANDLE hostPipe)
|
||||
|
@ -54,14 +54,12 @@ void MainWindow::AddProcess(unsigned processId)
|
||||
QFile file("SavedHooks.txt");
|
||||
if (!file.open(QIODevice::ReadOnly)) return;
|
||||
QString processName = GetFullModuleName(processId);
|
||||
QString allData = file.readAll();
|
||||
QStringList allProcesses = allData.split("\r", QString::SkipEmptyParts);
|
||||
for (int i = allProcesses.size() - 1; i >= 0; --i)
|
||||
if (allProcesses[i].contains(processName))
|
||||
QStringList allProcesses = QString(file.readAll()).split("\r", QString::SkipEmptyParts);
|
||||
for (auto hooks = allProcesses.rbegin(); hooks != allProcesses.rend(); ++hooks)
|
||||
if (hooks->contains(processName))
|
||||
{
|
||||
QStringList hooks = allProcesses[i].split(" , ");
|
||||
for (int j = 1; j < hooks.size(); ++j)
|
||||
Host::InsertHook(processId, ParseCode(hooks[j]).value_or(HookParam()));
|
||||
for (auto hook : hooks->split(" , "))
|
||||
if (auto hp = ParseCode(hook)) Host::InsertHook(processId, hp.value());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -185,7 +183,7 @@ void MainWindow::on_attachButton_clicked()
|
||||
bool injected = false;
|
||||
if (!ok) return;
|
||||
if (process.toInt(nullptr, 0)) injected |= Host::InjectProcess(process.toInt(nullptr, 0));
|
||||
else for (auto i : allProcesses.values(process)) injected |= Host::InjectProcess(i);
|
||||
else for (auto processId : allProcesses.values(process)) injected |= Host::InjectProcess(processId);
|
||||
if (!injected) Host::AddConsoleOutput(L"failed to inject");
|
||||
}
|
||||
|
||||
@ -206,17 +204,14 @@ void MainWindow::on_hookButton_clicked()
|
||||
void MainWindow::on_unhookButton_clicked()
|
||||
{
|
||||
QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId());
|
||||
if (hooks.size() == 0)
|
||||
{
|
||||
Host::AddConsoleOutput(L"no hooks detected");
|
||||
return;
|
||||
}
|
||||
if (hooks.size() == 0) return Host::AddConsoleOutput(L"no hooks detected");
|
||||
QStringList hookList;
|
||||
for (auto i : hooks) hookList.push_back(
|
||||
QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), i.address)) +
|
||||
": " +
|
||||
GenerateCode(i, GetSelectedProcessId())
|
||||
);
|
||||
for (auto hook : hooks)
|
||||
hookList.push_back(
|
||||
QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), hook.address)) +
|
||||
": " +
|
||||
GenerateCode(hook, GetSelectedProcessId())
|
||||
);
|
||||
bool ok;
|
||||
QString hook = QInputDialog::getItem(this, "Unhook", "Which hook to remove?", hookList, 0, false, &ok);
|
||||
if (ok) Host::RemoveHook(GetSelectedProcessId(), hooks.at(hookList.indexOf(hook)).address);
|
||||
@ -226,9 +221,9 @@ void MainWindow::on_saveButton_clicked()
|
||||
{
|
||||
QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId());
|
||||
QString hookList = GetFullModuleName(GetSelectedProcessId());
|
||||
for (auto i : hooks)
|
||||
if (!(i.type & HOOK_ENGINE))
|
||||
hookList += " , " + GenerateCode(i, GetSelectedProcessId());
|
||||
for (auto hook : hooks)
|
||||
if (!(hook.type & HOOK_ENGINE))
|
||||
hookList += " , " + GenerateCode(hook, GetSelectedProcessId());
|
||||
QFile file("SavedHooks.txt");
|
||||
if (!file.open(QIODevice::Append | QIODevice::Text)) return;
|
||||
file.write((hookList + "\r\n").toUtf8());
|
||||
|
Loading…
x
Reference in New Issue
Block a user