-
-
Save ahmed605/b403fdfa17994548c40ddb0573a51d64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// This code is licensed under MIT License | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in all | |
// copies or substantial portions of the Software. | |
// | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
// SOFTWARE. | |
// | |
#include <cstdlib> | |
#include <uxtheme.h> | |
#include <dwmapi.h> | |
#include <windhawk_api.h> | |
typedef HWND (*CWindowNode_GetHwnd_t)(void* thisPtr); | |
CWindowNode_GetHwnd_t CWindowNode_GetHwnd_Original; | |
typedef void (*CWindowNode_ctor_t)(void* thisPtr, void* compositor); | |
CWindowNode_ctor_t CWindowNode_ctor_Original; | |
typedef void (*CGaussianBlurEffect_ctor_t)(void* thisPtr, void* compositor); | |
CGaussianBlurEffect_ctor_t CGaussianBlurEffect_ctor_Original; | |
typedef HRESULT (*CResourceFactory_Create_t)(void* compositor, void* channel, int type, void** res); | |
CResourceFactory_Create_t CResourceFactory_Create_Original; | |
typedef void* (*CRectangleGeometry_ctor_t)(void); | |
CRectangleGeometry_ctor_t CRectangleGeometry_ctor_Original; | |
typedef void (*CVisual_SetOpacity_t)(void* thisPtr, float opacity); | |
CVisual_SetOpacity_t CVisual_SetOpacity_Original; | |
typedef void (*CVisual_SetEffect_t)(void* thisPtr, void* effect); | |
CVisual_SetEffect_t CVisual_SetEffect_Original; | |
typedef void (*CVisual_SetClip_t)(void* thisPtr, void* clip); | |
CVisual_SetClip_t CVisual_SetClip_Original; | |
typedef long (*CVisual_SetTransform_t)(void* thisPtr, void* transform); | |
CVisual_SetTransform_t CVisual_SetTransform_Original; | |
typedef long (*CWindowNode_ProcessCreate_t)(void* thisPtr, void* resTbl, void* msg); | |
CWindowNode_ProcessCreate_t CWindowNode_ProcessCreate_Original; | |
struct CRotateTransform3DData | |
{ | |
long double m_Angle; | |
long double m_AxisX; | |
long double m_AxisY; | |
long double m_AxisZ; | |
long double m_CenterX; | |
long double m_CenterY; | |
long double m_CenterZ; | |
}; | |
enum MilRenderOptionFlagsEnum | |
{ | |
BitmapScalingMode=1, | |
InterpolationMode=2, | |
CompositingMode=4, | |
BorderMode=8, | |
DCompCompositeMode=16, | |
OpacityMode=32, | |
BackfaceVisibility=64, | |
DepthMode=128, | |
HighFlagPlusOne=129 | |
}; | |
struct TMILFlagsEnumMilRenderOptionFlagsEnum | |
{ | |
MilRenderOptionFlagsEnum flags; | |
}; | |
enum MilBitmapBorderMode | |
{ | |
Soft=0, | |
Hard=1, | |
Inherit=-1 | |
}; | |
struct MilRenderOptions | |
{ | |
TMILFlagsEnumMilRenderOptionFlagsEnum Flags; | |
int InterpolationMode; | |
MilBitmapBorderMode BorderMode; | |
int CompositingMode; | |
int BitmapScalingMode; | |
int DCompCompositeMode; | |
int OpacityMode; | |
int BackfaceVisibility; | |
int DepthMode; | |
unsigned int ForcePacking; | |
}; | |
struct MILCMD_VISUAL_SETRENDEROPTIONS | |
{ | |
int Type; | |
unsigned int Handle; | |
MilRenderOptions renderOptions; | |
}; | |
typedef long (*CVisual_ProcessSetRenderOptions_t)(void* thisPtr, void* resTbl, MILCMD_VISUAL_SETRENDEROPTIONS *pCmd); | |
CVisual_ProcessSetRenderOptions_t CVisual_ProcessSetRenderOptions_Original; | |
typedef void (*CRotateTransform3D_SetProperty_t)(void* thisPtr, unsigned int propId, int propType, void* prop); | |
CRotateTransform3D_SetProperty_t CRotateTransform3D_SetProperty_Original; | |
typedef void (*CRectangleGeometry_SetProperty_t)(void* thisPtr, unsigned int propId, int propType, void* prop); | |
CRectangleGeometry_SetProperty_t CRectangleGeometry_SetProperty_Original; | |
void* compositor = nullptr; | |
void* channel = nullptr; | |
void* CtorAdr = nullptr; | |
void* CResourceFactory_CreateAdr = nullptr; | |
void* CRectangleGeometry_vtbl = nullptr; | |
HRESULT CResourceFactory_CreateHook(void* comp, void* chnl, int type, void** res) | |
{ | |
if (!channel && compositor == comp) | |
{ | |
channel = chnl; | |
Wh_RemoveFunctionHook(CResourceFactory_CreateAdr); // I have no idea how to unhook functions using MinHook, this doesn't seem to work | |
} | |
return CResourceFactory_Create_Original(comp, chnl, type, res); | |
} | |
void CWindowNode_ctorHook(void* thisPtr, void* comp) | |
{ | |
if (!compositor) | |
{ | |
compositor = comp; | |
Wh_RemoveFunctionHook(CtorAdr); // I have no idea how to unhook functions using MinHook, this doesn't seem to work | |
} | |
return CWindowNode_ctor_Original(thisPtr, comp); | |
} | |
long CWindowNode_ProcessCreateHook(void* thisPtr, void* resTbl, void* msg) | |
{ | |
auto res = CWindowNode_ProcessCreate_Original(thisPtr, resTbl, msg); | |
HWND hwnd = CWindowNode_GetHwnd_Original(thisPtr); | |
if (hwnd && compositor != nullptr && channel != nullptr) | |
{ | |
TCHAR className[MAX_PATH]; | |
GetClassNameW(hwnd, className, _countof(className)); | |
if (wcsicmp(className, L"OMain") == 0) | |
{ | |
//void* effectRaw = malloc(0xE0); | |
//CGaussianBlurEffect_ctor_Original(effectRaw, compositor); | |
//CVisual_SetEffect_Original(thisPtr, effectRaw); | |
//CVisual_SetOpacity_Original(thisPtr, 0.5f); | |
MILCMD_VISUAL_SETRENDEROPTIONS options {}; | |
options.renderOptions.Flags.flags = MilRenderOptionFlagsEnum::BorderMode; | |
options.renderOptions.BorderMode = MilBitmapBorderMode::Soft; | |
CVisual_ProcessSetRenderOptions_Original(thisPtr, resTbl, &options); | |
void* transform = nullptr; | |
void* clip = nullptr; | |
auto hr = CResourceFactory_Create_Original(compositor, channel, 0x1A, &transform); | |
hr = CResourceFactory_Create_Original(compositor, channel, 0x48, &clip); | |
Wh_Log(L"HRESULT: %i", hr); | |
Wh_Log(L"Clip: %i", clip); | |
Wh_Log(L"Channel: %i", channel); | |
if (clip != nullptr && hr == S_OK) | |
{ | |
RECT rect; | |
GetClientRect(hwnd, &rect); | |
float angle = 180; | |
float x = rect.right / 2; | |
float y = rect.bottom / 2; | |
CRotateTransform3D_SetProperty_Original((void*)transform, 0, 0x12, &angle); | |
CRotateTransform3D_SetProperty_Original((void*)transform, 1, 0x12, &x); | |
CRotateTransform3D_SetProperty_Original((void*)transform, 2, 0x12, &y); | |
CVisual_SetTransform_Original(thisPtr, transform); | |
float left = rect.left; | |
float top = rect.top; | |
float right = rect.right; | |
float bottom = rect.bottom; | |
float radius = 64; | |
CRectangleGeometry_SetProperty_Original(clip, 1, 0x12, &left); | |
CRectangleGeometry_SetProperty_Original(clip, 2, 0x12, &top); | |
CRectangleGeometry_SetProperty_Original(clip, 3, 0x12, &right); | |
CRectangleGeometry_SetProperty_Original(clip, 4, 0x12, &bottom); | |
CRectangleGeometry_SetProperty_Original(clip, 5, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 6, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 7, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 8, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 9, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 10, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 11, 0x12, &radius); | |
CRectangleGeometry_SetProperty_Original(clip, 12, 0x12, &radius); | |
CVisual_SetClip_Original(thisPtr, clip); | |
//CVisual_SetOpacity_Original(thisPtr, 0.5f); | |
} | |
} | |
} | |
return res; | |
} | |
// The mod is being initialized, load settings, hook functions, and do other | |
// initialization stuff if required. | |
BOOL Wh_ModInit() { | |
Wh_Log(L"Init!"); | |
HMODULE dwmcMod = GetModuleHandle(L"dwmcore.dll"); | |
if (!dwmcMod) return FALSE; | |
WH_FIND_SYMBOL findSymbol; | |
HANDLE findSymbolHandle = Wh_FindFirstSymbol(dwmcMod, nullptr, &findSymbol); | |
if (!findSymbolHandle) { | |
Wh_Log(L"Wh_FindFirstSymbol failed"); | |
return FALSE; | |
} | |
void* ProcessCreateAdr = nullptr; | |
do { | |
if (wcsicmp(findSymbol.symbol, L"public: long __cdecl CWindowNode::ProcessCreate(class CResourceTable *,struct MILCMD_WINDOWNODE_CREATE const *)") == 0) | |
{ | |
ProcessCreateAdr = findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"protected: virtual struct HWND__ * __cdecl CWindowNode::GetHwnd(void)const ") == 0) | |
{ | |
CWindowNode_GetHwnd_Original = (CWindowNode_GetHwnd_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: void __cdecl CVisual::SetOpacity(float)") == 0) | |
{ | |
CVisual_SetOpacity_Original = (CVisual_SetOpacity_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"protected: __cdecl CWindowNode::CWindowNode(class CComposition *)") == 0) | |
{ | |
CtorAdr = findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"protected: __cdecl CGaussianBlurEffect::CGaussianBlurEffect(class CComposition *)") == 0) | |
{ | |
CGaussianBlurEffect_ctor_Original = (CGaussianBlurEffect_ctor_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"protected: long __cdecl CVisual::SetEffect(class CEffect *)") == 0) | |
{ | |
CVisual_SetEffect_Original = (CVisual_SetEffect_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"protected: static void * __cdecl CRectangleGeometry::operator new(unsigned __int64)") == 0) | |
{ | |
CRectangleGeometry_ctor_Original = (CRectangleGeometry_ctor_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"const CRectangleGeometry::`vftable'") == 0) | |
{ | |
CRectangleGeometry_vtbl = findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: virtual long __cdecl CRotateTransform3D::SetProperty(unsigned int,enum DCOMPOSITION_EXPRESSION_TYPE,void const *)") == 0) | |
{ | |
CRotateTransform3D_SetProperty_Original = (CRotateTransform3D_SetProperty_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: virtual long __cdecl CRectangleGeometry::SetProperty(unsigned int,enum DCOMPOSITION_EXPRESSION_TYPE,void const *)") == 0) | |
{ | |
CRectangleGeometry_SetProperty_Original = (CRectangleGeometry_SetProperty_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: long __cdecl CVisual::SetClip(class CGeometry *)") == 0) | |
{ | |
CVisual_SetClip_Original = (CVisual_SetClip_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: long __cdecl CVisual::ProcessSetRenderOptions(class CResourceTable *,struct MILCMD_VISUAL_SETRENDEROPTIONS const *)") == 0) | |
{ | |
CVisual_ProcessSetRenderOptions_Original = (CVisual_ProcessSetRenderOptions_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: long __cdecl CVisual::SetTransform(class CTransform3D *)") == 0) | |
{ | |
CVisual_SetTransform_Original = (CVisual_SetTransform_t)findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
else if (wcsicmp(findSymbol.symbol, L"public: static long __cdecl CResourceFactory::Create(class CComposition *,class CChannelContext *,enum MIL_RESOURCE_TYPE,class CResource * *)") == 0) | |
{ | |
CResourceFactory_CreateAdr = findSymbol.address; | |
Wh_Log(L"symbol: %s, Addr: %i", findSymbol.symbol, findSymbol.address); | |
} | |
} while (Wh_FindNextSymbol(findSymbolHandle, &findSymbol)); | |
Wh_FindCloseSymbol(findSymbolHandle); | |
if (ProcessCreateAdr == nullptr | |
|| CWindowNode_GetHwnd_Original == nullptr | |
|| CVisual_SetOpacity_Original == nullptr | |
|| CtorAdr == nullptr | |
|| CGaussianBlurEffect_ctor_Original == nullptr | |
|| CVisual_SetEffect_Original == nullptr | |
|| CRotateTransform3D_SetProperty_Original == nullptr | |
|| CRectangleGeometry_vtbl == nullptr | |
|| CRectangleGeometry_ctor_Original == nullptr | |
|| CVisual_SetClip_Original == nullptr | |
|| CResourceFactory_CreateAdr == nullptr | |
|| CVisual_SetTransform_Original == nullptr | |
|| CVisual_ProcessSetRenderOptions_Original == nullptr) | |
return FALSE; | |
Wh_SetFunctionHook(CResourceFactory_CreateAdr, (void*)CResourceFactory_CreateHook, (void**)&CResourceFactory_Create_Original); | |
Wh_SetFunctionHook(CtorAdr, (void*)CWindowNode_ctorHook, (void**)&CWindowNode_ctor_Original); | |
auto res = Wh_SetFunctionHook(ProcessCreateAdr, (void*)CWindowNode_ProcessCreateHook, (void**)&CWindowNode_ProcessCreate_Original); | |
Wh_Log(L"hook res: %i", res); | |
return TRUE; | |
} | |
// The mod is being unloaded, free all allocated resources. | |
void Wh_ModUninit() { | |
Wh_Log(L"Uninit"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment