Skip to content

Commit

Permalink
Fixes #1 (the menu is now skinned) (v22000.1.0.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
valinet committed Aug 12, 2021
1 parent c2fa263 commit 2560089
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 21 deletions.
8 changes: 4 additions & 4 deletions ExplorerPatcher/ExplorerPatcher.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 22000,1,0,1
PRODUCTVERSION 22000,1,0,1
FILEVERSION 22000,1,0,2
PRODUCTVERSION 22000,1,0,2
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "VALINET Solutions SRL"
VALUE "FileDescription", "ExplorerPatcher Daemon"
VALUE "FileVersion", "22000.1.0.1"
VALUE "FileVersion", "22000.1.0.2"
VALUE "InternalName", "ExplorerPatcher.exe"
VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved."
VALUE "OriginalFilename", "ExplorerPatcher.exe"
VALUE "ProductName", "ExplorerPatcher"
VALUE "ProductVersion", "22000.1.0.1"
VALUE "ProductVersion", "22000.1.0.2"
END
END
BLOCK "VarFileInfo"
Expand Down
3 changes: 3 additions & 0 deletions ExplorerPatcher/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")

#define DEBUG
#undef DEBUG

#define CLASS_NAME TEXT("ExplorerPatcher")
#define APP_NAME TEXT("Windows Explorer")
#define NOP 0x90
Expand Down
8 changes: 4 additions & 4 deletions ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 22000,1,0,1
PRODUCTVERSION 22000,1,0,1
FILEVERSION 22000,1,0,2
PRODUCTVERSION 22000,1,0,2
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "VALINET Solutions SRL"
VALUE "FileDescription", "ExplorerPatcher Library"
VALUE "FileVersion", "22000.1.0.1"
VALUE "FileVersion", "22000.1.0.2"
VALUE "InternalName", "ExplorerPatcherLibrary.dll"
VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved."
VALUE "OriginalFilename", "ExplorerPatcherLibrary.dll"
VALUE "ProductName", "WinOverview"
VALUE "ProductVersion", "22000.1.0.1"
VALUE "ProductVersion", "22000.1.0.2"
END
END
BLOCK "VarFileInfo"
Expand Down
138 changes: 125 additions & 13 deletions ExplorerPatcherLibrary/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#pragma comment(lib, "Psapi.lib") // required by funchook
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
#include <dwmapi.h>
#pragma comment(lib, "Dwmapi.lib")


#define DEBUG
#undef DEBUG

funchook_t* funchook = NULL;
HMODULE hModule = NULL;
Expand Down Expand Up @@ -61,12 +64,26 @@ static INT64(*ImmersiveContextMenuHelper_ApplyOwnerDrawToMenu)(
void* data
);

static void(*ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenu)(
HMENU _this,
HMENU hWnd,
HWND a3
);

static INT64(*CLauncherTipContextMenu_GetMenuItemsAsync)(
void* _this,
void* rect,
void** iunk
);

static INT64(*CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProc)(
HWND hWnd,
int a2,
HWND a3,
int a4,
BOOL* a5
);

