Implement all the things

This commit is contained in:
Xpl0itR 2023-01-15 20:25:09 +00:00
parent 6a23255da4
commit a994639caa
Signed by: Xpl0itR
GPG Key ID: 91798184109676AD
8 changed files with 321 additions and 0 deletions

32
VersionShim.sln Normal file
View File

@ -0,0 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33209.295
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VersionShim", "VersionShim\VersionShim.vcxproj", "{7D2E1375-BF0B-49EF-BBA8-C134A347F1C7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{39DCA191-5807-42D8-A66A-373FBE7F5EA9}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D2E1375-BF0B-49EF-BBA8-C134A347F1C7}.Debug|x64.ActiveCfg = Debug|x64
{7D2E1375-BF0B-49EF-BBA8-C134A347F1C7}.Debug|x64.Build.0 = Debug|x64
{7D2E1375-BF0B-49EF-BBA8-C134A347F1C7}.Release|x64.ActiveCfg = Release|x64
{7D2E1375-BF0B-49EF-BBA8-C134A347F1C7}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {577CC093-ACE1-4DFE-BC2F-AAD2A3A7FF00}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<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">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{7d2e1375-bf0b-49ef-bba8-c134a347f1c7}</ProjectGuid>
<RootNamespace>VersionShim</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>VersionShim</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<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>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="util.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.c" />
<ClCompile Include="pch.c" />
<ClCompile Include="util.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@ -0,0 +1,36 @@
<?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="pch.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="util.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

66
VersionShim/dllmain.c Normal file
View File

@ -0,0 +1,66 @@
// Copyright © 2023 Xpl0itR
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "pch.h"
#include "util.h"
#pragma region Forward functions to version.dll
#pragma comment(linker, "/EXPORT:GetFileVersionInfoA=C:\\Windows\\System32\\version.GetFileVersionInfoA,@1")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoByHandle=C:\\Windows\\System32\\version.GetFileVersionInfoByHandle,@2")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoExA=C:\\Windows\\System32\\version.GetFileVersionInfoExA,@3")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoExW=C:\\Windows\\System32\\version.GetFileVersionInfoExW,@4")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeA=C:\\Windows\\System32\\version.GetFileVersionInfoSizeA,@5")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExA=C:\\Windows\\System32\\version.GetFileVersionInfoSizeExA,@6")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExW=C:\\Windows\\System32\\version.GetFileVersionInfoSizeExW,@7")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeW=C:\\Windows\\System32\\version.GetFileVersionInfoSizeW,@8")
#pragma comment(linker, "/EXPORT:GetFileVersionInfoW=C:\\Windows\\System32\\version.GetFileVersionInfoW,@9")
#pragma comment(linker, "/EXPORT:VerFindFileA=C:\\Windows\\System32\\version.VerFindFileA,@10")
#pragma comment(linker, "/EXPORT:VerFindFileW=C:\\Windows\\System32\\version.VerFindFileW,@11")
#pragma comment(linker, "/EXPORT:VerInstallFileA=C:\\Windows\\System32\\version.VerInstallFileA,@12")
#pragma comment(linker, "/EXPORT:VerInstallFileW=C:\\Windows\\System32\\version.VerInstallFileW,@13")
#pragma comment(linker, "/EXPORT:VerLanguageNameA=C:\\Windows\\System32\\version.VerLanguageNameA,@14")
#pragma comment(linker, "/EXPORT:VerLanguageNameW=C:\\Windows\\System32\\version.VerLanguageNameW,@15")
#pragma comment(linker, "/EXPORT:VerQueryValueA=C:\\Windows\\System32\\version.VerQueryValueA,@16")
#pragma comment(linker, "/EXPORT:VerQueryValueW=C:\\Windows\\System32\\version.VerQueryValueW,@17")
#pragma endregion
BOOL APIENTRY DllMain(const HMODULE hModule, const DWORD fdwReason, LPCVOID lpReserved)
{
if (fdwReason != DLL_PROCESS_ATTACH)
return TRUE;
HANDLE hFile = NULL;
if (!OpenRead("Libraries.txt", &hFile))
return FALSE;
LPCH fileBuf = NULL;
DWORD fileLen = 0;
BOOL success = ReadUtf8File(hFile, &fileBuf, &fileLen);
CloseHandle(hFile);
if (!success)
return Error(L"Failed to read Libraries.txt");
if (fileLen > INT_MAX)
return Error(L"Libraries.txt was too large to read");
LPWSTR fileStr = NULL;
success = Utf8ToUtf16(fileBuf, &fileStr, (int)fileLen);
free(fileBuf);
if (!success)
return Error(L"Failed to read Libraries.txt as UTF-16");
LPWSTR end = fileStr + fileLen;
for (LPWSTR dllPath = fileStr; dllPath < end;)
{
int numCharInVal = NextLine(dllPath);
LoadLibrary(dllPath);
dllPath += numCharInVal + 2;
}
free(fileStr);
return TRUE;
}

