Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
simonowen committed Feb 20, 2017
0 parents commit 02f4f79ded4f9c3ae2edfb51dfb2f86044bb1aab
Showing with 645 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +36 −0 DashFix.sln
  3. +181 −0 DashFix/DashFix.cpp
  4. +144 −0 DashFix/DashFix.vcxproj
  5. +14 −0 DashFix/DashFix.vcxproj.filters
  6. +31 −0 ReadMe.txt
  7. +51 −0 inject/inject.cpp
  8. +157 −0 inject/inject.vcxproj
  9. +14 −0 inject/inject.vcxproj.filters
@@ -0,0 +1,17 @@
/.vs
.DS_Store
*.o
*.aps
*.opt
*.ncb
*.plg
*.suo
/*.vcproj.*.user
/*.vcxproj.user
/*.sdf
/*.opensdf
/*.opendb
/*.VC.db
/ipch/
[Dd]ebug/
[Rr]elease/
@@ -0,0 +1,36 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DashFix", "DashFix\DashFix.vcxproj", "{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}"
ProjectSection(ProjectDependencies) = postProject
{C10D7779-70C9-4D6C-8486-768908A3E769} = {C10D7779-70C9-4D6C-8486-768908A3E769}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "inject", "inject\inject.vcxproj", "{C10D7779-70C9-4D6C-8486-768908A3E769}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E092A9E4-C507-4382-88A2-EA2B7131A7C6}"
ProjectSection(SolutionItems) = preProject
ReadMe.txt = ReadMe.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}.Debug|x86.ActiveCfg = Debug|Win32
{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}.Debug|x86.Build.0 = Debug|Win32
{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}.Release|x86.ActiveCfg = Release|Win32
{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}.Release|x86.Build.0 = Release|Win32
{C10D7779-70C9-4D6C-8486-768908A3E769}.Debug|x86.ActiveCfg = Debug|Win32
{C10D7779-70C9-4D6C-8486-768908A3E769}.Debug|x86.Build.0 = Debug|Win32
{C10D7779-70C9-4D6C-8486-768908A3E769}.Release|x86.ActiveCfg = Release|Win32
{C10D7779-70C9-4D6C-8486-768908A3E769}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,181 @@
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WIN7
#include <SDKDDKVer.h>

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tlhelp32.h>
#include <string>
#include <vector>
#include <thread>


_Success_(return)
bool GetProcessId(
_In_ const std::wstring &strProcess,
_Out_ DWORD & dwProcessId,
_In_opt_ DWORD dwExcludeProcessId = 0)
{
bool ret{ false };
dwProcessId = 0;

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 pe{ sizeof(pe) };

auto f = Process32First(hSnapshot, &pe);
while (f)
{
if (!lstrcmpi(pe.szExeFile, strProcess.c_str()) &&
pe.th32ProcessID != dwExcludeProcessId)
{
dwProcessId = pe.th32ProcessID;
ret = true;
break;
}

f = Process32Next(hSnapshot, &pe);
}

CloseHandle(hSnapshot);
}

return ret;
}

_Success_(return)
bool InjectRemoteThread(
_In_ DWORD dwProcessId,
_In_ const std::wstring &strDLL)
{
bool ret{ false };

auto hProcess = OpenProcess(
PROCESS_ALL_ACCESS,
FALSE,
dwProcessId);

if (hProcess != NULL)
{
auto pfnLoadLibrary = GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")),
"LoadLibraryW");

auto uStringSize = (strDLL.length() + 1) * sizeof(strDLL[0]);
auto pszRemoteString = VirtualAllocEx(
hProcess,
NULL,
uStringSize,
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

if (pszRemoteString)
{
WriteProcessMemory(hProcess, pszRemoteString, strDLL.c_str(), uStringSize, NULL);

auto hThread = CreateRemoteThread(
hProcess, NULL, 0,
reinterpret_cast<LPTHREAD_START_ROUTINE>(pfnLoadLibrary),
pszRemoteString,
0,
NULL);

if (hThread != NULL)
{
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
ret = true;
}

VirtualFreeEx(hProcess, pszRemoteString, 0, MEM_RELEASE);
}

WaitForSingleObject(hProcess, INFINITE);
CloseHandle(hProcess);
}

return ret;
}


void PatchModules(
_In_ const std::vector<std::wstring> &mods)
{
WCHAR szEXE[MAX_PATH];
GetModuleFileName(NULL, szEXE, ARRAYSIZE(szEXE));

// The injection DLL is in the same directory as the EXE.
std::wstring strDLL{szEXE};
strDLL = strDLL.substr(0, strDLL.rfind('\\'));
strDLL += TEXT("\\inject.dll");

std::vector<std::thread> threads{};
for (auto &mod : mods)
{
std::thread([=]
{
// Loop forever watching
for (;;)
{
DWORD dwProcessId;

// Poll for process start, with 3 seconds between checks.
if (!GetProcessId(mod, dwProcessId))
{
Sleep(3000);
}
// Inject the patch DLL into the process and wait for it to
// terminate. 1 second between injection attempts.
else if (!InjectRemoteThread(dwProcessId, strDLL))
{
Sleep(1000);
}
}
}).detach();
}
}


int CALLBACK WinMain(
_In_ HINSTANCE /*hInstance*/,
_In_opt_ HINSTANCE /*hPrevInstance*/,
_In_ LPSTR /*lpCmdLine*/,
_In_ int /*nCmdShow*/)
{
HANDLE hMutex = CreateMutex(NULL, TRUE, TEXT("DashFixMutex"));
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
ReleaseMutex(hMutex);

if (MessageBox( NULL,
TEXT("Program is already running. Do you want to close it?"),
TEXT("DashFix"), MB_ICONQUESTION | MB_YESNO) == IDYES)
{
DWORD dwProcessId{0};

if (GetProcessId( TEXT("DashFix.exe"), dwProcessId, GetCurrentProcessId()))
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);
if (hProcess)
{
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
}
}
else
{
// So far only 2 modules seem to need patching.
PatchModules( { TEXT("steam.exe"), TEXT("vrdashboard.exe") } );

MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return 0;
}
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{6A4E0B46-D7F2-4C46-93C6-7900F07A3B5A}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>DashFix</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="DashFix.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DashFix.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

0 comments on commit 02f4f79

Please sign in to comment.
You can’t perform that action at this time.