DEFINE_GUID(IID_ILauncherTipContextMenu,
0xb8c1db5f,
0xcbb3, 0x48bc, 0xaf, 0xd9,
Expand Down Expand Up @@ -102,6 +119,87 @@ static BOOL(*IsDesktopInputContextFunc)(

HANDLE hThread;

LRESULT CALLBACK CLauncherTipContextMenu_WndProc(
_In_ HWND hWnd,
_In_ UINT uMsg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
LRESULT result;

if (uMsg == WM_NCCREATE)
{
CREATESTRUCT* pCs = lParam;
if (pCs->lpCreateParams)
{
*((HWND*)((char*)pCs->lpCreateParams + 0x78)) = hWnd;
SetWindowLongPtr(
hWnd,
GWLP_USERDATA,
pCs->lpCreateParams
);
result = DefWindowProc(
hWnd,
uMsg,
wParam,
lParam
);
}
else
{
result = 0;
}
}
else
{
void* _this = GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (_this)
{
BOOL v12 = FALSE;
if ((uMsg == WM_DRAWITEM || uMsg == WM_MEASUREITEM) &&
CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProc(
hWnd,
uMsg,
wParam,
lParam,
&v12
))
{
result = 0;
}
else
{
result = DefWindowProc(
hWnd,
uMsg,
wParam,
lParam
);
}
if (uMsg == WM_NCDESTROY)
{
SetWindowLongPtrW(
hWnd,
GWLP_USERDATA,
0
);
*((HWND*)((char*)_this + 0x78)) = 0;
}
}
else
{
result = DefWindowProc(
hWnd,
uMsg,
wParam,
lParam
);
}
}
return result;
}

typedef struct
{
void* _this;
Expand All @@ -115,7 +213,7 @@ DWORD ShowLauncherTipContextMenu(
{
WNDCLASS wc = { 0 };
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = DefWindowProc; // CLauncherTipContextMenu_WndProc
wc.lpfnWndProc = CLauncherTipContextMenu_WndProc;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = CLASS_NAME;
Expand All @@ -134,7 +232,7 @@ DWORD ShowLauncherTipContextMenu(
0,
0,
GetModuleHandle(NULL),
params->_this,
(char*)params->_this - 0x58,
7
);
ShowWindow(hWnd, SW_SHOW);
Expand All @@ -149,16 +247,14 @@ DWORD ShowLauncherTipContextMenu(
goto finalize;
}

/*
void* v25 = 0;
INT64* unknown_array = calloc(4, sizeof(INT64));
ImmersiveContextMenuHelper_ApplyOwnerDrawToMenu(
*((HMENU*)((char*)params->_this + 0xe8)),
hWnd,
&(params->point),
0xc,
&v25
unknown_array
);
*/

BOOL res = TrackPopupMenu(
*((HMENU*)((char*)params->_this + 0xe8)),
Expand All @@ -169,6 +265,14 @@ DWORD ShowLauncherTipContextMenu(
hWnd,
0
);

ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenu(
*((HMENU*)((char*)params->_this + 0xe8)),
hWnd,
&(params->point)
);
free(unknown_array);

if (res > 0)
{
if (res < 4000)
Expand All @@ -189,8 +293,6 @@ DWORD ShowLauncherTipContextMenu(
}
}

// ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenu

finalize:
params->iunk->lpVtbl->Release(params->iunk);
SendMessage(
Expand Down Expand Up @@ -337,19 +439,23 @@ __declspec(dllexport) DWORD WINAPI main(
_In_ LPVOID lpParameter
)
{
/*
#ifdef DEBUG
FILE* conout;
AllocConsole();
freopen_s(&conout, "CONOUT$", "w", stdout);
*/
freopen_s(
&conout,
"CONOUT$",
"w",
stdout
);
#endif

int rv;
if (!funchook)
{
messageWindow = (HWND)lpParameter;



funchook = funchook_create();


Expand All @@ -362,6 +468,9 @@ __declspec(dllexport) DWORD WINAPI main(

HANDLE hTwinuiPcshell = GetModuleHandle(L"twinui.pcshell.dll");

CImmersiveContextMenuOwnerDrawHelper_s_ContextMenuWndProc = (INT64(*)(HWND, int, HWND, int, BOOL*))
((uintptr_t)hTwinuiPcshell + 0xB0E12);

InternalAddRef = (INT64(*)(void*, INT64))
((uintptr_t)hTwinuiPcshell + 0x46650);

Expand All @@ -370,6 +479,9 @@ __declspec(dllexport) DWORD WINAPI main(

ImmersiveContextMenuHelper_ApplyOwnerDrawToMenu = (INT64(*)(HMENU, HMENU, HWND, unsigned int, void*))
((uintptr_t)hTwinuiPcshell + 0x535AF8);

ImmersiveContextMenuHelper_RemoveOwnerDrawFromMenu = (void(*)(HMENU, HMENU, HWND))
((uintptr_t)hTwinuiPcshell + 0x536300);

CLauncherTipContextMenu_ExecuteShutdownCommand = (void(*)(void*, void*))
((uintptr_t)hTwinuiPcshell + 0x514714);
Expand Down

0 comments on commit 2560089

Please sign in to comment.