-
Notifications
You must be signed in to change notification settings - Fork 1
/
VCLFixPack.pas
3072 lines (2681 loc) · 97.7 KB
/
VCLFixPack.pas
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{**************************************************************************************************}
{ }
{ VCLFixPack unit - Unoffical bug fixes for Delphi/C++Builder }
{ Version 1.4 (2009-09-03) }
{ }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the }
{ License at https://www.mozilla.org/MPL/ }
{ }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF }
{ ANY KIND, either express or implied. See the License for the specific language governing rights }
{ and limitations under the License. }
{ }
{ The Original Code is VCLFixPack.pas. }
{ }
{ The Initial Developer of the Original Code is Andreas Hausladen ([email protected]). }
{ Portions created by Andreas Hausladen are Copyright (C) 2008-2009 Andreas Hausladen. }
{ All Rights Reserved. }
{ }
{**************************************************************************************************}
// This contains fixes for Delphi 10, Delphi 11, Delphi 12 and above.
{$IFNDEF CONDITIONALEXPRESSIONS}
Delphi5_is_not_supported
{$ENDIF}
{$A8,B-,C+,D-,E-,F-,G+,H+,I+,J-,K-,L+,M-,N-,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{ If you define VCLFIXPACK_DEBUG the patches are compiled with debug information. }
{$IFDEF VCLFIXPACK_DEBUG} {$D+} {$ENDIF}
{ If you use Delphi 6/7/2005 Personal you must disable the VCLFIXPACK_DB_SUPPORT define. }
{$DEFINE VCLFIXPACK_DB_SUPPORT}
unit VCLFixPack;
interface
const
VCLFixPackRevision = '1.4';
VCLFixPackDate = '2009/03/09'; // yyyy/dd/mm
{
Usage
=====
Add the unit to the .dpr file's uses-list.
C++Builder user can add the file to the project (Menu Project/Add to project)
Example
=======
uses
FastMM4, // optional memory manager
VCLFixPack,
Forms,
Unit1 in 'Unit1.pas';
Fixes the following bug
=======================
- [2006-2009]
QC #74646: Buffer overflow in TCustomClientDataSet.DataConvert with ftWideString
(https://qc.codegear.com/wc/qcmain.aspx?d=74646)
- [2006-2009] fixed in Delphi 2009 Update 3
QC #68647: Infinite loop in Forms.GetNonToolWindowPopupParent
(https://qc.codegear.com/wc/qcmain.aspx?d=68647)
- [2007-2009] fixed in Delphi 2009 Update 3
QC #68740: Lost focus after TOpenDialog when MainFormOnTaskBar is set
(https://qc.codegear.com/wc/qcmain.aspx?d=68740)
- [2005-2009]
QC #59963: Closing non-modal forms after a task switch can deactivate the application
(https://qc.codegear.com/wc/qcmain.aspx?d=59963)
- [6-2007]
Control resize bugfix for kernel stack overflow due to WH_CALLWNDPROC hook
- [6-2007]
QC #59654: TActionList access already released FActions field
(https://qc.codegear.com/wc/qcmain.aspx?d=59654)
- [6-2007]
QC #54286 : Parent-PopupMenu overrides standard context menu (edit, memo, combobox, ...)
(https://qc.codegear.com/wc/qcmain.aspx?d=54286)
- [2006-2007]
QC #50097: ObjAuto access violation on XEON (Data Execution Prevention bug)
(https://qc.codegear.com/wc/qcmain.aspx?d=50097)
- [6-2009]
Classes.MakeObjectInstance memory leak fix
(for usage in a DLL)
- [2007]
QC #58938: MainForm Minimize minimizes in the background
(https://qc.codegear.com/wc/qcmain.aspx?d=58938)
- [6-2009] fixed in Delphi 2009 Update 3
QC #64484: SysUtils.Abort can raise an AccessViolation
(https://qc.codegear.com/wc/qcmain.aspx?d=64484)
- [2007]
QC #58939: No taskbar button when starting from ShellLink with Show=Minimized
(https://qc.codegear.com/wc/qcmain.aspx?d=58939)
- [6-2009] fixed in Delphi 2009 Update 3
QC #35001: MDIChild's active control focus is not set correctly
(https://qc.codegear.com/wc/qcmain.aspx?d=35001)
- [7-2009]
QC #56252: TPageControl flickers a lot with active theming
(https://qc.codegear.com/wc/qcmain.aspx?d=56252)
QC #68730: TLabel is not painted on a themed, double-buffered TTabSheet in Vista
(https://qc.codegear.com/wc/qcmain.aspx?d=68730)
TLabels on TTabSheet are not painted (themes) if a TWinControl like TMemo is on the TTabSheet (TWinControl.PaintWindow bug)
- [7-2009]
Grid flickers with active theming (DBGrid, StringGrid and DrawGrid only, no derived classes)
- [2009]
QC #69112: TSpeedButton is painted as a black rectangle on a double buffered panel on a sheet of glass.
- [2009]
QC #69294: TProgressBar fails with PBS_MARQUEE and disabled Themes (Vista)
https://qc.codegear.com/wc/qcmain.aspx?d=69294
- [Windows Vista]
Workaround for Windows Vista CompareString bug
(Workaround is disabled by default, define "VistaCompareStringFix" to activate it)
- [2007-2009]
QC #52439: DbNavigator paints incorrectly when flat=true in themed mode
- [2009]
QC #69875: StringBuilder.Replace is incorrect
QC #67564: Error in TStringBuilder.Replace
- [6-2009]
QC #7393: App with no main form showing a form with hints freezes
Changlog:
2009-09-03:
Added: QC #74646: Buffer overflow in TCustomClientDataSet.DataConvert with ftWideString
Fixed: TTabSheet looked stange if used with SilverThemes.
2009-05-30:
Changed: Disabled all patches that are fixed by Delphi 2009 Update 3
Added: QC #7393: App with no main form showing a form with hints freezes
2009-03-03:
Fixed: Rewritten patch for QC #59963 (AppDeActivateZOrderFix) to fix the cause instead of the symptom
Added: QC #52439: DbNavigator paints incorrectly when flat=true in themed mode
Added: QC #70441: ToUpper and ToLower modify a Const argument
Added: QC #69752: ToUpper and ToLower with NullString
Added: QC #69875, #67564: StringBuilder.Replace is incorrect
+ a much faster implementation
2009-01-25:
Fixed: DBGrid ScrollBar gab wasn't painted correctly in BiDiMode <> bdLeftToRight
Fixed: TTabSheet could throw an access violation if no PageControl was assigned to it
Changed: Rewritten TaskModalDialog bugfix
Added: QC #69294: TProgressBar fails with PBS_MARQUEE and disabled Themes (Vista)
}
{ ---------------------------------------------------------------------------- }
{$IF (CompilerVersion >= 18.0) and (CompilerVersion <= 20.0)}
{$IFDEF VCLFIXPACK_DB_SUPPORT}
{$DEFINE CDSDataConvertFix}
{$ENDIF VCLFIXPACK_DB_SUPPORT}
{$IFEND}
{$DEFINE DBTextColorBugFix} // Delphi 6+
{$IF (CompilerVersion >= 18.0) and (CompilerVersion < 20.0)} // Delphi 2006-2009, fixed in Delphi 2009 Update 3
{$DEFINE GetNonToolWindowPopupParentFix}
{$IFEND}
{$IF CompilerVersion = 18.5} // Delphi 2007-2009, fixed in Delphi 2009 Update 3
{$DEFINE TaskModalDialogFix}
{$IFEND}
{$IF CompilerVersion >= 16.0} // Delphi 2005
{$DEFINE AppDeActivateZOrderFix}
{$IFEND}
{$IF CompilerVersion < 20.0} // Delphi 6-2007
{$DEFINE ControlResizeFix}
{ The OPTIMIZED_RESIZE_REDRAW option is experimental. It speeds up the resizing of forms
by not redrawing each control when it is realigned but by invalidating them all after
one align round is done. }
{.$DEFINE OPTIMIZED_RESIZE_REDRAW}
{$IFEND}
{$IF CompilerVersion < 20.0} // Delphi 6-2007
{$DEFINE ActionListAVFix}
{$IFEND}
{$IF CompilerVersion < 20.0} // Delphi 6-2007
{$DEFINE ContextMenuFix}
{$IFEND}
{$IF (CompilerVersion >= 18.0) and (CompilerVersion < 20.0)} // Delphi 2006-2007
{$DEFINE ObjAutoDEPFix}
{$IFEND}
{$DEFINE MkObjInstLeakFix} // Delphi 6+
{$IF CompilerVersion < 20.0}
{$DEFINE SysUtilsAbortFix} // Delphi 6-2009, fixed in Delphi 2009 Update 3
{$IFEND}
{$IF CompilerVersion = 18.5} // Delphi 2007
{$DEFINE AppMinimizeFix}
{$IFEND}
{$IF CompilerVersion = 18.5} // Delphi 2007
{$DEFINE CmdShowMinimizeFix}
{$IFEND}
{$IF CompilerVersion < 20.0}
{$DEFINE MDIChildFocusFix} // Delphi 6-2009, fixed in Delphi 2009 Update 3
{$IFEND}
{$IF CompilerVersion >= 15} // Delphi 7+
{$DEFINE PageControlPaintingFix}
{$IFEND}
{$IF CompilerVersion >= 15} // Delphi 7+
{$DEFINE GridFlickerFix}
{$IFEND}
{$IF CompilerVersion = 20.0} // Delphi 2009
{$DEFINE SpeedButtonGlassFix}
{$IFEND}
{$IF CompilerVersion = 20.0} // Delphi 2009
{$DEFINE VistaProgressBarMarqueeFix}
{$IFEND}
{$IF CompilerVersion = 20.0} // Delphi 2009
{$DEFINE StringBuilderFix}
{$IFEND}
{$IF CompilerVersion <= 20.0} // Delphi 6-2009
{$DEFINE CancelHintDeadlockFix}
{$IFEND}
{$IF (CompilerVersion >= 18.5) and (CompilerVersion <= 20.0)} // Delphi 2007-2009
{$IFDEF VCLFIXPACK_DB_SUPPORT}
{$DEFINE DBNavigatorFix}
{$ENDIF VCLFIXPACK_DB_SUPPORT}
{$IFEND}
{**************************************************************************************************}
{ Workaround for Windows Vista CompareString bug. }
{ The �/� ($DC/$FC) and the UE/ue are treated equal in all locales, but they aren't equal. There }
{ was a bugfix intended for Vista SP1 but it was removed before SP1 was released. }
{ Windows 2008 Server still includes this bugfix but Vista will never get this bugfix. }
{ Microsoft: new versions are for correctness; service packs are for consistency and compatibility }
{**************************************************************************************************}
{ WARNING: This bugfix can slow down CompareString }
{.$DEFINE VistaCompareStringFix}
// Types and Procedures Made Public
type
TJumpOfs = Integer;
PPointer = ^Pointer;
type
PXRedirCode = ^TXRedirCode;
TXRedirCode = packed record
Jump: Byte;
Offset: TJumpOfs;
end;
procedure HookProc(Proc, Dest: Pointer; var BackupCode: TXRedirCode);
procedure UnhookProc(Proc: Pointer; var BackupCode: TXRedirCode);
implementation
{$IF CompilerVersion >= 18.0}
{$DEFINE DELPHI2006_UP}
{$IFEND}
{$IF CompilerVersion >= 17.0}
{$DEFINE DELPHI2005_UP}
{$IFEND}
uses
Windows, Messages, SysUtils, Classes, TypInfo, ActnList, SysConst,
{$IFDEF ObjAutoDEPFix}
ObjAuto,
{$ENDIF ObjAutoDEPFix}
{$IF CompilerVersion >= 15.0}
Themes,
{$IFEND}
{$IF CompilerVersion >= 20.0}
Character,
{$IFEND}
{$IFDEF VCLFIXPACK_DB_SUPPORT}
DB, DBClient, DBGrids, DBCtrls,
{$ENDIF VCLFIXPACK_DB_SUPPORT}
Controls,
Graphics, Forms, Dialogs, StdCtrls, Grids, ComCtrls, Buttons,
CommCtrl,
{$IF CompilerVersion >= 24.0}
Types
{$IFEND}
;
{ ---------------------------------------------------------------------------- }
{ Helper functions, shared }
type
TOpenWinControl = class(TWinControl);
TOpenCustomForm = class(TCustomForm);
TOpenCommonDialog = class(TCommonDialog);
TOpenCustomActionList = class(TCustomActionList);
TOpenComponent = class(TComponent);
TOpenCustomCombo = class(TCustomCombo);
PWin9xDebugThunk = ^TWin9xDebugThunk;
TWin9xDebugThunk = packed record
PUSH: Byte;
Addr: Pointer;
JMP: TXRedirCode;
end;
PAbsoluteIndirectJmp = ^TAbsoluteIndirectJmp;
TAbsoluteIndirectJmp = packed record
OpCode: Word; //$FF25(Jmp, FF /4)
Addr: PPointer;
end;
{ Hooking }
function GetActualAddr(Proc: Pointer): Pointer;
function IsWin9xDebugThunk(AAddr: Pointer): Boolean;
begin
Result := (AAddr <> nil) and
(PWin9xDebugThunk(AAddr).PUSH = $68) and
(PWin9xDebugThunk(AAddr).JMP.Jump = $E9);
end;
begin
if Proc <> nil then
begin
if (Win32Platform <> VER_PLATFORM_WIN32_NT) and IsWin9xDebugThunk(Proc) then
Proc := PWin9xDebugThunk(Proc).Addr;
if (PAbsoluteIndirectJmp(Proc).OpCode = $25FF) then
Result := PAbsoluteIndirectJmp(Proc).Addr^
else
Result := Proc;
end
else
Result := nil;
end;
procedure HookProc(Proc, Dest: Pointer; var BackupCode: TXRedirCode);
var
n: NativeUInt;
Code: TXRedirCode;
begin
Proc := GetActualAddr(Proc);
Assert(Proc <> nil);
if ReadProcessMemory(GetCurrentProcess, Proc, @BackupCode, SizeOf(BackupCode), n) then
begin
Code.Jump := $E9;
Code.Offset := PAnsiChar(Dest) - PAnsiChar(Proc) - SizeOf(Code);
WriteProcessMemory(GetCurrentProcess, Proc, @Code, SizeOf(Code), n);
end;
end;
procedure UnhookProc(Proc: Pointer; var BackupCode: TXRedirCode);
var
n: NativeUInt;
begin
if (BackupCode.Jump <> 0) and (Proc <> nil) then
begin
Proc := GetActualAddr(Proc);
Assert(Proc <> nil);
WriteProcessMemory(GetCurrentProcess, Proc, @BackupCode, SizeOf(BackupCode), n);
BackupCode.Jump := 0;
end;
end;
procedure ReplaceVmtField(AClass: TClass; OldProc, NewProc: Pointer);
type
PVmt = ^TVmt;
TVmt = array[0..MaxInt div SizeOf(Pointer) - 1] of Pointer;
var
I: Integer;
Vmt: PVmt;
n: NativeUInt;
P: Pointer;
begin
OldProc := GetActualAddr(OldProc);
NewProc := GetActualAddr(NewProc);
I := vmtSelfPtr div SizeOf(Pointer);
Vmt := Pointer(AClass);
while (I < 0) or (Vmt[I] <> nil) do
begin
P := Vmt[I];
if (P <> OldProc) and (Integer(P) > $10000) and not IsBadReadPtr(P, 6) then
P := GetActualAddr(P);
if P = OldProc then
begin
WriteProcessMemory(GetCurrentProcess, @Vmt[I], @NewProc, SizeOf(NewProc), n);
Exit;
end;
Inc(I);
end;
end;
function GetDynamicMethod(AClass: TClass; Index: Integer): Pointer;
asm
call System.@FindDynaClass
end;
procedure DebugLog(const S: string);
begin
OutputDebugString(PChar('VCLFixPack patch installed: ' + S));
end;
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ QC #68647: Infinite loop in Forms.GetNonToolWindowPopupParent }
{$IFDEF GetNonToolWindowPopupParentFix}
{
Forms.pas.4712: Result := GetParent(WndParent); <= must be "Result := GetParent(Result);"
56 push esi <= must be "push ebx"
E8181EFAFF call GetParent
8BD8 mov ebx,eax
Forms.pas.4711: while (Result <> 0) and (GetWindowLong(Result, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = WS_EX_TOOLWINDOW) do
85DB test ebx,ebx
}
procedure FixGetNonToolWindowPopupParent;
var
P: PAnsiChar;
Len: Integer;
Buf: Byte;
n: Cardinal;
begin
P := GetActualAddr(@TOpenCustomForm.CreateParams);
Dec(P);
Len := 0;
while Len < 112 do
begin
if //(P[0] = #$56) and // push esi
(P[1] = #$E8) and // call GetParent
(P[6] = #$8B) and (P[7] = #$D8) and // mov ebx,eax
(P[8] = #$85) and (P[9] = #$DB) then // test ebx,ebx
begin
if P[0] = #$56 then // push esi
begin
Buf := $53; // push esi (WndParent) => push ebx (Result)
WriteProcessMemory(GetCurrentProcess, P, @Buf, 1, n);
DebugLog('GetNonToolWindowPopupParentFix');
Exit;
end else
if P[0] = #$53 then // push ebx => already fixed, abort search
Exit;
end;
Dec(P);
Inc(Len);
end;
end;
{$ENDIF GetNonToolWindowPopupParentFix}
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ QC #68740: Lost focus after TOpenDialog when MainFormOnTaskBar is set }
{$IFDEF TaskModalDialogFix}
var
DialogsTaskModalDialogHook: TXRedirCode;
DialogsTaskModalDialogCritSect: TRTLCriticalSection;
function TCommonDialog_TaskModalDialog(Instance: TObject; DialogFunc: Pointer; var DialogData): Bool;
var
FocusWindow: HWND;
Func: function(Instance: TObject; DialogFunc: Pointer; var DialogData): Bool;
begin
EnterCriticalSection(DialogsTaskModalDialogCritSect);
try
UnhookProc(@TOpenCommonDialog.TaskModalDialog, DialogsTaskModalDialogHook);
try
FocusWindow := GetFocus;
try
Func := @TOpenCommonDialog.TaskModalDialog;
Result := Func(Instance, DialogFunc, DialogData);
finally
SetFocus(FocusWindow);
end;
finally
HookProc(@TOpenCommonDialog.TaskModalDialog, @TCommonDialog_TaskModalDialog, DialogsTaskModalDialogHook);
end;
finally
LeaveCriticalSection(DialogsTaskModalDialogCritSect);
end;
end;
procedure InitTaskModalDialogFix;
begin
InitializeCriticalSection(DialogsTaskModalDialogCritSect);
HookProc(@TOpenCommonDialog.TaskModalDialog, @TCommonDialog_TaskModalDialog, DialogsTaskModalDialogHook);
DebugLog('FixTaskModalDialog');
end;
procedure FiniTaskModalDialogFix;
begin
UnhookProc(@TOpenCommonDialog.TaskModalDialog, DialogsTaskModalDialogHook);
DeleteCriticalSection(DialogsTaskModalDialogCritSect);
end;
{$ENDIF TaskModalDialogFix}
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ QC #59963: Closing non-modal forms after a task switch can deactivate the application }
{$IFDEF AppDeActivateZOrderFix}
{
// Release
0047B1FD F6401C08 test byte ptr [eax+$1c],$08
0047B201 7522 jnz $0047b225 << replace by $90 $90 => nop nop
0047B203 8BC3 mov eax,ebx
0047B205 8B150C824500 mov edx,[$0045820c]
0047B20B E85C8BF8FF call @IsClass
0047B210 84C0 test al,al
0047B212 7509 jnz $0047b21d
0047B214 83BBCC01000000 cmp dword ptr [ebx+$000001cc],$00
0047B21B 7408 jz $0047b225
0047B21D 8B45FC mov eax,[ebp-$04]
0047B220 E8DFFDFFFF call TWinControl.UpdateShowing
0047B225 5E pop esi
0047B226 5B pop ebx
0047B227 59 pop ecx
0047B228 5D pop ebp
0047B229 C3 ret
}
procedure InitAppDeActivateZOrderFix;
var
P: PAnsiChar;
Len: Integer;
Buf: Word;
n: NativeUInt;
begin
P := GetActualAddr(@TWinControl.UpdateControlState);
Len := 0;
while Len < 200 do
begin
if (P[0] = #$F6) and (P[1] = #$40) and (P[2] = #$1C) and (P[3] = #$08) and // test byte ptr [eax+$1c],$08
(P[4] = #$75) and (P[5] = #$22) and // jnz +$22
(P[6] = #$8B) and (P[7] = #$C3) and // mov eax,ebx
(P[8] = #$8B) then // mov edx,[TCustomForm]
begin
Buf := $9090; // nop nop
WriteProcessMemory(GetCurrentProcess, @P[4], @Buf, SizeOf(Buf), n);
DebugLog('AppDeActivateZOrderFix');
Exit;
end
else
if (P[0] = #$59) and (P[0] = #$5D) and (P[1] = #$C3) then // function end reached
Break;
Inc(P);
Inc(Len);
end;
end;
procedure FiniAppDeActivateZOrderFix;
begin
end;
{$ENDIF AppDeActivateZOrderFix}
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ Control resize bugfix for kernel stack overflow due to WH_CALLWNDPROC hook }
{$IFDEF ControlResizeFix}
{2008-05-25:
- Added code to detect endless resizing controls.
- Added experimental OPTIMIZED_RESIZE_REDRAW option for faster form resizing }
var
WinControl_AlignControlProc, WinControl_WMSize, WinControl_SetBounds: Pointer;
BackupAlignControl, BackupWMSize, BackupSetBounds: TXRedirCode;
type
TControlResizeFixWinControl = class(TWinControl)
private
procedure AlignControl(AControl: TControl);
procedure HandleAlignControls(AControl: TControl; var R: TRect);
protected
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
end;
{$IFNDEF DELPHI2005_UP}
TD5WinControlPrivate = class(TControl)
public
FAlignLevel: Word;
end;
{$ENDIF ~DELPHI2005_UP}
threadvar
AlignControlList: TList;
procedure TControlResizeFixWinControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
WindowPlacement: TWindowPlacement;
begin
if (ALeft <> Left) or (ATop <> Top) or
(AWidth <> Width) or (AHeight <> Height) then
begin
if HandleAllocated and not IsIconic(WindowHandle) then
begin
if AlignControlList <> nil then
SetWindowPos(WindowHandle, 0, ALeft, ATop, AWidth, AHeight,
SWP_NOZORDER or SWP_NOACTIVATE or SWP_DEFERERASE)
else
SetWindowPos(WindowHandle, 0, ALeft, ATop, AWidth, AHeight,
SWP_NOZORDER or SWP_NOACTIVATE);
end
else
begin
PInteger(@Left)^ := ALeft;
PInteger(@Top)^ := ATop;
PInteger(@Width)^ := AWidth;
PInteger(@Height)^ := AHeight;
if HandleAllocated then
begin
WindowPlacement.Length := SizeOf(WindowPlacement);
GetWindowPlacement(WindowHandle, @WindowPlacement);
WindowPlacement.rcNormalPosition := BoundsRect;
SetWindowPlacement(WindowHandle, @WindowPlacement);
end;
end;
UpdateBoundsRect(Rect(Left, Top, Left + Width, Top + Height));
RequestAlign;
end;
end;
procedure TControlResizeFixWinControl.HandleAlignControls(AControl: TControl; var R: TRect);
function AlignWork: Boolean;
var
I: Integer;
begin
Result := True;
for I := ControlCount - 1 downto 0 do
if (Controls[I].Align <> alNone) or
(Controls[I].Anchors <> [akLeft, akTop]) then
Exit;
Result := False;
end;
var
OwnAlignControlList, TempAlignControlList: TList;
ResizeList: TList;
ResizeCounts: TList; // of Integer
Ctrl: TWinControl;
I, Index: Integer;
begin
if AlignWork then
begin
OwnAlignControlList := nil;
try
if AlignControlList = nil then
begin
OwnAlignControlList := TList.Create;
AlignControlList := OwnAlignControlList;
end;
AlignControls(AControl, R);
if (OwnAlignControlList <> nil) and (OwnAlignControlList.Count > 0) then
begin
{ Convert recursion into an iteration to prevent the kernel stack overflow }
ResizeList := TList.Create;
ResizeCounts := TList.Create;
try
{ The controls in the OwnAlignControlList must be added to ResizeList in reverse order.
Otherwise the OnResize events aren't fired in correct order. }
AlignControlList := TList.Create;
try
repeat
try
for I := OwnAlignControlList.Count - 1 downto 0 do
begin
Ctrl := TWinControl(OwnAlignControlList[I]);
Index := ResizeList.IndexOf(Ctrl);
{ An endless resizing component was stopped by the kernel stack overflow bug.
So we must catch this condition to prevent an endless loop. }
if (Index = -1) or (Integer(ResizeCounts[Index]) < 30) then
begin
Ctrl.Realign;
if Index <> -1 then
ResizeCounts[Index] := Pointer(Integer(ResizeCounts[Index]) + 1);
ResizeCounts.Add(Pointer(0)); // keep index in sync
ResizeList.Add(Ctrl);
end
else if Index <> -1 then
begin
{$WARNINGS OFF}
if DebugHook <> 0 then
{$WARNINGS ON}
OutputDebugString(PChar(Format('The component "%s" of class %s has an endless resize loop', [Ctrl.Name, Ctrl.ClassName])));
end;
end;
finally
OwnAlignControlList.Clear;
{ Switch lists }
TempAlignControlList := AlignControlList;
AlignControlList := OwnAlignControlList;
OwnAlignControlList := TempAlignControlList;
end;
until (OwnAlignControlList.Count = 0) {or EndlessResizeDetection};
finally
{ Let another AlignControlList handle any alignment that comes from the
OnResize method. }
FreeAndNil(AlignControlList);
end;
{ Fire Resize events }
for I := ResizeList.Count - 1 downto 0 do
begin
Ctrl := TWinControl(ResizeList[I]);
if not (csLoading in Ctrl.ComponentState) then
TOpenWinControl(Ctrl).Resize;
end;
finally
ResizeCounts.Free;
ResizeList.Free;
end;
{$IFDEF OPTIMIZED_RESIZE_REDRAW}
Invalidate;
{$ENDIF OPTIMIZED_RESIZE_REDRAW}
end;
finally
if OwnAlignControlList <> nil then
begin
AlignControlList := nil;
FreeAndNil(OwnAlignControlList);
end;
end;
end
else
AlignControls(AControl, R);
end;
procedure TControlResizeFixWinControl.WMSize(var Message: TWMSize);
begin
{$IFDEF DELPHI2005_UP}
UpdateBounds;
{$IFDEF DELPHI2006_UP}
UpdateExplicitBounds;
{$ENDIF DELPHI2006_UP}
{$ELSE}
if HandleAllocated then
Perform(WM_MOVE, 0, LPARAM(Left and $0000ffff) or (Top shl 16)); // calls the private UpdateBounds
{$ENDIF DELPHI2005_UP}
DefaultHandler(Message);
if AlignControlList <> nil then
begin
if AlignControlList.IndexOf(Self) = -1 then
AlignControlList.Add(Self)
end
else
begin
Realign;
if not (csLoading in ComponentState) then
Resize;
end;
end;
procedure TControlResizeFixWinControl.AlignControl(AControl: TControl);
var
Rect: TRect;
begin
if not HandleAllocated or (csDestroying in ComponentState) then
Exit;
{$IFDEF DELPHI2005_UP}
if AlignDisabled then
{$ELSE}
if TD5WinControlPrivate(Self).FAlignLevel <> 0 then
{$ENDIF DELPHI2005_UP}
ControlState := ControlState + [csAlignmentNeeded]
else
begin
DisableAlign;
try
Rect := GetClientRect;
HandleAlignControls(AControl, Rect);
finally
ControlState := ControlState - [csAlignmentNeeded];
EnableAlign;
end;
end;
end;
function GetAlignControlProc: Pointer;
var
P: PByteArray;
Offset: Integer;
MemInfo: TMemoryBasicInformation;
begin
P := GetActualAddr(@TWinControl.Realign);
if (P <> nil) and (VirtualQuery(P, MemInfo, SizeOf(MemInfo)) = SizeOf(MemInfo)) then
begin
if (MemInfo.AllocationProtect <> PAGE_NOACCESS) then
begin
Offset := 0;
while Offset < $40 do
begin
if ((P[0] = $33) and (P[1] = $D2)) or // xor edx,edx
((P[0] = $31) and (P[1] = $D2)) then // xor edx,edx
begin
if P[2] = $E8 then // call TWinControl.AlignControl
begin
Inc(PByte(P), 2);
Result := PAnsiChar(P) + 5 + PInteger(PAnsiChar(P) + 1)^;
Exit;
end
else if (P[2] = $8B) and (P[3] = $45) and (P[4] = $FC) and // mov eax,[ebp-$04]
(P[5] = $E8) then // call TWinControl.AlignControl
begin
Inc(PByte(P), 5);
Result := PAnsiChar(P) + 5 + PInteger(PAnsiChar(P) + 1)^;
Exit;
end;
end;
Inc(PByte(P));
Inc(Offset);
end;
end;
end;
Result := nil;
end;
procedure InitControlResizeFix;
begin
WinControl_AlignControlProc := GetAlignControlProc;
WinControl_WMSize := GetDynamicMethod(TWinControl, WM_SIZE);
WinControl_SetBounds := @TOpenWinControl.SetBounds;
if (WinControl_AlignControlProc <> nil) and (WinControl_WMSize <> nil) then
begin
DebugLog('ControlResizeFix');
{ Redirect the original function to the bug fixed version }
HookProc(WinControl_AlignControlProc, @TControlResizeFixWinControl.AlignControl, BackupAlignControl);
HookProc(WinControl_WMSize, @TControlResizeFixWinControl.WMSize, BackupWMSize);
{$IFDEF OPTIMIZED_RESIZE_REDRAW}
HookProc(WinControl_SetBounds, @TControlResizeFixWinControl.SetBounds, BackupSetBounds);
{$ENDIF OPTIMIZED_RESIZE_REDRAW}
end;
end;
procedure FiniControlResizeFix;
begin
{ Restore the original function }
UnhookProc(WinControl_AlignControlProc, BackupAlignControl);
UnhookProc(WinControl_WMSize, BackupWMSize);
UnhookProc(WinControl_SetBounds, BackupSetBounds);
end;
{$ENDIF ControlResizeFix}
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ QC #59654: TActionList access already released FActions field }
{$IFDEF ActionListAVFix}
var
HookTCustomActionList_Notification: TXRedirCode;
type
TCustomActionListFix = class(TCustomActionList)
protected
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
end;
procedure TCustomActionListFix.Notification(AComponent: TComponent; Operation: TOperation);
var
P: procedure(Instance: TComponent; AComponent: TComponent; Operation: TOperation);
begin
{ inherited: }
P := @TOpenComponent.Notification;
P(Self, AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = Images then
Images := nil
else if {<*}not (csDestroying in ComponentState) and{*>} (AComponent is TContainedAction) then
RemoveAction(TContainedAction(AComponent));
end;
end;
procedure InitActionListAVFix;
begin
DebugLog('ActionListAVFix');
HookProc(@TOpenCustomActionList.Notification, @TCustomActionListFix.Notification, HookTCustomActionList_Notification);
end;
procedure FiniActionListAVFix;
begin
UnhookProc(@TOpenCustomActionList.Notification, HookTCustomActionList_Notification);
end;
{$ENDIF ActionListAVFix}
{ ---------------------------------------------------------------------------- }
{ ---------------------------------------------------------------------------- }
{ QC #54286 : Parent-PopupMenu overrides standard context menu (edit, memo, combobox, ...) }
{$IFDEF ContextMenuFix}
type
TContextMenuFixWinControl = class(TWinControl)
public
procedure DefaultHandler(var Message); override;
end;
var
RM_GetObjectInstance: DWORD;
BackupDefaultHandler: TXRedirCode;
procedure TContextMenuFixWinControl.DefaultHandler(var Message);
type
TDefHandler = procedure(Self: TControl; var Message);
begin
if HandleAllocated then
begin
with TMessage(Message) do
begin
{ Here was the WM_CONTEXTMENU Code that is not necessary because
DefWndProc will send this message to the parent control. }
{ Keep the odd bahavior for grids because everybody seems to be used to it. }
if (Msg = WM_CONTEXTMENU) and (Parent <> nil) and (Parent is TCustomGrid) then
begin
Result := Parent.Perform(Msg, WParam, LParam);
if Result <> 0 then Exit;
end;
case Msg of
WM_CTLCOLORMSGBOX..WM_CTLCOLORSTATIC:
Result := SendMessage(LParam, CN_BASE + Msg, WParam, LParam);
CN_CTLCOLORMSGBOX..CN_CTLCOLORSTATIC:
begin
SetTextColor(WParam, ColorToRGB(Font.Color));
SetBkColor(WParam, ColorToRGB(Brush.Color));
Result := Brush.Handle;
end;
else
if Msg = RM_GetObjectInstance then
Result := LRESULT(Self)
else
Result := CallWindowProc(DefWndProc, Handle, Msg, WParam, LParam);
end;
if Msg = WM_SETTEXT then
SendDockNotification(Msg, WParam, LParam);
end;
end
else
//inherited DefaultHandler(Message);
TDefHandler(@TControl.DefaultHandler)(Self, Message);
end;
procedure InitContextMenuFix;
var
HInst: HMODULE;
begin
HInst := FindHInstance(Pointer(TWinControl)); // get the HInstance of the module that contains Controls.pas
RM_GetObjectInstance := RegisterWindowMessage(PChar(Format('ControlOfs%.8X%.8X', [HInst, GetCurrentThreadId])));
DebugLog('ContextMenuFix');
{ Redirect the original function to the bug fixed version }
HookProc(@TWinControl.DefaultHandler, @TContextMenuFixWinControl.DefaultHandler, BackupDefaultHandler);
end;
procedure FiniContextMenuFix;
begin
UnhookProc(@TWinControl.DefaultHandler, BackupDefaultHandler);
end;