mirror of https://github.com/Thracky/GlosSI
Add dll-inject function and overlayelement needed for UWPOverlay
Also made some "slight" overlay adjustmentsmain
parent
cb41e5fadd
commit
0e292cb591
@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
#include <tlhelp32.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace DllInjector {
|
||||
|
||||
inline bool TakeDebugPrivilege()
|
||||
{
|
||||
HANDLE process = GetCurrentProcess(), token;
|
||||
TOKEN_PRIVILEGES priv;
|
||||
LUID luid = {NULL};
|
||||
|
||||
if (!OpenProcessToken(process, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
|
||||
CloseHandle(process);
|
||||
spdlog::error("Failed to open process token");
|
||||
return false;
|
||||
}
|
||||
LookupPrivilegeValue(0, SE_DEBUG_NAME, &luid);
|
||||
|
||||
priv.PrivilegeCount = 1;
|
||||
priv.Privileges[0].Luid = luid;
|
||||
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
||||
if (!AdjustTokenPrivileges(token, false, &priv, sizeof(priv), NULL, NULL)) {
|
||||
spdlog::error("Failed to take debug privilege token");
|
||||
}
|
||||
|
||||
CloseHandle(token);
|
||||
CloseHandle(process);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Inject(DWORD pid, const std::wstring& lib_path)
|
||||
{
|
||||
HANDLE process = NULL, alloc_address = NULL, remote_thread = NULL;
|
||||
LPTHREAD_START_ROUTINE thread_routine = NULL;
|
||||
|
||||
size_t path_size = (lib_path.length() + 1) * sizeof(wchar_t);
|
||||
|
||||
process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, pid);
|
||||
|
||||
if (!process) {
|
||||
spdlog::error("Failed to open process");
|
||||
return false;
|
||||
}
|
||||
|
||||
alloc_address = VirtualAllocEx(process, NULL, path_size, MEM_COMMIT, PAGE_READWRITE);
|
||||
|
||||
if (!VirtualAllocEx(process, NULL, path_size, MEM_COMMIT, PAGE_READWRITE)) {
|
||||
spdlog::error("Failed to allocate memory in target process");
|
||||
CloseHandle(process);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WriteProcessMemory(process, (LPVOID)alloc_address, lib_path.c_str(), path_size, NULL)) {
|
||||
spdlog::error("Failed to write memory in target process");
|
||||
VirtualFreeEx(process, alloc_address, path_size, MEM_DECOMMIT);
|
||||
CloseHandle(process);
|
||||
return false;
|
||||
}
|
||||
|
||||
thread_routine = reinterpret_cast<PTHREAD_START_ROUTINE>(GetProcAddress(GetModuleHandle(L"Kernel32"), "LoadLibraryW"));
|
||||
if (!thread_routine) {
|
||||
spdlog::error("Failed to get address of LoadLibraryW");
|
||||
VirtualFreeEx(process, alloc_address, path_size, MEM_DECOMMIT);
|
||||
CloseHandle(process);
|
||||
return false;
|
||||
}
|
||||
|
||||
remote_thread = CreateRemoteThread(process, NULL, 0, thread_routine, alloc_address, 0, NULL);
|
||||
|
||||
if (!remote_thread) {
|
||||
spdlog::error("Failed to create remote thread");
|
||||
VirtualFreeEx(process, alloc_address, path_size, MEM_DECOMMIT);
|
||||
CloseHandle(process);
|
||||
return false;
|
||||
}
|
||||
|
||||
WaitForSingleObject(remote_thread, INFINITE);
|
||||
|
||||
CloseHandle(remote_thread);
|
||||
VirtualFreeEx(process, alloc_address, path_size, MEM_DECOMMIT);
|
||||
CloseHandle(process);
|
||||
spdlog::debug("Successfully injected");
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool findModule(DWORD pid, std::wstring& lib_path, HMODULE& hMod)
|
||||
{
|
||||
MODULEENTRY32W entry = {sizeof(entry)};
|
||||
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
|
||||
|
||||
if (Module32FirstW(snapshot, &entry) == TRUE) {
|
||||
while (Module32NextW(snapshot, &entry) == TRUE) {
|
||||
std::wstring ModuleName(entry.szModule);
|
||||
std::wstring ExePath(entry.szExePath);
|
||||
if (ModuleName == lib_path || ExePath == lib_path) {
|
||||
hMod = (HMODULE)entry.modBaseAddr;
|
||||
CloseHandle(snapshot);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(snapshot);
|
||||
spdlog::error(L"Failed to find module \"{}\"", lib_path);
|
||||
return false;
|
||||
}
|
||||
|
||||
}; // namespace DllInjector
|
@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "DllInjector.h"
|
||||
#include "Overlay.h"
|
||||
|
||||
namespace UWPOverlayEnabler {
|
||||
|
||||
namespace internal {
|
||||
|
||||
inline std::filesystem::path EnablerPath()
|
||||
{
|
||||
wchar_t buff[MAX_PATH];
|
||||
GetModuleFileName(GetModuleHandle(NULL), buff, MAX_PATH);
|
||||
const std::wstring path(buff);
|
||||
return path.substr(0, 1 + path.find_last_of(L'\\')) + L"UWPOverlayEnablerDLL.dll";
|
||||
}
|
||||
|
||||
inline DWORD ExplorerPid()
|
||||
{
|
||||
PROCESSENTRY32 entry;
|
||||
entry.dwSize = sizeof(PROCESSENTRY32);
|
||||
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
|
||||
if (Process32First(snapshot, &entry) == TRUE) {
|
||||
while (Process32Next(snapshot, &entry) == TRUE) {
|
||||
if (std::wstring(entry.szExeFile).find(L"explorer.exe") != std::string::npos) {
|
||||
return entry.th32ProcessID;
|
||||
}
|
||||
}
|
||||
}
|
||||
CloseHandle(snapshot);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
inline void AddUwpOverlayOvWidget()
|
||||
{
|
||||
Overlay::AddOverlayElem([]() {
|
||||
ImGui::SetNextWindowPos({950, 100}, ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSizeConstraints({170, 225}, {1000, 1000});
|
||||
ImGui::SetNextWindowCollapsed(true, ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("UWP-Overlay");
|
||||
ImGui::Text("To enable the overlay on top of \"fullscreen\" UWP-Apps,");
|
||||
ImGui::Text("a .dll has to be injected into explorer.exe");
|
||||
ImGui::Spacing();
|
||||
ImGui::Spacing();
|
||||
ImGui::Text("This method also uses undocumented windows functions");
|
||||
ImGui::Text("and is highly experimental");
|
||||
ImGui::Spacing();
|
||||
ImGui::Spacing();
|
||||
ImGui::Text("This might cause issues!!!");
|
||||
ImGui::Spacing();
|
||||
if (ImGui::CollapsingHeader("I am sure!")) {
|
||||
if (ImGui::Button(/* just */ "DO IT!")) { // insert meme gif here >.<
|
||||
const auto enabler_path = internal::EnablerPath();
|
||||
if (std::filesystem::exists(enabler_path)) {
|
||||
const auto explorer_pid = internal::ExplorerPid();
|
||||
if (explorer_pid != 0) {
|
||||
if (DllInjector::TakeDebugPrivilege()) {
|
||||
// No need to eject, as the dll is self-ejecting.
|
||||
if (DllInjector::Inject(explorer_pid, enabler_path.wstring())) {
|
||||
spdlog::info("Successfully injected UWPOverlay enabler into explorer.exe");
|
||||
// Nesting level over 9000
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
spdlog::error("explorer not found"); // needs loglevel WTF
|
||||
}
|
||||
}
|
||||
else {
|
||||
spdlog::error("UWPOverlayEnablerDLL not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue