cleanup
This commit is contained in:
parent
494fcd24c3
commit
7cdbd93dcb
@ -43,8 +43,7 @@ namespace
|
|||||||
static_assert(sizeof(data) < PIPE_BUFFER_SIZE);
|
static_assert(sizeof(data) < PIPE_BUFFER_SIZE);
|
||||||
std::thread([=]
|
std::thread([=]
|
||||||
{
|
{
|
||||||
DWORD DUMMY;
|
WriteFile(pipe, &data, sizeof(data), DUMMY, nullptr);
|
||||||
WriteFile(pipe, &data, sizeof(data), &DUMMY, nullptr);
|
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +92,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
current = &Host::GetThread(Host::console);
|
current = &Host::GetThread(Host::console);
|
||||||
Host::AddConsoleOutput(ABOUT);
|
Host::AddConsoleOutput(ABOUT);
|
||||||
|
|
||||||
DWORD DUMMY;
|
|
||||||
AttachConsole(ATTACH_PARENT_PROCESS);
|
AttachConsole(ATTACH_PARENT_PROCESS);
|
||||||
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), CL_OPTIONS, wcslen(CL_OPTIONS), &DUMMY, NULL);
|
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), CL_OPTIONS, wcslen(CL_OPTIONS), DUMMY, NULL);
|
||||||
std::vector<DWORD> processIds = Util::GetAllProcessIds();
|
std::vector<DWORD> processIds = Util::GetAllProcessIds();
|
||||||
std::vector<std::wstring> processNames;
|
std::vector<std::wstring> processNames;
|
||||||
for (auto processId : processIds) processNames.emplace_back(Util::GetModuleFilename(processId).value_or(L""));
|
for (auto processId : processIds) processNames.emplace_back(Util::GetModuleFilename(processId).value_or(L""));
|
||||||
@ -116,10 +115,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
if (InternetHandle request = WinHttpOpenRequest(connection, L"GET", L"/repos/Artikash/Textractor/releases", NULL, NULL, NULL, WINHTTP_FLAG_SECURE))
|
if (InternetHandle request = WinHttpOpenRequest(connection, L"GET", L"/repos/Artikash/Textractor/releases", NULL, NULL, NULL, WINHTTP_FLAG_SECURE))
|
||||||
if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL))
|
if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL))
|
||||||
{
|
{
|
||||||
DWORD bytesRead;
|
char buffer[1000] = {};
|
||||||
char buffer[2000] = {};
|
|
||||||
WinHttpReceiveResponse(request, NULL);
|
WinHttpReceiveResponse(request, NULL);
|
||||||
WinHttpReadData(request, buffer, 1000, &bytesRead);
|
WinHttpReadData(request, buffer, 1000, DUMMY);
|
||||||
if (abs(strstr(buffer, "/tag/") - strstr(buffer, VERSION)) > 10) MESSAGE(UPDATE_AVAILABLE);
|
if (abs(strstr(buffer, "/tag/") - strstr(buffer, VERSION)) > 10) MESSAGE(UPDATE_AVAILABLE);
|
||||||
}
|
}
|
||||||
}).detach();
|
}).detach();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
#include <cwctype>
|
#include <cwctype>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <atomic>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
|
|
||||||
|
@ -6,11 +6,10 @@ class RateLimiter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RateLimiter(int requests, int delay) : requestsLeft(requests), delay(delay) {}
|
RateLimiter(int requests, int delay) : requestsLeft(requests), delay(delay) {}
|
||||||
bool Request() { CreateTimerQueueTimer(&DUMMY, timerQueue, [](void* This, BOOLEAN) { ((RateLimiter*)This)->requestsLeft += 1; }, this, delay, 0, 0); return --requestsLeft > 0; }
|
bool Request() { CreateTimerQueueTimer(DUMMY, timerQueue, [](void* This, BOOLEAN) { ((RateLimiter*)This)->requestsLeft += 1; }, this, delay, 0, 0); return --requestsLeft > 0; }
|
||||||
int delay;
|
int delay;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline static HANDLE DUMMY;
|
|
||||||
std::atomic<int> requestsLeft;
|
std::atomic<int> requestsLeft;
|
||||||
AutoHandle<Functor<DeleteTimerQueue>> timerQueue = CreateTimerQueue();
|
AutoHandle<Functor<DeleteTimerQueue>> timerQueue = CreateTimerQueue();
|
||||||
};
|
};
|
||||||
|
@ -72,6 +72,13 @@ private:
|
|||||||
std::unique_ptr<void, HandleCleaner> h;
|
std::unique_ptr<void, HandleCleaner> h;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline struct
|
||||||
|
{
|
||||||
|
BYTE DUMMY[100];
|
||||||
|
template <typename T>
|
||||||
|
operator T*() { static_assert(sizeof(T) < sizeof(DUMMY)); return (T*)DUMMY; }
|
||||||
|
} DUMMY;
|
||||||
|
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 4996)
|
#pragma warning(disable: 4996)
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
|
@ -25,7 +25,6 @@ namespace
|
|||||||
uint64_t addressCharCache[CACHE_SIZE] = {};
|
uint64_t addressCharCache[CACHE_SIZE] = {};
|
||||||
long sumCache[CACHE_SIZE] = {};
|
long sumCache[CACHE_SIZE] = {};
|
||||||
|
|
||||||
DWORD DUMMY;
|
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
BYTE trampoline[32] =
|
BYTE trampoline[32] =
|
||||||
{
|
{
|
||||||
@ -171,7 +170,7 @@ void SearchForHooks(SearchParam sp)
|
|||||||
}), addresses.end());
|
}), addresses.end());
|
||||||
*(void**)(trampoline + send_offset) = Send;
|
*(void**)(trampoline + send_offset) = Send;
|
||||||
auto trampolines = (decltype(trampoline)*)VirtualAlloc(NULL, sizeof(trampoline) * addresses.size(), MEM_COMMIT, PAGE_READWRITE);
|
auto trampolines = (decltype(trampoline)*)VirtualAlloc(NULL, sizeof(trampoline) * addresses.size(), MEM_COMMIT, PAGE_READWRITE);
|
||||||
VirtualProtect(trampolines, addresses.size() * sizeof(trampoline), PAGE_EXECUTE_READWRITE, &DUMMY);
|
VirtualProtect(trampolines, addresses.size() * sizeof(trampoline), PAGE_EXECUTE_READWRITE, DUMMY);
|
||||||
for (int i = 0; i < addresses.size(); ++i)
|
for (int i = 0; i < addresses.size(); ++i)
|
||||||
{
|
{
|
||||||
void* original;
|
void* original;
|
||||||
|
@ -27,7 +27,6 @@ namespace
|
|||||||
TextHook (*hooks)[MAX_HOOK];
|
TextHook (*hooks)[MAX_HOOK];
|
||||||
bool running;
|
bool running;
|
||||||
int currentHook = 0;
|
int currentHook = 0;
|
||||||
DWORD DUMMY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD WINAPI Pipe(LPVOID)
|
DWORD WINAPI Pipe(LPVOID)
|
||||||
@ -91,7 +90,7 @@ void TextOutput(ThreadParam tp, BYTE* text, int len)
|
|||||||
BYTE buffer[PIPE_BUFFER_SIZE] = {};
|
BYTE buffer[PIPE_BUFFER_SIZE] = {};
|
||||||
*(ThreadParam*)buffer = tp;
|
*(ThreadParam*)buffer = tp;
|
||||||
memcpy(buffer + sizeof(tp), text, len);
|
memcpy(buffer + sizeof(tp), text, len);
|
||||||
WriteFile(hookPipe, buffer, sizeof(tp) + len, &DUMMY, nullptr);
|
WriteFile(hookPipe, buffer, sizeof(tp) + len, DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleOutput(LPCSTR text, ...)
|
void ConsoleOutput(LPCSTR text, ...)
|
||||||
@ -100,7 +99,7 @@ void ConsoleOutput(LPCSTR text, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, text);
|
va_start(args, text);
|
||||||
vsnprintf(buffer.message, MESSAGE_SIZE, text, args);
|
vsnprintf(buffer.message, MESSAGE_SIZE, text, args);
|
||||||
WriteFile(hookPipe, &buffer, sizeof(buffer), &DUMMY, nullptr);
|
WriteFile(hookPipe, &buffer, sizeof(buffer), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyHookFound(uint64_t addr, int offset, wchar_t* text)
|
void NotifyHookFound(uint64_t addr, int offset, wchar_t* text)
|
||||||
@ -110,14 +109,14 @@ void NotifyHookFound(uint64_t addr, int offset, wchar_t* text)
|
|||||||
hp.type = USING_UNICODE | USING_STRING;
|
hp.type = USING_UNICODE | USING_STRING;
|
||||||
hp.address = addr;
|
hp.address = addr;
|
||||||
HookFoundNotif buffer(hp, text);
|
HookFoundNotif buffer(hp, text);
|
||||||
WriteFile(hookPipe, &buffer, sizeof(buffer), &DUMMY, nullptr);
|
WriteFile(hookPipe, &buffer, sizeof(buffer), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyHookRemove(uint64_t addr, LPCSTR name)
|
void NotifyHookRemove(uint64_t addr, LPCSTR name)
|
||||||
{
|
{
|
||||||
if (name) ConsoleOutput(REMOVING_HOOK, name);
|
if (name) ConsoleOutput(REMOVING_HOOK, name);
|
||||||
HookRemovedNotif buffer(addr);
|
HookRemovedNotif buffer(addr);
|
||||||
WriteFile(hookPipe, &buffer, sizeof(buffer), &DUMMY, nullptr);
|
WriteFile(hookPipe, &buffer, sizeof(buffer), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID)
|
BOOL WINAPI DllMain(HINSTANCE hModule, DWORD fdwReason, LPVOID)
|
||||||
|
Loading…
Reference in New Issue
Block a user