From c32066e43cabe10766168ee5e6c65d0edec9f41b Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 4 Aug 2018 03:16:14 -0400 Subject: [PATCH] make host play nice with larger addresses, and more refactoring --- GUI/extensions.h | 1 - GUI/mainwindow.cpp | 17 +++++++++++++---- GUI/mainwindow.h | 1 + GUI/misc.cpp | 18 ++++++++++-------- host/host.h | 2 +- host/textthread.h | 6 +++--- vnrhook/include/types.h | 2 +- 7 files changed, 29 insertions(+), 18 deletions(-) diff --git a/GUI/extensions.h b/GUI/extensions.h index 54eae66..fb9b27c 100644 --- a/GUI/extensions.h +++ b/GUI/extensions.h @@ -17,6 +17,5 @@ struct InfoForExtension InfoForExtension* nextProperty; }; typedef const wchar_t*(*ExtensionFunction)(const wchar_t*, const InfoForExtension*); -extern QComboBox* ttCombo; #endif // EXTENSIONS_H diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index e333b25..b343013 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -117,10 +117,7 @@ void MainWindow::AddThread(TextThread* thread) ); thread->RegisterOutputCallBack([&](TextThread* thread, std::wstring output) { - output = DispatchSentenceToExtensions(output, - { - { "current select", ttCombo->currentText().split(":")[0].toInt() == thread->Number() ? 1 : 0 } - }); + output = DispatchSentenceToExtensions(output, GetInfoForExtensions(thread)); emit ThreadOutputReceived(thread, QString::fromWCharArray(output.c_str())); return output; }); @@ -147,6 +144,18 @@ void MainWindow::ThreadOutput(TextThread* thread, QString output) } } +std::unordered_map MainWindow::GetInfoForExtensions(TextThread* thread) +{ + return + { + { "current select", ttCombo->currentText().split(":")[0].toInt() == thread->Number() ? 1 : 0 }, + { "text number", thread->Number() }, + { "process id", thread->GetThreadParameter().pid }, + { "hook address", (int)thread->GetThreadParameter().hook }, + { "hook address (upper 32 bits)", (int)(thread->GetThreadParameter().hook >> 32) } + }; +} + QVector MainWindow::GetAllHooks(DWORD processId) { std::unordered_set addresses; diff --git a/GUI/mainwindow.h b/GUI/mainwindow.h index 5e0ade7..a3e0f71 100644 --- a/GUI/mainwindow.h +++ b/GUI/mainwindow.h @@ -41,6 +41,7 @@ private slots: void on_rmvExtenButton_clicked(); private: + std::unordered_map GetInfoForExtensions(TextThread* thread); QVector GetAllHooks(DWORD processId); Ui::MainWindow *ui; diff --git a/GUI/misc.cpp b/GUI/misc.cpp index fc4336f..56d8c98 100644 --- a/GUI/misc.cpp +++ b/GUI/misc.cpp @@ -113,9 +113,9 @@ HookParam ParseHCode(QString HCode) hp.type |= MODULE_OFFSET; hp.module = Hash(HCode); } - if (hp.offset & 0x80000000) + if (hp.offset < 0) hp.offset -= 4; - if (hp.split & 0x80000000) + if (hp.split < 0) hp.split -= 4; return hp; } @@ -143,27 +143,29 @@ QString GenerateHCode(HookParam hp, DWORD processId) } if (hp.type & NO_CONTEXT) code += "N"; - if (hp.offset >> 31) - code += "-" + QString::number(-(hp.offset + 4), 16); + if (hp.offset < 0) hp.offset += 4; + if (hp.split < 0) hp.split += 4; + if (hp.offset < 0) + code += "-" + QString::number(-hp.offset, 16); else code += QString::number(hp.offset, 16); if (hp.type & DATA_INDIRECT) { - if (hp.index >> 31) + if (hp.index < 0) code += "*-" + QString::number(-hp.index, 16); else code += "*" + QString::number(hp.index, 16); } if (hp.type & USING_SPLIT) { - if (hp.split >> 31) - code += ":-" + QString::number(-(hp.split + 4), 16); + if (hp.split < 0) + code += ":-" + QString::number(-hp.split, 16); else code += ":" + QString::number(hp.split, 16); } if (hp.type & SPLIT_INDIRECT) { - if (hp.split_index >> 31) + if (hp.split_index < 0) code += "*-" + QString::number(-hp.split_index, 16); else code += "*" + QString::number(hp.split_index, 16); diff --git a/host/host.h b/host/host.h index 48b8667..4410244 100644 --- a/host/host.h +++ b/host/host.h @@ -28,7 +28,7 @@ struct ThreadParameterHasher { size_t operator()(const ThreadParameter& tp) const { - return std::hash()(tp.pid << 6) + std::hash()(tp.hook) + std::hash()(tp.retn) + std::hash()(tp.spl); + return std::hash<__int64>()(tp.pid << 6) + std::hash<__int64>()(tp.hook) + std::hash<__int64>()(tp.retn) + std::hash<__int64>()(tp.spl); } }; diff --git a/host/textthread.h b/host/textthread.h index 161a70d..dc05fa8 100644 --- a/host/textthread.h +++ b/host/textthread.h @@ -12,9 +12,9 @@ struct ThreadParameter { DWORD pid; // jichi: 5/11/2014: The process ID - DWORD hook; // Artikash 6/6/2018: The start address of the hook - DWORD retn; // jichi 5/11/2014: The return address of the hook - DWORD spl; // jichi 5/11/2014: the processed split value of the hook paramete + unsigned __int64 hook; // Artikash 6/6/2018: The start address of the hook + unsigned __int64 retn; // jichi 5/11/2014: The return address of the hook + __int64 spl; // jichi 5/11/2014: the processed split value of the hook paramete // Artikash 5/31/2018: required for unordered_map to work with struct key friend bool operator==(const ThreadParameter& one, const ThreadParameter& two) diff --git a/vnrhook/include/types.h b/vnrhook/include/types.h index 6d9e2db..4f870f9 100644 --- a/vnrhook/include/types.h +++ b/vnrhook/include/types.h @@ -77,7 +77,7 @@ struct Hook { // size: 0x80 BYTE recover[0x68 - sizeof(HookParam)]; BYTE original[0x10]; - DWORD Address() const { return hp.address; } + unsigned __int64 Address() const { return hp.address; } DWORD Type() const { return hp.type; } WORD Length() const { return hp.hook_len; } LPSTR Name() const { return hook_name; }