Suspend UWP app at start and inject .dll

dunno what to use for, yet
experimental/UWP_Inject
Peter Repukat 2 years ago
parent 35a47b03aa
commit 1cc6c02bbc

@ -18,9 +18,14 @@ limitations under the License.
#include <spdlog/spdlog.h>
#ifdef _WIN32
#define COBJMACROS
#include <winternl.h>
#include <objbase.h>
#include <sddl.h>
#include <ShObjIdl.h>
#include <atlbase.h>
#include <tlhelp32.h>
#include <atlcomcli.h>
#endif
#include "Settings.h"
@ -183,6 +188,17 @@ void AppLauncher::launchUWPApp(const LPCWSTR package_full_name, const std::wstri
HRESULT result = CoInitialize(nullptr);
if (SUCCEEDED(result)) {
// DllInjector::TakeDebugPrivilege();
HRESULT hResult = S_OK;
ATL::CComQIPtr<IPackageDebugSettings> debugSettings;
hResult = debugSettings.CoCreateInstance(CLSID_PackageDebugSettings, NULL, CLSCTX_ALL);
debugSettings->EnableDebugging(
L"Microsoft.MinecraftUWP_1.18.203.0_x64__8wekyb3d8bbwe",
L"D:\\Alia5\\Documents\\Visual_Studio_Projects\\GlosSI\\x64\\Debug\\GlosSITarget.exe",
NULL
);
CComPtr<IApplicationActivationManager> sp_app_activation_manager;
// Initialize IApplicationActivationManager
result = CoCreateInstance(
@ -209,6 +225,7 @@ void AppLauncher::launchUWPApp(const LPCWSTR package_full_name, const std::wstri
} else {
spdlog::error("CoCreateInstance failed: Code {}", result);
}
debugSettings->DisableDebugging(L"Microsoft.MinecraftUWP_1.18.203.0_x64__8wekyb3d8bbwe");
CoUninitialize();
}
else {

@ -16,12 +16,16 @@ limitations under the License.
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#include <winternl.h>
#undef WIN32_NO_STATUS
#include <ntstatus.h>
#endif
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include "DllInjector.h"
#include "SteamTarget.h"
#include "OverlayLogSink.h"
@ -95,7 +99,11 @@ int main(int argc, char* argv[])
path /= "GlosSI";
if (!std::filesystem::exists(path))
std::filesystem::create_directories(path);
path /= "glossitarget.log";
if (__argc > 1 && std::string(__argv[1]) == "-p") {
path /= "glossitarget_UWP_inject.log";
} else {
path /= "glossitarget.log";
}
const auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path.string(), true);
#else
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("/tmp/glossitarget.log", true);
@ -120,8 +128,63 @@ int main(int argc, char* argv[])
#ifdef _WIN32
std::string argsv = "";
if (__argc > 1) {
for (int i = 1; i < __argc; i++)
argsv += i == 1 ? __argv[i] : std::string(" ") + __argv[i];
if (std::string(__argv[1]) == "-p" && __argc >= 3) {
DWORD pid = std::stoi(std::string(__argv[2]));
spdlog::debug("DLLInject requested with pid: {}", pid);
if (DllInjector::TakeDebugPrivilege()) {
// No need to eject, as the dll is self-ejecting.
if (DllInjector::Inject(
pid,
L"Test.dll")) {
spdlog::info("Successfully injected Test.dll...");
// --
typedef LONG (NTAPI *fnNtResumeProcess)(IN HANDLE processHandle);
auto resume_proc = reinterpret_cast<fnNtResumeProcess>(GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtResumeProcess"));
if (!resume_proc) {
spdlog::error("Failed to get address of NtResumeProcess");
} else {
spdlog::debug("Got adress of NTResumeProc...");
}
HANDLE process = NULL;
process = OpenProcess(
PROCESS_QUERY_INFORMATION | PROCESS_SUSPEND_RESUME | PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE,
false,
pid);
if (!process) {
spdlog::error("Failed to open process");
spdlog::shutdown();
return 1;
}
spdlog::debug("Resuming proc...");
if (!NT_SUCCESS(resume_proc(process)))
{
spdlog::error("Failed to resume proc!");
}
CloseHandle(process);
// --
} else {
spdlog::error("Couldn't inject...");
}
} else {
spdlog::error("Couldn't take debug privilege!");
}
spdlog::shutdown();
return 0;
} else {
for (int i = 1; i < __argc; i++)
argsv += i == 1 ? __argv[i] : std::string(" ") + __argv[i];
}
}
Settings::Parse(argsv);
SteamTarget target(__argc, __argv);

Loading…
Cancel
Save