3
VersionShim/pch.c Normal file
View File

@ -0,0 +1,3 @@
// pch.c: source file corresponding to the pre-compiled header
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
#include "pch.h"

14
VersionShim/pch.h Normal file
View File

@ -0,0 +1,14 @@
// pch.h: This is a precompiled header file.
// Files listed below are compiled only once, improving build performance for future builds.
// This also affects IntelliSense performance, including code completion and many code browsing features.
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
// Do not add files here that you will be updating frequently as this negates the performance advantage.
#ifndef PCH_H
#define PCH_H
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
#endif //PCH_H

78
VersionShim/util.c Normal file
View File

@ -0,0 +1,78 @@
// Copyright © 2023 Xpl0itR
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include "pch.h"
BOOL Error(const LPWSTR message)
{
MessageBox(NULL, message, L"VersionShim", MB_ICONHAND | MB_OK);
return FALSE;
}
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle)
{
OFSTRUCT ofStruct = { 0 };
HFILE hFile = OpenFile(lpFileName, &ofStruct, OF_READ | OF_PROMPT);
*fileHandle = (HANDLE)hFile;
return hFile != HFILE_ERROR;
}
BOOL ReadUtf8File(const HANDLE fileHandle, LPCH* fileBuffer, DWORD* fileLength)
{
const DWORD fileLen = GetFileSize(fileHandle, NULL);
*fileLength = fileLen;
LPCH buffer = malloc(fileLen + 1);
if (!buffer)
return FALSE;
if (!ReadFile(fileHandle, buffer, fileLen, NULL, NULL))
{
free(buffer);
return FALSE;
}
buffer[fileLen] = '\0';
*fileBuffer = buffer;
return TRUE;
}
BOOL Utf8ToUtf16(LPCCH utf8String, const PZPWSTR utf16String, const int length)
{
LPWSTR string = malloc(length * 2 + 2);
if (!string)
return FALSE;
if (!MultiByteToWideChar(CP_UTF8, 0, utf8String, length, string, length))
{
free(string);
return FALSE;
}
string[length] = L'\0';
*utf16String = string;
return TRUE;
}
int NextLine(const LPWSTR text)
{
for (int i = 0; ; i++)
{
if (text[i] == L'\r' &&
text[i + 1] == L'\n')
{
text[i] = text[i + 1] = L'\0';
}
if (text[i] == L'\0')
{
return i;
}
}
}

8
VersionShim/util.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include "pch.h"
BOOL Error(LPWSTR message);
BOOL OpenRead(LPCSTR lpFileName, HANDLE* fileHandle);
BOOL ReadUtf8File(HANDLE fileHandle, LPCH* fileBuffer, DWORD* fileLength);
BOOL Utf8ToUtf16(LPCCH utf8String, PZPWSTR utf16String, int length);
int NextLine(LPWSTR text);