-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
TaskbarDll.dpr
233 lines (200 loc) · 6.23 KB
/
TaskbarDll.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
{
DLL system hooking for mouse's position, taskbar drawing, etc.
Currently it hooks mouse position in order no to use delphi's method
which is not really appropriate, but it has disadvantages on privileged
levels windows on focus, it won't work.
}
library TaskbarDll;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
System.SysUtils,
System.Classes,
Variants,
Winapi.Windows,
DWMAPI,
Messages,
DDetours;
{$R *.res}
const
MemMapFile ='TaskbarDocks';
WCA_ACCENT_POLICY = 19;
ACCENT_ENABLE_GRADIENT = 1;
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2;
ACCENT_ENABLE_BLURBEHIND = 3;
ACCENT_ENABLE_BLURBEHINDFLUENT = 4;
ACCENT_DEFAULT = 99;
type
AccentPolicy = packed record
AccentState: Integer;
AccentFlags: Integer;
GradientColor: Integer;
AnimationId: Integer;
end;
WindowCompositionAttributeData = packed record
Attribute: Cardinal;
Data: Pointer;
SizeOfData: Integer;
end;
PDLLGlobal = ^TDLLGlobal;
TDLLGlobal = packed record
HookHandle: HHOOK;
end;
var
GlobalData: PDLLGlobal;
MMF: THandle;
TrampolineMessageBoxW: function(hWnd: HWND; lpText, lpCaption: LPCWSTR; uType: UINT): Integer;
stdcall = nil;
TrampolineSetWindowCompositionAttribute: function (hWnd: HWND; var data: WindowCompositionAttributeData): Integer;
stdcall = nil;
function SetWindowCompositionAttribute(Wnd: HWND; const AttrData: WindowCompositionAttributeData): BOOL; stdcall;
external user32 Name 'SetWindowCompositionAttribute';
function SetWindowCompositionAttributeHooked (hWnd: HWND; var data: WindowCompositionAttributeData): Integer;
var
accent: AccentPolicy;
_data: WindowCompositionAttributeData;
begin
if hwnd = FindWindow('Shell_TrayWnd',nil) then
begin
OutputDebugString(PChar('HWND: '+inttostr(hwnd)));
accent.AccentState := ACCENT_ENABLE_TRANSPARENTGRADIENT;
accent.GradientColor := $00000;//accent.GradientColor;
_data.Attribute := WCA_ACCENT_POLICY;
_data.SizeOfData := SizeOf(accent);
_data.Data := @accent;
end
else
_data := data;
Result := TrampolineSetWindowCompositionAttribute(hWnd, _data);
end;
function StartThread(pFunction: TFNThreadStartRoutine;
iPriority: Integer = THREAD_PRIORITY_NORMAL;
iStartFlag: Integer = 0): THandle;
var
ThreadId: DWORD;
begin
Result := CreateThread(nil, 0, pFunction, nil, iStartFlag, ThreadId);
if Result <> NULL then
SetThreadPriority(Result, iPriority);
end;
function CloseThread(ThreadHandle: THandle): Boolean;
begin
Result := TerminateThread(ThreadHandle, 1);
CloseHandle(ThreadHandle);
end;
procedure ThisIsTheThread;
begin
// MessageBoxW(0, 'Hola chico', 'ñol', 0);
@TrampolineSetWindowCompositionAttribute
:= InterceptCreate(@SetWindowCompositionAttribute,@SetWindowCompositionAttributeHooked);
end;
procedure Run;
var
hThread: THandle;
begin
hThread := StartThread(@ThisIsTheThread);
hThread := StartThread(@ThisIsTheThread, THREAD_PRIORITY_ERROR_RETURN);
CloseThread(hThread);
end;
procedure mydllproc(Reason: Integer);
begin
case Reason of
DLL_PROCESS_ATTACH:
begin
OutputDebugString('hola');
Run;
end;
DLL_PROCESS_DETACH:
begin
if Assigned(@TrampolineSetWindowCompositionAttribute) then
begin
InterceptRemove(@TrampolineSetWindowCompositionAttribute);
TrampolineSetWindowCompositionAttribute := nil;
end;
end;
end;
end;
function MouseProc(Code: Integer; wParam: WPARAM; lParam: LPARAM): HRESULT; stdcall;
var
TargetWnd: THandle;
Msg: PCopyDataStruct;
begin
if (Code < 0) or (Code = HC_NOREMOVE) then
begin
Result := CallNextHookEx(GlobalData^.HookHandle, Code, wParam, lParam);
Exit;
end;
if (wParam = WM_MOUSEMOVE) then
begin
TargetWnd := FindWindow('TaskbarDocks', nil);
if TargetWnd <> 0 then
begin
New(Msg);
Msg^.dwData := 0;
Msg^.cbData := SizeOf(TMouseHookStruct) + 1;
Msg^.lpData := PMouseHookStruct(lParam);
SendMessageTimeout(TargetWnd, WM_COPYDATA, 0, Integer(Msg), SMTO_ABORTIFHUNG, 50, nil);
Dispose(Msg);
end;
end;
Result := CallNextHookEx(GlobalData^.HookHandle, Code, wParam, lParam);
end;
procedure CreateGlobalHeap;
begin
MMF := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(TDLLGlobal), MemMapFile);
if MMF = 0 then
begin
MessageBox(0, 'CreateFileMapping failed', '', 0);
Exit;
end;
GlobalData := MapViewOfFile(MMF, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TDLLGlobal));
if GlobalData = nil then
begin
CloseHandle(MMF);
MessageBox(0, 'MapViewFile failed', '', 0);
end;
end;
procedure DeleteGlobalHeap;
begin
if GlobalData <> nil then
UnmapViewOfFile(GlobalData);
if MMF <> INVALID_HANDLE_VALUE then
CloseHandle(MMF);
end;
procedure RunHook; stdcall;
begin
OutputDebugString('empezamos');
GlobalData^.HookHandle := SetWindowsHookEx(WH_MOUSE_LL, @MouseProc, HInstance, 0);
if GlobalData^.HookHandle = INVALID_HANDLE_VALUE then
begin
MessageBox(0, 'Error', '', MB_OK);
Exit;
end;
end;
procedure KillHook; stdcall;
begin
if (GlobalData <> nil) and (GlobalData^.HookHandle <> INVALID_HANDLE_VALUE) then
UnhookWindowsHookEx(GlobalData^.HookHandle);
end;
procedure DLLEntry(dwReason: DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH: CreateGlobalHeap;
DLL_PROCESS_DETACH: DeleteGlobalHeap;
end;
end;
exports
KillHook,
RunHook;
begin
OutputDebugString('empezamos');
DllProc := @DllEntry; //mydllproc;
DllEntry(DLL_PROCESS_ATTACH); //mydllproc(DLL_PROCESS_ATTACH);
end.