Skip to content

Commit

Permalink
Additionally export methods from winhttp.dll
Browse files Browse the repository at this point in the history
also rewrite a bunch
  • Loading branch information
Xpl0itR committed Aug 28, 2024
1 parent c3439fb commit 756ba85
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 138 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ jobs:
- name: Release
uses: softprops/action-gh-release@v1
with:
files: x64/Release/VersionShim.dll
fail_on_unmatched_files: true
files: bin/x64/Release/VersionShim.dll
fail_on_unmatched_files: true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VersionShim
===========
A Dynamic-Link Library which exports the same methods as version.dll (winver.h) in addition to chainloading additional user defined libraries.
A Dynamic-Link Library which exports the same methods as version.dll (winver.h) and winhttp.dll in addition to chainloading additional user defined libraries.

Usage
-----
Rename VersionShim.dll to `version.dll` and place it in the target process's search location,
Rename VersionShim.dll to `version.dll` or `winhttp.dll` and place it in the target process's search location,
then create a file named `libraries.txt` in the same directory and list the paths to all the libraries you'd like to load,
each on a new line.

Expand Down
2 changes: 1 addition & 1 deletion VersionShim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VersionShim", "src\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
Expand Down
85 changes: 0 additions & 85 deletions VersionShim/dllmain.c

This file was deleted.

3 changes: 0 additions & 3 deletions VersionShim/pch.c

This file was deleted.

10 changes: 0 additions & 10 deletions VersionShim/pch.h

This file was deleted.

8 changes: 0 additions & 8 deletions VersionShim/util.h

This file was deleted.

32 changes: 23 additions & 9 deletions VersionShim/VersionShim.vcxproj → src/VersionShim.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,60 @@
<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 Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)bin\$(Platform)\$(Configuration)\</OutDir>
<GenerateManifest>false</GenerateManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;PROJECT_NAME="$(ProjectName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;VERSIONSHIM_EXPORTS;_WINDOWS;_USRDLL;PROJECT_NAME="$(ProjectName)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Create</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MinSpace</Optimization>
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<BufferSecurityCheck>false</BufferSecurityCheck>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<AdditionalOptions>/EMITPOGOPHASEINFO %(AdditionalOptions)</AdditionalOptions>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="exports.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>
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,16 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="util.h">
<ClInclude Include="exports.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>
67 changes: 67 additions & 0 deletions src/dllmain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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/.

// ReSharper disable once CppUnusedIncludeDirective
#include "exports.h"
#include "util.h"

BOOL APIENTRY DllMain(CONST HMODULE hModule, CONST DWORD fdwReason, CONST LPVOID lpvReserved)
{
if (fdwReason != DLL_PROCESS_ATTACH)
return TRUE;

LPSTR fileStr = NULL;
DWORD fileLen = 0;

if (!OpenReadFileUtf8("libraries.txt", &fileStr, &fileLen))
{
MessageBoxA(NULL, "Failed to read libraries.txt", PROJECT_NAME, ErrBoxType);
return TRUE;
}

LPSTR callerPath[MAX_PATH + 1];
if (!GetModuleFileNameA(NULL, callerPath, MAX_PATH + 1)) // NOLINT(clang-diagnostic-incompatible-pointer-types)
{
MessageBoxA(NULL, "Failed to read caller path", PROJECT_NAME, ErrBoxType);
return TRUE;
}

int read, hasTarget = FALSE, targetMatched = FALSE;
for (LPSTR line = SkipBomUtf8(fileStr), fileEnd = fileStr + fileLen; line < fileEnd; line += read)
{
read = TerminateLine(line);

if (*line == '#')
continue;

if (*line == '*')
{
if (!targetMatched)
{
hasTarget = TRUE;

if (StrEndsWith(callerPath, line + 1)) // NOLINT(clang-diagnostic-incompatible-pointer-types)
{
targetMatched = TRUE;
}
}

continue;
}

if (hasTarget && !targetMatched)
return TRUE;

// ReSharper disable once CppPointerToIntegralConversion
if (!LoadLibraryA(line))
{
MessageBoxA(NULL, line, PROJECT_NAME" - Failed to load library", ErrBoxType);
}
}

HeapFree(GetProcessHeap(), 0, fileStr);
return TRUE;
}
Loading

0 comments on commit 756ba85

Please sign in to comment.