remove unhook button

This commit is contained in:
Akash Mozumdar 2018-11-27 16:57:47 -05:00
parent 026912ca9c
commit 7310f9349b
7 changed files with 8 additions and 77 deletions

View File

@ -146,17 +146,6 @@ namespace Host
CreatePipe();
}
void Close()
{
// Artikash 7/25/2018: This is only called when Textractor is closed, at which point Windows should free everything itself...right?
#ifdef _DEBUG // Check memory leaks
ProcessRecord::OnConnect = ProcessRecord::OnDisconnect = [](auto) {};
TextThread::OnCreate = TextThread::OnDestroy = [](auto) {};
processRecordsByIds->clear();
textThreadsByParams->clear();
#endif
}
bool InjectProcess(DWORD processId, DWORD timeout)
{
if (processId == GetCurrentProcessId()) return false;
@ -209,11 +198,6 @@ namespace Host
processRecordsByIds->at(processId)->Send(InsertHookCmd(hp, name));
}
void RemoveHook(DWORD processId, uint64_t addr)
{
processRecordsByIds->at(processId)->Send(RemoveHookCmd(addr));
}
HookParam GetHookParam(DWORD processId, uint64_t addr)
{
return processRecordsByIds->at(processId)->GetHook(addr).hp;

View File

@ -7,13 +7,10 @@ namespace Host
{
typedef std::function<void(DWORD)> ProcessEventCallback;
void Start(ProcessEventCallback OnConnect, ProcessEventCallback OnDisconnect, TextThread::EventCallback OnCreate, TextThread::EventCallback OnDestroy, TextThread::OutputCallback Output);
void Close();
bool InjectProcess(DWORD processId, DWORD timeout = 5000);
void DetachProcess(DWORD processId);
void InsertHook(DWORD processId, HookParam hp, std::string name = "");
void RemoveHook(DWORD processId, uint64_t addr);
HookParam GetHookParam(DWORD processId, uint64_t addr);
inline HookParam GetHookParam(ThreadParam tp) { return GetHookParam(tp.processId, tp.addr); }

View File

@ -37,7 +37,6 @@ MainWindow::~MainWindow()
{
settings.setValue(WINDOW, geometry());
settings.sync();
Host::Close();
delete ui;
}
@ -152,22 +151,6 @@ std::unordered_map<std::string, int64_t> MainWindow::GetMiscInfo(TextThread* thr
};
}
QVector<HookParam> MainWindow::GetAllHooks(DWORD processId)
{
QSet<uint64_t> addresses;
QVector<HookParam> hooks;
for (int i = 0; i < ttCombo->count(); ++i)
{
ThreadParam tp = ParseTextThreadString(ttCombo->itemText(i));
if (tp.processId == processId && !addresses.contains(tp.addr))
{
addresses.insert(tp.addr);
hooks.push_back(Host::GetHookParam(tp));
}
}
return hooks;
}
void MainWindow::on_attachButton_clicked()
{
auto allProcesses = GetAllProcesses();
@ -194,27 +177,16 @@ void MainWindow::on_hookButton_clicked()
else Host::AddConsoleOutput(INVALID_CODE);
}
void MainWindow::on_unhookButton_clicked()
{
auto hooks = GetAllHooks(GetSelectedProcessId());
if (hooks.empty()) return Host::AddConsoleOutput(NO_HOOKS);
QStringList hookList;
for (auto hp : hooks)
hookList.push_back(
QString::fromStdWString(Host::GetHookName(GetSelectedProcessId(), hp.insertion_address)) +
": " +
GenerateCode(hp, GetSelectedProcessId())
);
bool ok;
QString hook = QInputDialog::getItem(this, UNHOOK, REMOVE_HOOK, hookList, 0, false, &ok, Qt::WindowCloseButtonHint);
if (ok) Host::RemoveHook(GetSelectedProcessId(), hooks.at(hookList.indexOf(hook)).insertion_address);
}
void MainWindow::on_saveButton_clicked()
{
QHash<uint64_t, QString> hookCodes;
for (int i = 0; i < ttCombo->count(); ++i)
{
ThreadParam tp = ParseTextThreadString(ttCombo->itemText(i));
if (tp.processId == GetSelectedProcessId() && !(Host::GetHookParam(tp).type & HOOK_ENGINE)) hookCodes[tp.addr] = GenerateCode(Host::GetHookParam(tp), tp.processId);
}
QString hookList = GetFullModuleName(GetSelectedProcessId());
for (auto hp : GetAllHooks(GetSelectedProcessId()))
if (!(hp.type & HOOK_ENGINE)) hookList += " , " + GenerateCode(hp, GetSelectedProcessId());
for (auto hookCode : hookCodes) hookList += " , " + hookCode;
QAutoFile(HOOK_SAVE_FILE, QIODevice::Append)->write((hookList + "\r\n").toUtf8());
}

View File

@ -24,7 +24,6 @@ public:
private slots:
void on_attachButton_clicked();
void on_detachButton_clicked();
void on_unhookButton_clicked();
void on_hookButton_clicked();
void on_saveButton_clicked();
void on_setButton_clicked();
@ -32,6 +31,7 @@ private slots:
void on_ttCombo_activated(int index);
private:
void closeEvent(QCloseEvent*);
void InvokeOnMainThread(std::function<void()>&& f);
void ProcessConnected(DWORD processId);
void ProcessDisconnected(DWORD processId);
@ -42,8 +42,6 @@ private:
ThreadParam ParseTextThreadString(QString ttString);
DWORD GetSelectedProcessId();
std::unordered_map<std::string, int64_t> GetMiscInfo(TextThread* thread);
QVector<HookParam> GetAllHooks(DWORD processId);
void closeEvent(QCloseEvent*);
Ui::MainWindow* ui;
QSettings settings = QSettings(CONFIG_FILE, QSettings::IniFormat);

View File

@ -87,13 +87,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="unhookButton">
<property name="text">
<string>Remove hook</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">

View File

@ -99,13 +99,6 @@ struct InsertHookCmd // From host
char name[HOOK_NAME_SIZE] = {};
};
struct RemoveHookCmd // From host
{
RemoveHookCmd(uint64_t address) : address(address) {};
int command = HOST_COMMAND_REMOVE_HOOK;
uint64_t address;
};
struct ConsoleOutputNotif // From hook
{
ConsoleOutputNotif(std::string message = "") { strcpy_s<MESSAGE_SIZE>(this->message, message.c_str()); };

View File

@ -71,12 +71,6 @@ DWORD WINAPI Pipe(LPVOID)
NewHook(info.hp, info.name, 0);
}
break;
case HOST_COMMAND_REMOVE_HOOK:
{
auto info = *(RemoveHookCmd*)buffer;
RemoveHook(info.address);
}
break;
case HOST_COMMAND_DETACH:
{
running = false;