2016-05-08 14:42:54 +00:00
|
|
|
#include <Windows.h>
|
2016-04-08 04:25:49 -04:00
|
|
|
#include <stdio.h>
|
2016-04-23 10:56:14 +00:00
|
|
|
#include <string.h>
|
2016-05-18 15:46:15 +00:00
|
|
|
#include <Shlobj.h>
|
|
|
|
|
#include <Shlwapi.h>
|
2016-04-08 04:25:49 -04:00
|
|
|
#include "ReviveInject.h"
|
|
|
|
|
|
2016-05-18 15:46:15 +00:00
|
|
|
FILE* g_LogFile = NULL;
|
|
|
|
|
|
2016-11-14 17:10:37 +01:00
|
|
|
bool GetOculusBasePath(PWCHAR path, DWORD length)
|
|
|
|
|
{
|
|
|
|
|
LONG error = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
HKEY oculusKey;
|
|
|
|
|
error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Oculus VR, LLC\\Oculus", 0, KEY_READ | KEY_WOW64_32KEY, &oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
LOG("Unable to open Oculus key.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
error = RegQueryValueEx(oculusKey, L"Base", NULL, NULL, (PBYTE)path, &length);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
LOG("Unable to read Base path.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
RegCloseKey(oculusKey);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-16 16:30:51 +02:00
|
|
|
bool GetDefaultLibraryPath(PWCHAR path, DWORD length)
|
|
|
|
|
{
|
|
|
|
|
LONG error = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
// Open the libraries key
|
|
|
|
|
WCHAR keyPath[MAX_PATH] = { L"Software\\Oculus VR, LLC\\Oculus\\Libraries\\" };
|
|
|
|
|
HKEY oculusKey;
|
|
|
|
|
error = RegOpenKeyExW(HKEY_CURRENT_USER, keyPath, 0, KEY_READ, &oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
LOG("Unable to open Libraries key.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the default library
|
|
|
|
|
WCHAR guid[40] = { L'\0' };
|
|
|
|
|
DWORD guidSize = sizeof(guid);
|
|
|
|
|
error = RegQueryValueExW(oculusKey, L"DefaultLibrary", NULL, NULL, (PBYTE)guid, &guidSize);
|
|
|
|
|
RegCloseKey(oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
LOG("Unable to read DefaultLibrary guid.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Open the default library key
|
|
|
|
|
wcsncat(keyPath, guid, MAX_PATH);
|
|
|
|
|
error = RegOpenKeyExW(HKEY_CURRENT_USER, keyPath, 0, KEY_READ, &oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
LOG("Unable to open Library path key.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get the volume path to this library
|
|
|
|
|
DWORD pathSize;
|
|
|
|
|
error = RegQueryValueExW(oculusKey, L"Path", NULL, NULL, NULL, &pathSize);
|
|
|
|
|
PWCHAR volumePath = (PWCHAR)malloc(pathSize);
|
|
|
|
|
error = RegQueryValueExW(oculusKey, L"Path", NULL, NULL, (PBYTE)volumePath, &pathSize);
|
|
|
|
|
RegCloseKey(oculusKey);
|
|
|
|
|
if (error != ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
free(volumePath);
|
|
|
|
|
LOG("Unable to read Library path.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resolve the volume path to a mount point
|
|
|
|
|
DWORD total;
|
|
|
|
|
WCHAR volume[50] = { L'\0' };
|
|
|
|
|
wcsncpy(volume, volumePath, 49);
|
|
|
|
|
GetVolumePathNamesForVolumeNameW(volume, path, length, &total);
|
|
|
|
|
wcsncat(path, volumePath + 49, MAX_PATH);
|
|
|
|
|
free(volumePath);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 14:42:54 +00:00
|
|
|
int wmain(int argc, wchar_t *argv[]) {
|
2016-04-08 04:25:49 -04:00
|
|
|
if (argc < 2) {
|
2016-05-10 20:58:35 +00:00
|
|
|
printf("usage: ReviveInjector.exe [/handle] <process path/process handle>\n");
|
2016-04-08 04:25:49 -04:00
|
|
|
return -1;
|
|
|
|
|
}
|
2016-05-14 16:41:27 +00:00
|
|
|
|
2016-05-18 15:46:15 +00:00
|
|
|
WCHAR LogPath[MAX_PATH];
|
|
|
|
|
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, LogPath)))
|
|
|
|
|
{
|
|
|
|
|
wcsncat(LogPath, L"\\Revive", MAX_PATH);
|
|
|
|
|
|
|
|
|
|
BOOL exists = PathFileExists(LogPath);
|
|
|
|
|
if (!exists)
|
|
|
|
|
exists = CreateDirectory(LogPath, NULL);
|
|
|
|
|
|
2017-02-15 17:11:35 +01:00
|
|
|
wcsncat(LogPath, L"\\ReviveInjector.txt", MAX_PATH);
|
2016-05-18 15:46:15 +00:00
|
|
|
if (exists)
|
|
|
|
|
g_LogFile = _wfopen(LogPath, L"w");
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-18 15:46:15 +00:00
|
|
|
LOG("Launched injector with: %ls\n", GetCommandLine());
|
|
|
|
|
|
2016-06-26 10:35:16 +00:00
|
|
|
WCHAR path[MAX_PATH] = { 0 };
|
2016-06-26 10:35:16 +00:00
|
|
|
for (int i = 1; i < argc; i++)
|
2016-05-14 16:41:27 +00:00
|
|
|
{
|
2016-05-15 15:07:52 +00:00
|
|
|
if (wcscmp(argv[i], L"/handle") == 0)
|
2016-06-26 10:35:16 +00:00
|
|
|
{
|
|
|
|
|
return OpenProcessAndInject(argv[++i]);
|
|
|
|
|
}
|
2016-11-18 00:24:09 +01:00
|
|
|
else if (wcscmp(argv[i], L"/base") == 0)
|
|
|
|
|
{
|
|
|
|
|
if (!GetOculusBasePath(path, MAX_PATH))
|
|
|
|
|
return -1;
|
|
|
|
|
wnsprintf(path, MAX_PATH, L"%s\\%s", path, argv[++i]);
|
|
|
|
|
}
|
|
|
|
|
else if (wcscmp(argv[i], L"/library") == 0)
|
2016-05-15 15:07:52 +00:00
|
|
|
{
|
2016-11-18 00:24:09 +01:00
|
|
|
if (!GetDefaultLibraryPath(path, MAX_PATH))
|
|
|
|
|
return -1;
|
|
|
|
|
wnsprintf(path, MAX_PATH, L"%s\\%s", path, argv[++i]);
|
2016-06-26 10:35:16 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Concatenate all other arguments
|
|
|
|
|
wcsncat(path, argv[i], MAX_PATH);
|
2016-05-15 15:07:52 +00:00
|
|
|
}
|
2016-06-26 10:35:16 +00:00
|
|
|
wcsncat(path, L" ", MAX_PATH);
|
2016-05-14 16:41:27 +00:00
|
|
|
}
|
2016-05-15 15:07:52 +00:00
|
|
|
|
2016-06-26 10:35:16 +00:00
|
|
|
return CreateProcessAndInject(path);
|
2016-04-23 10:56:14 +00:00
|
|
|
}
|