This commit is contained in:
Akash Mozumdar 2018-10-10 08:16:14 -04:00
parent effb005376
commit 3b9ca65e39
3 changed files with 19 additions and 28 deletions

View File

@ -7,15 +7,12 @@ std::optional<Extension> LoadExtension(QString file)
// Extension file format: {NUMBER}_{NAME}.dll and exports "OnNewSentence" // Extension file format: {NUMBER}_{NAME}.dll and exports "OnNewSentence"
QRegularExpressionMatch parsedFile = QRegularExpression("^(\\d+)_(.+).dll$").match(file); QRegularExpressionMatch parsedFile = QRegularExpression("^(\\d+)_(.+).dll$").match(file);
if (!parsedFile.hasMatch()) return {}; if (!parsedFile.hasMatch()) return {};
HMODULE module = GetModuleHandleW(file.toStdWString().c_str()); HMODULE module = GetModuleHandleW(file.toStdWString().c_str());
if (!module) module = LoadLibraryW(file.toStdWString().c_str()); if (!module) module = LoadLibraryW(file.toStdWString().c_str());
if (!module) return {}; if (!module) return {};
FARPROC callback = GetProcAddress(module, "OnNewSentence");
auto callback = (wchar_t*(*)(const wchar_t*, const InfoForExtension*))GetProcAddress(module, "OnNewSentence");
if (!callback) return {}; if (!callback) return {};
return Extension{ parsedFile.captured(1).toInt(), parsedFile.captured(2), (wchar_t*(*)(const wchar_t*, const InfoForExtension*))callback };
return Extension{ parsedFile.captured(1).toInt(), parsedFile.captured(2), callback };
} }
std::shared_mutex extenMutex; std::shared_mutex extenMutex;
@ -27,7 +24,6 @@ std::set<Extension> LoadExtensions()
QStringList files = QDir().entryList(); QStringList files = QDir().entryList();
for (auto file : files) for (auto file : files)
if (auto extension = LoadExtension(file)) newExtensions.insert(extension.value()); if (auto extension = LoadExtension(file)) newExtensions.insert(extension.value());
std::unique_lock<std::shared_mutex> extenLock(extenMutex); std::unique_lock<std::shared_mutex> extenLock(extenMutex);
return extensions = newExtensions; return extensions = newExtensions;
} }

View File

@ -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. //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); 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) void RegisterProcess(DWORD pid, HANDLE hostPipe)

View File

@ -54,14 +54,12 @@ void MainWindow::AddProcess(unsigned processId)
QFile file("SavedHooks.txt"); QFile file("SavedHooks.txt");
if (!file.open(QIODevice::ReadOnly)) return; if (!file.open(QIODevice::ReadOnly)) return;
QString processName = GetFullModuleName(processId); QString processName = GetFullModuleName(processId);
QString allData = file.readAll(); QStringList allProcesses = QString(file.readAll()).split("\r", QString::SkipEmptyParts);
QStringList allProcesses = allData.split("\r", QString::SkipEmptyParts); for (auto hooks = allProcesses.rbegin(); hooks != allProcesses.rend(); ++hooks)
for (int i = allProcesses.size() - 1; i >= 0; --i) if (hooks->contains(processName))
if (allProcesses[i].contains(processName))
{ {
QStringList hooks = allProcesses[i].split(" , "); for (auto hook : hooks->split(" , "))
for (int j = 1; j < hooks.size(); ++j) if (auto hp = ParseCode(hook)) Host::InsertHook(processId, hp.value());
Host::InsertHook(processId, ParseCode(hooks[j]).value_or(HookParam()));
return; return;
} }
} }
@ -185,7 +183,7 @@ void MainWindow::on_attachButton_clicked()
bool injected = false; bool injected = false;
if (!ok) return; if (!ok) return;
if (process.toInt(nullptr, 0)) injected |= Host::InjectProcess(process.toInt(nullptr, 0)); 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"); if (!injected) Host::AddConsoleOutput(L"failed to inject");
} }
@ -206,16 +204,13 @@ void MainWindow::on_hookButton_clicked()
void MainWindow::on_unhookButton_clicked() void MainWindow::on_unhookButton_clicked()
{ {
QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId()); QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId());
if (hooks.size() == 0) if (hooks.size() == 0) return Host::AddConsoleOutput(L"no hooks detected");
{
Host::AddConsoleOutput(L"no hooks detected");
return;
}
QStringList hookList; QStringList hookList;
for (auto i : hooks) hookList.push_back( for (auto hook : hooks)
QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), i.address)) + hookList.push_back(
QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), hook.address)) +
": " + ": " +
GenerateCode(i, GetSelectedProcessId()) GenerateCode(hook, GetSelectedProcessId())
); );
bool ok; bool ok;
QString hook = QInputDialog::getItem(this, "Unhook", "Which hook to remove?", hookList, 0, false, &ok); QString hook = QInputDialog::getItem(this, "Unhook", "Which hook to remove?", hookList, 0, false, &ok);
@ -226,9 +221,9 @@ void MainWindow::on_saveButton_clicked()
{ {
QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId()); QVector<HookParam> hooks = GetAllHooks(GetSelectedProcessId());
QString hookList = GetFullModuleName(GetSelectedProcessId()); QString hookList = GetFullModuleName(GetSelectedProcessId());
for (auto i : hooks) for (auto hook : hooks)
if (!(i.type & HOOK_ENGINE)) if (!(hook.type & HOOK_ENGINE))
hookList += " , " + GenerateCode(i, GetSelectedProcessId()); hookList += " , " + GenerateCode(hook, GetSelectedProcessId());
QFile file("SavedHooks.txt"); QFile file("SavedHooks.txt");
if (!file.open(QIODevice::Append | QIODevice::Text)) return; if (!file.open(QIODevice::Append | QIODevice::Text)) return;
file.write((hookList + "\r\n").toUtf8()); file.write((hookList + "\r\n").toUtf8());