From aa2d71a0786cc29d0f2b9cb8d96569d5f7a49eb4 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Wed, 31 Oct 2018 20:09:29 -0400 Subject: [PATCH] clean up some definitions --- GUI/host/host.cc | 4 ++-- GUI/mainwindow.cpp | 3 ++- include/defs.h | 4 ++-- vnrhook/main.cc | 2 -- vnrhook/pipe.cc | 9 +++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/GUI/host/host.cc b/GUI/host/host.cc index 749d27f..1f8bb64 100644 --- a/GUI/host/host.cc +++ b/GUI/host/host.cc @@ -99,8 +99,8 @@ namespace InitializeSecurityDescriptor(&pipeSD, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&pipeSD, TRUE, NULL, FALSE); // Allow non-admin processes to connect to pipe created by admin host SECURITY_ATTRIBUTES pipeSA = { sizeof(SECURITY_ATTRIBUTES), &pipeSD, FALSE }; - HANDLE hookPipe = CreateNamedPipeW(ITH_TEXT_PIPE, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, PIPE_BUFFER_SIZE, PIPE_BUFFER_SIZE, MAXDWORD, &pipeSA); - HANDLE hostPipe = CreateNamedPipeW(ITH_COMMAND_PIPE, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, PIPE_BUFFER_SIZE, PIPE_BUFFER_SIZE, MAXDWORD, &pipeSA); + HANDLE hookPipe = CreateNamedPipeW(HOOK_PIPE, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, 0, PIPE_BUFFER_SIZE, MAXDWORD, &pipeSA); + HANDLE hostPipe = CreateNamedPipeW(HOST_PIPE, PIPE_ACCESS_OUTBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, PIPE_UNLIMITED_INSTANCES, PIPE_BUFFER_SIZE, 0, MAXDWORD, &pipeSA); ConnectNamedPipe(hookPipe, nullptr); BYTE buffer[PIPE_BUFFER_SIZE + 1] = {}; diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index b7f6a71..e094c76 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "defs.h" #include "extensions.h" #include "misc.h" #include @@ -26,7 +27,7 @@ MainWindow::MainWindow(QWidget *parent) : else { for (auto file : QDir().entryList()) - if (file.endsWith(".dll") && file != "vnrhook.dll") Extension::Load(file.left(file.lastIndexOf(".dll"))); + if (file.endsWith(".dll") && file != ITH_DLL) Extension::Load(file.left(file.lastIndexOf(".dll"))); } ReloadExtensions(); diff --git a/include/defs.h b/include/defs.h index b3df3a7..da11226 100644 --- a/include/defs.h +++ b/include/defs.h @@ -7,8 +7,8 @@ // Pipes -#define ITH_TEXT_PIPE L"\\\\.\\pipe\\VNR_TEXT" -#define ITH_COMMAND_PIPE L"\\\\.\\pipe\\VNR_COMMAND" +#define HOOK_PIPE L"\\\\.\\pipe\\TEXTRACTOR_HOOK" +#define HOST_PIPE L"\\\\.\\pipe\\TEXTRACTOR_HOST" // Sections diff --git a/vnrhook/main.cc b/vnrhook/main.cc index 972333f..72143ac 100644 --- a/vnrhook/main.cc +++ b/vnrhook/main.cc @@ -52,8 +52,6 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID) for (TextHook *man = ::hookman; man < ::hookman + MAX_HOOK; man++) if (man->hp.insertion_address) man->ClearHook(); //if (ith_has_section) UnmapViewOfFile(::hookman); - - CloseHandle(::hookPipe); CloseHandle(hSection); //} ITH_EXCEPT {} } diff --git a/vnrhook/pipe.cc b/vnrhook/pipe.cc index 766b64e..5572d1c 100644 --- a/vnrhook/pipe.cc +++ b/vnrhook/pipe.cc @@ -23,7 +23,6 @@ void CreatePipe() { CreateThread(nullptr, 0, [](LPVOID) { - enum { STANDARD_WAIT = 50 }; while (::running) { DWORD count = 0; @@ -34,15 +33,16 @@ void CreatePipe() { if (::hookPipe == INVALID_HANDLE_VALUE) { - ::hookPipe = CreateFileW(ITH_TEXT_PIPE, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + ::hookPipe = CreateFileW(HOOK_PIPE, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); } if (::hookPipe != INVALID_HANDLE_VALUE && hostPipe == INVALID_HANDLE_VALUE) { - hostPipe = CreateFileW(ITH_COMMAND_PIPE, GENERIC_READ | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + hostPipe = CreateFileW(HOST_PIPE, GENERIC_READ | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); DWORD mode = PIPE_READMODE_MESSAGE; SetNamedPipeHandleState(hostPipe, &mode, NULL, NULL); + continue; } - Sleep(STANDARD_WAIT); + Sleep(50); } *(DWORD*)buffer = GetCurrentProcessId(); @@ -78,6 +78,7 @@ void CreatePipe() } CloseHandle(hostPipe); + CloseHandle(::hookPipe); } FreeLibraryAndExitThread(GetModuleHandleW(ITH_DLL), 0); return (DWORD)0;