refactor error handling

This commit is contained in:
Akash Mozumdar 2018-11-04 17:12:25 -05:00
parent a48815e9f4
commit 46ffaf017c
3 changed files with 6 additions and 8 deletions

View File

@ -44,7 +44,7 @@ namespace
WinMutex sectionMutex;
};
ThreadEventCallback OnCreate, OnRemove;
ThreadEventCallback OnCreate, OnDestroy;
ProcessEventCallback OnAttach, OnDetach;
std::unordered_map<ThreadParam, std::shared_ptr<TextThread>> textThreadsByParams;
@ -72,7 +72,7 @@ namespace
for (auto it = textThreadsByParams.begin(); it != textThreadsByParams.end();)
if (auto curr = it++; removeIf(curr->first))
{
OnRemove(curr->second);
OnDestroy(curr->second);
textThreadsByParams.erase(curr->first);
}
}
@ -172,9 +172,10 @@ namespace
namespace Host
{
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove, TextThread::OutputCallback output)
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onDestroy, TextThread::OutputCallback output)
{
OnAttach = onAttach; OnDetach = onDetach; OnCreate = onCreate; OnRemove = onRemove; TextThread::Output = output;
OnAttach = onAttach; OnDetach = onDetach; OnCreate = onCreate; OnDestroy = onDestroy; TextThread::Output = output;
RegisterProcess(CONSOLE.pid, INVALID_HANDLE_VALUE);
OnCreate(textThreadsByParams[CONSOLE] = std::make_shared<TextThread>(CONSOLE, HookParam{}, L"Console"));
OnCreate(textThreadsByParams[CLIPBOARD] = std::make_shared<TextThread>(CLIPBOARD, HookParam{}, L"Clipboard"));
StartCapturingClipboard();

View File

@ -12,7 +12,7 @@ typedef std::function<void(std::shared_ptr<TextThread>)> ThreadEventCallback;
namespace Host
{
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove, TextThread::OutputCallback output);
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onDestroy, TextThread::OutputCallback output);
void Close();
bool InjectProcess(DWORD processId, DWORD timeout = 5000);

View File

@ -161,7 +161,6 @@ QVector<HookParam> MainWindow::GetAllHooks(DWORD processId)
{
QSet<uint64_t> addresses;
QVector<HookParam> hooks;
if (!processId) return hooks;
for (int i = 0; i < ttCombo->count(); ++i)
{
ThreadParam tp = ParseTextThreadString(ttCombo->itemText(i));
@ -188,7 +187,6 @@ void MainWindow::on_attachButton_clicked()
void MainWindow::on_detachButton_clicked()
{
if (processCombo->count() == 0) return;
Host::DetachProcess(GetSelectedProcessId());
}
@ -197,7 +195,6 @@ void MainWindow::on_hookButton_clicked()
bool ok;
QString hookCode = QInputDialog::getText(this, ADD_HOOK, CODE_INFODUMP, QLineEdit::Normal, "", &ok, Qt::WindowCloseButtonHint);
if (!ok) return;
if (processCombo->count() == 0) return;
if (auto hp = ParseCode(hookCode)) Host::InsertHook(GetSelectedProcessId(), hp.value());
else Host::AddConsoleOutput(INVALID_CODE);
}