chore: add the reversing tools I have locally

This commit is contained in:
Almamu 2025-05-10 18:17:17 +02:00
parent a21e0cfa61
commit cb0df539d4
9 changed files with 414 additions and 0 deletions

14
tools/reversing/README.md Normal file
View File

@ -0,0 +1,14 @@
# Reverse Engineering Tools
These are the tools and binaries that I use for understanding what's going behind the scenes:
## d3dcompiler_47
A small shim to debug interactions with the d3dcompiler.
It's used to add extra information to wallpaper's themselves, like include processed shader before It's compiled
by d3d. Especially useful when something shader-related doesn't work so It can be inspected either manually
(with the logfile it creates) or in RenderDoc with shader names, source...
For it to work it has to live alongside the real d3dcompiler_74 dll renamed to d3dcompiler_47original.dll
## RenderDoc.cap
A base capture file that allows for Wallpaper Engine to run backgrounds, when used in conjunction with the
d3dcompiler_47 shim allows for taking captures of rendering, inspecting all the rendering performed by Wallpaper Engine.

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30204.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "d3dcompiler_47_shim", "d3dcompiler_47_shim\d3dcompiler_47_shim.vcxproj", "{44B2FA3F-952A-4661-B31D-4683CD500A8C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Debug|x64.ActiveCfg = Debug|x64
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Debug|x64.Build.0 = Debug|x64
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Debug|x86.ActiveCfg = Debug|Win32
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Debug|x86.Build.0 = Debug|Win32
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Release|x64.ActiveCfg = Release|x64
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Release|x64.Build.0 = Release|x64
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Release|x86.ActiveCfg = Release|Win32
{44B2FA3F-952A-4661-B31D-4683CD500A8C}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A062B42E-282C-4165-903B-C528ACDA9BF1}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,4 @@
LIBRARY
EXPORTS
D3DCompile=D3DCompile
D3DReflect=D3DReflect

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{44b2fa3f-952a-4661-b31d-4683cd500a8c}</ProjectGuid>
<RootNamespace>d3dcompiler47shim</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>d3dcompiler_47</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<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="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)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
<ModuleDefinitionFile>Source.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="framework.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Source.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,137 @@
// dllmain.cpp : Define el punto de entrada de la aplicación DLL.
#include "pch.h"
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#pragma warning(disable:4996)
typedef HRESULT (*OriginalD3DCompile)(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
const void* pDefines,
void* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
void** ppCode,
void** ppErrorMsgs
);
typedef HRESULT (*OriginalD3DReflect)(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
REFIID pInterface,
void** ppReflector
);
HMODULE original_lib = NULL;
OriginalD3DCompile ExternalD3DCompile = NULL;
OriginalD3DReflect ExternalD3DReflect = NULL;
FILE* fp = NULL;
extern "C"
{
__declspec(dllexport) HRESULT WINAPI D3DCompile(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
LPCSTR pSourceName,
const void* pDefines,
void* pInclude,
LPCSTR pEntrypoint,
LPCSTR pTarget,
UINT Flags1,
UINT Flags2,
void** ppCode,
void** ppErrorMsgs
)
{
if (fp != NULL)
{
fprintf(fp, "////////////////////////////////////////////////////////////////////////////\r\n");
fprintf(fp, "Shader: %s\n", pSourceName);
fprintf(fp, "////////////////////////////////////////////////////////////////////////////\r\n");
fwrite(pSrcData, SrcDataSize, 1, fp);
fflush (fp);
}
// includes D3DCOMPILE_DEBUG
Flags1 |= (1 << 0) | (1 << 2);
return ExternalD3DCompile(pSrcData, SrcDataSize, pSourceName, pDefines, pInclude, pEntrypoint, pTarget, Flags1, Flags2, ppCode, ppErrorMsgs);
}
__declspec(dllexport) HRESULT WINAPI D3DReflect(
LPCVOID pSrcData,
SIZE_T SrcDataSize,
REFIID pInterface,
void** ppReflector
)
{
return ExternalD3DReflect(pSrcData, SrcDataSize, pInterface, ppReflector);
}
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
char shadersFile[256];
memset(shadersFile, 0, 256);
sprintf(shadersFile, "C:\\development\\shaders_%lld_%i.log", time(NULL), rand());
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
fp = fopen(shadersFile, "ab+");
if (fp == NULL) {
return FALSE;
}
fprintf(fp, "=====================================================================================\n");
fputs("Booting up shader compiler shim!", fp);
original_lib = LoadLibrary(TEXT("d3dcompiler_47original.dll"));
if (!original_lib)
original_lib = LoadLibraryEx(TEXT("d3dcompiler_47original.dll"), 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
if (!original_lib)
{
fputs("Could not resolve DLL!\r\n", fp);
fclose(fp);
fp = NULL;
return FALSE;
}
ExternalD3DCompile = (OriginalD3DCompile) GetProcAddress(original_lib, "D3DCompile");
ExternalD3DReflect = (OriginalD3DReflect) GetProcAddress(original_lib, "D3DReflect");
if (!ExternalD3DReflect) {
fputs("Could not locate D3DReflect in d3dcompiler_47original.dll\r\n", fp);
} else {
fputs("Located D3DReflect in d3dcompiler_47original.dll\r\n", fp);
}
if (!ExternalD3DCompile) {
fputs("Could not locate D3DCompile in d3dcompiler_47original.dll\r\n", fp);
} else {
fputs("Located D3DCompile in d3dcompiler_47original.dll\r\n", fp);
}
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
fputs("Closing...\r\n", fp);
fclose(fp);
fp = NULL;
break;
}
return TRUE;
}

View File

@ -0,0 +1,5 @@
#pragma once
#define WIN32_LEAN_AND_MEAN // Excluir material rara vez utilizado de encabezados de Windows
// Archivos de encabezado de Windows
#include <windows.h>

View File

@ -0,0 +1,5 @@
// pch.cpp: el archivo de código fuente correspondiente al encabezado precompilado
#include "pch.h"
// Cuando se utilizan encabezados precompilados, se requiere este archivo de código fuente para que la compilación se realice correctamente.

View File

@ -0,0 +1,13 @@
// pch.h: este es un archivo de encabezado precompilado.
// Los archivos que se muestran a continuación se compilan solo una vez, lo que mejora el rendimiento de la compilación en futuras compilaciones.
// Esto también afecta al rendimiento de IntelliSense, incluida la integridad del código y muchas funciones de exploración del código.
// Sin embargo, los archivos que se muestran aquí se vuelven TODOS a compilar si alguno de ellos se actualiza entre compilaciones.
// No agregue aquí los archivos que se vayan a actualizar con frecuencia, ya que esto invalida la ventaja de rendimiento.
#ifndef PCH_H
#define PCH_H
// agregue aquí los encabezados que desea precompilar
#include "framework.h"
#endif //PCH_H

View File

@ -0,0 +1,28 @@
{
"rdocCaptureSettings": 1,
"settings": {
"autoStart": false,
"commandLine": "-showbrowse -language spanish -updateuicmd -showbrowse ",
"environment": [
],
"executable": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\wallpaper_engine\\wallpaper64.exe",
"inject": false,
"numQueuedFrames": 0,
"options": {
"allowFullscreen": true,
"allowVSync": true,
"apiValidation": false,
"captureAllCmdLists": false,
"captureCallstacks": false,
"captureCallstacksOnlyDraws": false,
"debugOutputMute": true,
"delayForDebugger": 0,
"hookIntoChildren": false,
"refAllResources": false,
"softMemoryLimit": 0,
"verifyBufferAccess": false
},
"queuedFrameCap": 0,
"workingDir": ""
}
}