From cb0df539d43529140361ca3d120b0af6f5ce7021 Mon Sep 17 00:00:00 2001 From: Almamu Date: Sat, 10 May 2025 18:17:17 +0200 Subject: [PATCH] chore: add the reversing tools I have locally --- tools/reversing/README.md | 14 ++ .../d3dcompiler_47/d3dcompiler_47_shim.sln | 31 +++ .../d3dcompiler_47_shim/Source.def | 4 + .../d3dcompiler_47_shim.vcxproj | 177 ++++++++++++++++++ .../d3dcompiler_47_shim/dllmain.cpp | 137 ++++++++++++++ .../d3dcompiler_47_shim/framework.h | 5 + .../d3dcompiler_47_shim/pch.cpp | 5 + .../d3dcompiler_47/d3dcompiler_47_shim/pch.h | 13 ++ tools/reversing/renderdoc.cap | 28 +++ 9 files changed, 414 insertions(+) create mode 100644 tools/reversing/README.md create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim.sln create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/Source.def create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/d3dcompiler_47_shim.vcxproj create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/dllmain.cpp create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/framework.h create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.cpp create mode 100644 tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.h create mode 100644 tools/reversing/renderdoc.cap diff --git a/tools/reversing/README.md b/tools/reversing/README.md new file mode 100644 index 0000000..4c40adf --- /dev/null +++ b/tools/reversing/README.md @@ -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. diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim.sln b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim.sln new file mode 100644 index 0000000..54b32ec --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim.sln @@ -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 diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/Source.def b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/Source.def new file mode 100644 index 0000000..a9ee971 --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/Source.def @@ -0,0 +1,4 @@ +LIBRARY +EXPORTS +D3DCompile=D3DCompile +D3DReflect=D3DReflect \ No newline at end of file diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/d3dcompiler_47_shim.vcxproj b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/d3dcompiler_47_shim.vcxproj new file mode 100644 index 0000000..471b5e2 --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/d3dcompiler_47_shim.vcxproj @@ -0,0 +1,177 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {44b2fa3f-952a-4661-b31d-4683cd500a8c} + d3dcompiler47shim + 10.0 + d3dcompiler_47 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + false + false + Source.def + + + + + Level3 + true + true + true + WIN32;NDEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + Source.def + + + + + Level3 + true + _DEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + Source.def + + + + + Level3 + true + true + true + NDEBUG;D3DCOMPILER47SHIM_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + Source.def + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/dllmain.cpp b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/dllmain.cpp new file mode 100644 index 0000000..064f103 --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/dllmain.cpp @@ -0,0 +1,137 @@ +// dllmain.cpp : Define el punto de entrada de la aplicación DLL. +#include "pch.h" +#include +#include +#include + +#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; +} + diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/framework.h b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/framework.h new file mode 100644 index 0000000..f24153d --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/framework.h @@ -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 diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.cpp b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.cpp new file mode 100644 index 0000000..a6ccf92 --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.cpp @@ -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. diff --git a/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.h b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.h new file mode 100644 index 0000000..8e034b6 --- /dev/null +++ b/tools/reversing/d3dcompiler_47/d3dcompiler_47_shim/pch.h @@ -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 diff --git a/tools/reversing/renderdoc.cap b/tools/reversing/renderdoc.cap new file mode 100644 index 0000000..f369c35 --- /dev/null +++ b/tools/reversing/renderdoc.cap @@ -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": "" + } +}