-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFormats.cs
1920 lines (1711 loc) · 75.1 KB
/
Formats.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.Serialization;
using System.Security.Claims;
using System.Security.Policy;
using System.Text;
// Disable IDE warnings that showed up after going from C# 7 to C# 9
#pragma warning disable IDE0079 // Disable message about unnecessary suppression
#pragma warning disable IDE1006 // Disable messages about capitalization of control names
#pragma warning disable IDE0063 // Disable messages about Using expression simplification
#pragma warning disable IDE0090 // Disable messages about New expression simplification
#pragma warning disable IDE0028,IDE0300,IDE0305 // Disable message about inputArray initialization
#pragma warning disable IDE0074 // Disable message about compound assignment for checking if null
#pragma warning disable IDE0066 // Disable message about switch case expression
// Nullable reference types
#nullable enable
// Notes:
// This file contains struct definitions for various clipboard formats. The definitions are based on the official Microsoft documentation.
// But it also contains classes that mirror the structs, which may contain lists in place of arrays and other differences to make them easier to parse
// The actual structs are used with Marshal to read the data from the clipboard. The classes are used to store the data in a more readable format as an object
// Structs are really only used for certain standard clipboard formats, since those formats often are just pointers to the struct, and Marsshal requires a struct to copy the data out
// Then the class version can be used to process those too. Some don't require the struct to get the data out, so the class is used directly
namespace EditClipboardContents
{
// Win32 API Types defined explicitly to avoid confusion and ensure compatibility with Win32 API, and it matches with documentation
// See: https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types
//using BOOL = System.Int32; // 4 Bytes
using LONG = System.Int32; // 4 Bytes
using ULONG = System.UInt32; // 4 Bytes
using DWORD = System.UInt32; // 4 Bytes, aka uint, uint32
using WORD = System.UInt16; // 2 Bytes
using BYTE = System.Byte; // 1 Byte
using FXPT2DOT30 = System.Int32; // 4 Bytes , aka LONG
using LPVOID = System.IntPtr; // Handle to any type
using HMETAFILE = System.IntPtr; // Handle to metafile
using CHAR = System.Byte; // 1 Byte
using WCHAR = System.Char; // 2 Bytes
using USHORT = System.UInt16; // 2 Bytes
using UINT32 = System.UInt32; // 4 Bytes
using INT16 = System.Int16; // 2 Bytes
using UINT = System.UInt32; // 4 Bytes
using CLIPFORMAT = System.UInt16; // 2 Bytes, aka WORD
using static System.Net.WebRequestMethods;
public static class ClipboardFormats
{
public interface IClipboardFormat
{
string? GetDocumentationUrl();
string? StructName();
Dictionary<string, string> DataDisplayReplacements();
List<string> PropertiesNoProcess();
void SetCacheStructObjectDisplayInfo(string structInfo);
string GetCacheStructObjectDisplayInfo();
IEnumerable<(string Name, object? Value, Type Type, int? ArraySize)> EnumerateProperties(bool getValues = false);
bool FillEmptyArrayWithRemainingBytes();
int MaxStringLength();
}
public abstract class ClipboardFormatBase : IClipboardFormat
{
// Protected method to be implemented by derived classes. But if it's en enum then check for StructNameAttribute
protected virtual string? GetStructName()
{
Type type = this.GetType();
if (type.IsEnum)
{
var attr = type.GetCustomAttribute<EnumNameAttribute>();
if (attr != null)
return attr.Name;
else
return null;
}
else
{
return null;
}
}
// Public method to access the struct name
public string? StructName() => GetStructName();
// MaxStringLength method
public virtual int MaxStringLength() => 0;
// Private field to store the cached struct display info
private string? _cachedStructDisplayInfo;
// Default implementation for FillEmptyArrayWithRemainingBytes - If the last array should be filled with bytes. Defaults to false
public virtual bool FillEmptyArrayWithRemainingBytes() => false;
// Common methods apply to all classes of the type
public virtual string? GetDocumentationUrl()
{
string? structName = StructName();
if (structName == null || !FormatInfoHardcoded.StructDocsLinks.ContainsKey(structName))
{
return null;
}
else
{
return FormatInfoHardcoded.StructDocsLinks[structName];
}
}
// Default implementation for DataDisplayReplacements - Things that need to be replaced or pre-processed before displaying
public virtual Dictionary<string, string> DataDisplayReplacements() => new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// Properties to not even process into the object because it won't be used at all
public virtual List<string> PropertiesNoProcess() => new List<string>();
// Method to cache the display info of the struct object
public void SetCacheStructObjectDisplayInfo(string structInfo)
{
_cachedStructDisplayInfo = structInfo;
}
// Method to retrieve the cached display info of the struct object
public string GetCacheStructObjectDisplayInfo()
{
return _cachedStructDisplayInfo ?? string.Empty;
}
public virtual IEnumerable<(string Name, object? Value, Type Type, int? ArraySize)> EnumerateProperties(bool getValues = false)
{
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var property in properties)
{
var type = property.PropertyType;
object? value = null;
int? arraySize = null;
if (getValues || typeof(ICollection).IsAssignableFrom(type) || type.IsArray)
{
try
{
value = property.GetValue(this);
if (value is ICollection collection)
{
arraySize = collection.Count;
}
else if (value is Array array)
{
arraySize = array.Length;
}
}
catch (Exception ex)
{
Debug.WriteLine($"Error getting value for property {property.Name}: {ex.Message}");
// Continue to the next property if there's an error
continue;
}
}
// If getValues is false, we always return null for the Value
yield return (property.Name, getValues ? value : null, type, arraySize);
}
}
}
// Static helper methods to be able to object info without creating an object
public static string? GetDocumentationUrl<T>() where T : IClipboardFormat, new()
{
return new T().GetDocumentationUrl();
}
public static string? StructName<T>() where T : IClipboardFormat, new()
{
return new T().StructName();
}
public static Dictionary<string, string> GetVariableSizedItems<T>() where T : IClipboardFormat, new()
{
return new T().DataDisplayReplacements();
}
public static List<string> PropertiesNoProcess<T>() where T : IClipboardFormat, new()
{
return new T().PropertiesNoProcess();
}
public static bool FillEmptyArrayWithRemainingBytes<T>() where T : IClipboardFormat, new()
{
return new T().FillEmptyArrayWithRemainingBytes();
}
public static int MaxStringLength<T>() where T : IClipboardFormat, new()
{
return new T().MaxStringLength();
}
public class BITMAP_OBJ : ClipboardFormatBase
{
public LONG bmType { get; set; }
public LONG bmWidth { get; set; }
public LONG bmHeight { get; set; }
public LONG bmWidthBytes { get; set; }
public WORD bmPlanes { get; set; }
public WORD bmBitsPixel { get; set; }
public LPVOID bmBits { get; set; }
protected override string GetStructName() => "BITMAP";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "bmBits", "[Bitmap Data]" }
};
}
}
public class BITMAPV5HEADER_OBJ : ClipboardFormatBase
{
public DWORD bV5Size { get; set; }
public LONG bV5Width { get; set; }
public LONG bV5Height { get; set; }
public WORD bV5Planes { get; set; }
public WORD bV5BitCount { get; set; }
public bV5Compression bV5Compression { get; set; }
public DWORD bV5SizeImage { get; set; }
public LONG bV5XPelsPerMeter { get; set; }
public LONG bV5YPelsPerMeter { get; set; }
public DWORD bV5ClrUsed { get; set; }
public DWORD bV5ClrImportant { get; set; }
public DWORD bV5RedMask { get; set; }
public DWORD bV5GreenMask { get; set; }
public DWORD bV5BlueMask { get; set; }
public DWORD bV5AlphaMask { get; set; }
//public LOGCOLORSPACEW_OBJ bV5CSType { get; set; } = new LOGCOLORSPACEW_OBJ();
public LCSCSTYPE bV5CSType { get; set; }
public CIEXYZTRIPLE_OBJ bV5Endpoints { get; set; } = new CIEXYZTRIPLE_OBJ();
public DWORD bV5GammaRed { get; set; }
public DWORD bV5GammaGreen { get; set; }
public DWORD bV5GammaBlue { get; set; }
public LCSGAMUTMATCH bV5Intent { get; set; }
public DWORD bV5ProfileData { get; set; }
public DWORD bV5ProfileSize { get; set; }
public DWORD bV5Reserved { get; set; }
protected override string GetStructName() => "BITMAPV5HEADER";
}
public class BITMAPINFOHEADER_OBJ : ClipboardFormatBase
{
public DWORD biSize { get; set; }
public LONG biWidth { get; set; }
public LONG biHeight { get; set; }
public WORD biPlanes { get; set; }
public WORD biBitCount { get; set; }
public DWORD biCompression { get; set; }
public DWORD biSizeImage { get; set; }
public LONG biXPelsPerMeter { get; set; }
public LONG biYPelsPerMeter { get; set; }
public DWORD biClrUsed { get; set; }
public DWORD biClrImportant { get; set; }
protected override string GetStructName() => "BITMAPINFOHEADER";
}
public class RGBQUAD_OBJ : ClipboardFormatBase
{
public BYTE rgbBlue { get; set; }
public BYTE rgbGreen { get; set; }
public BYTE rgbRed { get; set; }
public BYTE rgbReserved { get; set; }
protected override string GetStructName() => "RGBQUAD";
}
public class BITMAPINFO_OBJ : ClipboardFormatBase
{
public BITMAPINFOHEADER_OBJ bmiHeader { get; set; } = new BITMAPINFOHEADER_OBJ();
public List<RGBQUAD_OBJ> bmiColors { get; set; } = [];
protected override string GetStructName() => "BITMAPINFO";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "bmiColors", "[Color data bytes]" }
};
}
public override List<string> PropertiesNoProcess()
{
return ["bmiColors"];
}
}
public class METAFILEPICT_OBJ : ClipboardFormatBase
{
public LONG mm { get; set; }
public LONG xExt { get; set; }
public LONG yExt { get; set; }
//public byte[] hMF { get; set; } = []; // Handle to metafile. Will process as METAFILE_OBJ later separately
public METAFILE_OBJ hMF { get; set; } = new METAFILE_OBJ();
protected override string GetStructName() => "METAFILEPICT";
//public override Dictionary<string, string> DataDisplayReplacements()
//{
// return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
// {
// { "hMF", "[Handle to metafile]" }
// };
//}
public override bool FillEmptyArrayWithRemainingBytes() => true;
}
public class CIEXYZ_OBJ : ClipboardFormatBase
{
public FXPT2DOT30 ciexyzX { get; set; }
public FXPT2DOT30 ciexyzY { get; set; }
public FXPT2DOT30 ciexyzZ { get; set; }
protected override string GetStructName() => "CIEXYZ";
public override Dictionary<string, string> DataDisplayReplacements()
{
// Using double for better precision
const double FixedToFloat = 1.0 / (1 << 30); // 1/2^30
// Convert each coordinate from fixed point (2.30) to floating point
double x = ciexyzX * FixedToFloat;
double y = ciexyzY * FixedToFloat;
double z = ciexyzZ * FixedToFloat;
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "ciexyzX", $"{x:F6}{Utils.AutoHexString(ciexyzX)}" }, // F6 for 6 decimal places
{ "ciexyzY", $"{y:F6}{Utils.AutoHexString(ciexyzY)}" },
{ "ciexyzZ", $"{z:F6}{Utils.AutoHexString(ciexyzZ)}" },
};
}
}
public class CIEXYZTRIPLE_OBJ : ClipboardFormatBase
{
public CIEXYZ_OBJ ciexyzRed { get; set; } = new CIEXYZ_OBJ();
public CIEXYZ_OBJ ciexyzGreen { get; set; } = new CIEXYZ_OBJ();
public CIEXYZ_OBJ ciexyzBlue { get; set; } = new CIEXYZ_OBJ();
protected override string GetStructName() => "CIEXYZTRIPLE";
}
public class DROPFILES_OBJ : ClipboardFormatBase
{
public DWORD pFiles { get; set; }
public POINT_OBJ pt { get; set; } = new POINT_OBJ();
public BOOL fNC { get; set; }
public BOOL fWide { get; set; }
// Method for total size
public int GetSize()
{
return Marshal.SizeOf(this);
}
protected override string GetStructName() => "DROPFILES";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "pt", "[Memory Handle]" }
};
}
}
public class POINT_OBJ : ClipboardFormatBase
{
public LONG x { get; set; }
public LONG y { get; set; }
protected override string GetStructName() => "POINT";
}
public class PALETTEENTRY_OBJ : ClipboardFormatBase
{
public BYTE peRed { get; set; }
public BYTE peGreen { get; set; }
public BYTE peBlue { get; set; }
public BYTE peFlags { get; set; }
protected override string GetStructName() => "PALETTEENTRY";
}
public class LOGPALETTE_OBJ : ClipboardFormatBase
{
private WORD _palVersion { get; set; }
private WORD _palNumEntries { get; set; }
//private List<PALETTEENTRY_OBJ> _palPalEntry { get; set; } = [];
private PALETTEENTRY_OBJ[] _palPalEntry { get; set; } = [];
public WORD palVersion
{
get => _palVersion;
set => _palVersion = value;
}
public WORD palNumEntries
{
get => _palNumEntries;
set
{
_palNumEntries = value;
//_palPalEntry = new List<PALETTEENTRY_OBJ>(_palNumEntries);
_palPalEntry = new PALETTEENTRY_OBJ[_palNumEntries];
}
}
//public List<PALETTEENTRY_OBJ> palPalEntry
public PALETTEENTRY_OBJ[] palPalEntry
{
get => _palPalEntry;
set => _palPalEntry = value;
}
protected override string GetStructName() => "LOGPALETTE";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "palPalEntry", "[Color Data Bytes]" }
};
}
}
public class LOGCOLORSPACEW_OBJ : ClipboardFormatBase
{
public DWORD lcsSignature { get; set; }
public DWORD lcsVersion { get; set; }
public DWORD lcsSize { get; set; }
public LCSCSTYPE lcsCSType { get; set; }
public LCSGAMUTMATCH lcsIntent { get; set; }
public CIEXYZTRIPLE_OBJ lcsEndpoints { get; set; } = new CIEXYZTRIPLE_OBJ();
public DWORD lcsGammaRed { get; set; }
public DWORD lcsGammaGreen { get; set; }
public DWORD lcsGammaBlue { get; set; }
public string lcsFilename { get; set; } = string.Empty;
protected override string GetStructName() => "LOGCOLORSPACEW";
public override int MaxStringLength() => MAX_PATH;
}
public class FILEGROUPDESCRIPTORW_OBJ : ClipboardFormatBase
{
public DWORD cItems { get; set; }
public List<FILEDESCRIPTOR_OBJ> fgd { get; set; } = [];
protected override string GetStructName() => "FILEGROUPDESCRIPTORW";
}
public class FILEDESCRIPTOR_OBJ : ClipboardFormatBase
{
public DWORD dwFlags { get; set; }
public CLSID_OBJ clsid { get; set; } = new CLSID_OBJ();
public SIZEL_OBJ sizel { get; set; } = new SIZEL_OBJ();
public POINTL_OBJ point { get; set; } = new POINTL_OBJ();
public DWORD dwFileAttributes { get; set; }
public FILETIME_OBJ ftCreationTime { get; set; } = new FILETIME_OBJ();
public FILETIME_OBJ ftLastAccessTime { get; set; } = new FILETIME_OBJ();
public FILETIME_OBJ ftLastWriteTime { get; set; } = new FILETIME_OBJ();
public DWORD nFileSizeHigh { get; set; }
public DWORD nFileSizeLow { get; set; }
public string cFileName { get; set; } = string.Empty;
public static int MetaDataOnlySize()
{
return 4 + 16 + 8 + 8 + 4 + 8 + 8 + 8 + 4 + 4;
}
public override int MaxStringLength() => MAX_PATH;
protected override string GetStructName() => "FILEDESCRIPTORW";
}
public class CLSID_OBJ : ClipboardFormatBase
{
public DWORD Data1 { get; set; }
public WORD Data2 { get; set; }
public WORD Data3 { get; set; }
public byte[] Data4 { get; set; } = new byte[8];
// Method for total size
public static int GetSize()
{
return 16;
}
public override Dictionary<string, string> DataDisplayReplacements()
{
string data4String = BitConverter.ToString(Data4).Replace("-", "");
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "Data1", Data1.ToString("X8") },
{ "Data2", Data2.ToString("X4") },
{ "Data3", Data3.ToString("X4") },
{ "Data4", data4String }
};
}
protected override string GetStructName() => "CLSID";
}
public class POINTL_OBJ : ClipboardFormatBase
{
public LONG x { get; set; }
public LONG y { get; set; }
protected override string GetStructName() => "POINTL";
}
public class SIZEL_OBJ : ClipboardFormatBase
{
public DWORD cx { get; set; }
public DWORD cy { get; set; }
protected override string GetStructName() => "SIZEL";
}
public class FILETIME_OBJ : ClipboardFormatBase
{
public DWORD dwLowDateTime { get; set; }
public DWORD dwHighDateTime { get; set; }
protected override string GetStructName() => "FILETIME";
}
public class CIDA_OBJ : ClipboardFormatBase
{
private uint _cidl;
private uint[] _aoffset = [];
private ITEMIDLIST_OBJ[] _ITEMIDLIST = [];
// Automatically updates the size of aoffset when cidl is set because it is dependent on it
public uint cidl
{
get => _cidl;
set
{
_cidl = value;
_aoffset = new uint[_cidl + 1];
_ITEMIDLIST = []; // Initialize to empty array since we are manually going to fill it later with separate processing
}
}
// Still allow setting aoffset directly so we can put values into it
public uint[] aoffset
{
get => _aoffset;
set => _aoffset = value;
}
public ITEMIDLIST_OBJ[] ITEMIDLIST
{
get => _ITEMIDLIST;
set => _ITEMIDLIST = value;
}
protected override string GetStructName() => "CIDA";
public override Dictionary<string, string> DataDisplayReplacements()
{
try
{
string aoffsetString = string.Join(", ", _aoffset.Select(x => x.ToString()));
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "aoffset", $"[{aoffsetString}]" },
};
}
catch
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "aoffset", $"[Data Not Available]" },
};
}
}
}
public class ITEMIDLIST_OBJ : ClipboardFormatBase
{
public SHITEMID_OBJ mkid { get; set; } = new SHITEMID_OBJ();
protected override string GetStructName() => "ITEMIDLIST";
}
public class SHITEMID_OBJ : ClipboardFormatBase
{
private USHORT _cb; // Size of the structure in bytes, including the cb field itself
private byte[] _abID = []; // The actual data
public uint cb
{
get => _cb;
set
{
_cb = (USHORT)value;
_abID = new byte[_cb - sizeof(USHORT)];
}
}
public byte[] abID
{
get => _abID;
set => _abID = value;
}
// Method to decode the abID into a string
public string abIDString()
{
string byteString = BitConverter.ToString(_abID).Replace("-", "");
return byteString;
}
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "abID", abIDString() }
};
}
protected override string GetStructName() => "SHITEMID";
}
public class METAFILE_OBJ : ClipboardFormatBase
{
public METAHEADER_OBJ METAHEADER { get; set; } = new METAHEADER_OBJ();
private METARECORD_OBJ[] _METARECORD { get; set; } = []; // Last record must be a META_EOF which is 0x0000
//private byte[] _rawRecordsData { get; set; } = new byte[0]; // Raw data of all records
public override bool FillEmptyArrayWithRemainingBytes() => false;
public METARECORD_OBJ[] METARECORD
{
get => _METARECORD;
set => _METARECORD = value;
}
protected override string GetStructName() => "MS-WMF";
}
public class METARECORD_OBJ : ClipboardFormatBase
{
public DWORD rdSize { get; set; }
public WMF_RecordType rdFunction { get; set; }
public WORD[] rdParm { get; set; } = [];
// ----------------------------------------------------------
public METARECORD_OBJ(UInt32 rdSizeInput, byte[] rawBytes)
{
rdSize = rdSizeInput;
rdFunction = GetFunctionValue(rawBytes);
rdParm = new WORD[rdSizeInput - sizeof(DWORD) - sizeof(WORD)]; // Assign the remaining bytes to rdParm
}
// ----------------------------------------------------------
private WMF_RecordType GetFunctionValue(byte[] rawBytes)
{
// Get the two bytes that are after the first DWORD
byte[] functionBytes = new byte[2];
Array.Copy(rawBytes, 4, functionBytes, 0, 2);
WORD function = BitConverter.ToUInt16(functionBytes, 0);
return (WMF_RecordType)function;
}
protected override string GetStructName() => "METARECORD";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "rdParm", $"[Parameter Data]" }
};
}
}
public class METAHEADER_OBJ : ClipboardFormatBase
{
public MetaFileType mtType { get; set; }
public WORD mtHeaderSize { get; set; }
public WORD mtVersion { get; set; }
public DWORD mtSize { get; set; }
public WORD mtNoObjects { get; set; }
public DWORD mtMaxRecord { get; set; }
public WORD mtNoParameters { get; set; }
protected override string GetStructName() => "METAHEADER";
}
public class ENHMETAFILE_OBJ : ClipboardFormatBase
{
public ENHMETAHEADER_OBJ ENHMETAHEADER { get; set; } = new ENHMETAHEADER_OBJ();
public ENHMETARECORD_OBJ[] ENHMETARECORD { get; set; } = [];
// Last record must be a EMR_EOF which is 0x0000
protected override string GetStructName() => "MS-EMF";
public override bool FillEmptyArrayWithRemainingBytes() => false;
//public override Dictionary<string, string> DataDisplayReplacements()
//{
// return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
// {
// { "ENHMETARECORD", "[Enhanced Metafile Record Data]" }
// };
//}
}
public class ENHMETAHEADER_OBJ : ClipboardFormatBase
{
public EMF_RecordType iType { get; set; } // Aka RecordType, 4 bytes DWORD
public DWORD nSize { get; set; }
public RECTL_OBJ rclBounds { get; set; } = new RECTL_OBJ(); // 16 Bytes
public RECTL_OBJ rclFrame { get; set; } = new RECTL_OBJ();
public DWORD dSignature { get; set; }
public DWORD nVersion { get; set; }
public DWORD nBytes { get; set; }
public DWORD nRecords { get; set; }
public WORD nHandles { get; set; }
public WORD sReserved { get; set; }
public DWORD nDescription { get; set; }
public DWORD offDescription { get; set; }
public DWORD nPalEntries { get; set; }
public SIZEL_OBJ szlDevice { get; set; } = new SIZEL_OBJ();
public SIZEL_OBJ szlMillimeters { get; set; } = new SIZEL_OBJ();
public DWORD cbPixelFormat { get; set; }
public DWORD offPixelFormat { get; set; }
public DWORD bOpenGL { get; set; }
public SIZEL_OBJ szlMicrometers { get; set; } = new SIZEL_OBJ();
protected override string GetStructName() => "ENHMETAHEADER";
}
public class ENHMETARECORD_OBJ : ClipboardFormatBase
{
public EMF_RecordType iType { get; set; } // DWORD
public DWORD nSize { get; set; }
public DWORD[] dParm { get; set; } = [];
// ----------------------------------------------------------
public ENHMETARECORD_OBJ(UInt32 nSizeInput, byte[] rawBytes)
{
iType = GetFunctionValue(rawBytes);
//nSize = GetnSize(rawBytes);
nSize = nSizeInput;
dParm = new DWORD[nSizeInput - (sizeof(DWORD) * 2)];
}
// ----------------------------------------------------------
private EMF_RecordType GetFunctionValue(byte[] rawBytes)
{
// Get the first DWORD
byte[] functionBytes = new byte[sizeof(DWORD)];
Array.Copy(sourceArray: rawBytes, sourceIndex: 0, destinationArray: functionBytes, destinationIndex: 0, length: sizeof(DWORD));
DWORD function = BitConverter.ToUInt32(functionBytes, 0);
return (EMF_RecordType)function;
}
private DWORD GetnSize(byte[] rawBytes)
{
// Get the DWORD after the first DWORD
byte[] sizeCountBytes = new byte[sizeof(DWORD)];
Array.Copy(sourceArray: rawBytes, sourceIndex: sizeof(DWORD), destinationArray: sizeCountBytes, destinationIndex: 0, length: sizeof(DWORD));
DWORD size = BitConverter.ToUInt32(sizeCountBytes, 0);
return size;
}
protected override string GetStructName() => "ENHMETARECORD";
public override Dictionary<string, string> DataDisplayReplacements()
{
return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "dParm", $"[Parameter Data]" }
};
}
}
public class RECTL_OBJ : ClipboardFormatBase // 16 bytes
{
public LONG left { get; set; }
public LONG top { get; set; }
public LONG right { get; set; }
public LONG bottom { get; set; }
protected override string GetStructName() => "RECTL";
}
public class META_PLACEABLE_OBJ : ClipboardFormatBase
{
public UINT32 Key { get; set; }
public INT16 Hmf { get; set; } // Handle to metafile
public PWMFRect16_OBJ BoundingBox { get; set; } = new PWMFRect16_OBJ();
public INT16 Inch { get; set; }
public UINT32 Reserved { get; set; }
public INT16 Checksum { get; set; }
protected override string GetStructName() => "META_PLACEABLE";
}
public class PWMFRect16_OBJ : ClipboardFormatBase
{
public INT16 Left { get; set; }
public INT16 Top { get; set; }
public INT16 Right { get; set; }
public INT16 Bottom { get; set; }
protected override string GetStructName() => "PWMFRect16";
}
public class DataObjectAttributes_Obj : ClipboardFormatBase
{
public SFGAO dwRequested { get; set; } // Bitmask of attributes that were requested
public SFGAO dwReceived { get; set; } // Bitmask of actual attributes received from GetAttributesOf
public UINT cItems { get; set; } // Count of items in the data object
protected override string GetStructName() => "DataObjectAttributes";
}
public class FORMATETC_OBJ : ClipboardFormatBase
{
public CLIPFORMAT cfFormat { get; set; }
// DVTARGETDEVICE is a handle, so we will process it separately.
// Will use marshal to get the true struct with the pointer then put it into this object
//public DVTARGETDEVICE_OBJ ptd { get; set; } = new DVTARGETDEVICE_OBJ();
public LPVOID ptd { get; set; }
//public DVTARGETDEVICE_OBJ? DVTARGETDEVICE { get; set; } = null;
public DWORD dwAspect { get; set; }
public LONG lindex { get; set; }
public TYMED tymed { get; set; }
protected override string GetStructName() => "FORMATETC";
public FORMATETC_OBJ() { }
public override List<string> PropertiesNoProcess()
{
return ["DVTARGETDEVICE"]; // We'll manually process this based on the pointer
}
}
public class DVTARGETDEVICE_OBJ : ClipboardFormatBase
{
public DWORD tdSize { get; set; }
public WORD tdDriverNameOffset { get; set; }
public WORD tdDeviceNameOffset { get; set; }
public WORD tdPortNameOffset { get; set; }
public WORD tdExtDevmodeOffset { get; set; }
public BYTE[] tdData { get; set; } = [];
protected override string GetStructName() => "DVTARGETDEVICE";
public override bool FillEmptyArrayWithRemainingBytes() => true;
}
public class DROPDESCRIPTION_OBJ : ClipboardFormatBase
{
public DROPIMAGETYPE type { get; set; }
public string szMessage { get; set; } = string.Empty;
public string szInsert { get; set; } = string.Empty;
protected override string GetStructName() => "DROPDESCRIPTION";
public override int MaxStringLength() => MAX_PATH;
}
public class OBJECTDESCRIPTOR_OBJ : ClipboardFormatBase
{
public ULONG cbSize { get; set; }
public CLSID_OBJ clsid { get; set; } = new CLSID_OBJ();
public DVASPECT dwDrawAspect { get; set; }
public SIZEL_OBJ sizel { get; set; } = new SIZEL_OBJ();
public POINTL_OBJ pointl { get; set; } = new POINTL_OBJ();
public OLEMISC dwStatus { get; set; }
public DWORD dwFullUserTypeName { get; set; }
public DWORD dwSrcOfCopy { get; set; }
protected override string GetStructName() => "OBJECTDESCRIPTOR";
}
public class OLE_PRIVATE_DATA_OBJ : ClipboardFormatBase
{
public DWORD unknown1 { get; set; }
public DWORD size { get; set; } // total structure size in bytes
public DWORD unknown2 { get; set; }
public DWORD count { get; set; } // number of format entries
public DWORD unknown3 { get; set; }
public DWORD unknown4 { get; set; }
public OLE_ENTRY_OBJ[] entries { get; set; } = []; // array of format entries
// Then follows any DVTARGETDEVICE structures referenced in the FORMATETCs
// Generic constructor that takes in number of entries
public OLE_PRIVATE_DATA_OBJ(uint entryCount)
{
entries = new OLE_ENTRY_OBJ[entryCount];
}
// Need a parameterless constructor for serialization
public OLE_PRIVATE_DATA_OBJ() { }
}
public class OLE_ENTRY_OBJ : ClipboardFormatBase
{
public FORMATETC_OBJ fmtetc { get; set; } = new FORMATETC_OBJ();
public DWORD first_use { get; set; } // Has this cf been added to the list already
public DWORD unknown1 { get; set; }
public DWORD unknown2 { get; set; }
// Need a parameterless constructor for serialization
public OLE_ENTRY_OBJ() { }
}
// --------------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------- Enum Definitions -----------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------------
[Flags]
[EnumName("TYMED")]
public enum TYMED : DWORD
{
TYMED_HGLOBAL = 1,
TYMED_FILE = 2,
TYMED_ISTREAM = 4,
TYMED_ISTORAGE = 8,
TYMED_GDI = 16,
TYMED_MFPICT = 32,
TYMED_ENHMF = 64,
TYMED_NULL = 0
}
[EnumName("DVASPECT")]
public enum DVASPECT : DWORD
{
DVASPECT_CONTENT = 1,
DVASPECT_THUMBNAIL = 2,
DVASPECT_ICON = 4,
DVASPECT_DOCPRINT = 8
}
[Flags]
[EnumName("OLEMISC")]
public enum OLEMISC : DWORD
{
OLEMISC_RECOMPOSEONRESIZE = 0x1,
OLEMISC_ONLYICONIC = 0x2,
OLEMISC_INSERTNOTREPLACE = 0x4,
OLEMISC_STATIC = 0x8,
OLEMISC_CANTLINKINSIDE = 0x10,
OLEMISC_CANLINKBYOLE1 = 0x20,
OLEMISC_ISLINKOBJECT = 0x40,
OLEMISC_INSIDEOUT = 0x80,
OLEMISC_ACTIVATEWHENVISIBLE = 0x100,
OLEMISC_RENDERINGISDEVICEINDEPENDENT = 0x200,
OLEMISC_INVISIBLEATRUNTIME = 0x400,
OLEMISC_ALWAYSRUN = 0x800,
OLEMISC_ACTSLIKEBUTTON = 0x1000,
OLEMISC_ACTSLIKELABEL = 0x2000,
OLEMISC_NOUIACTIVATE = 0x4000,
OLEMISC_ALIGNABLE = 0x8000,
OLEMISC_SIMPLEFRAME = 0x10000,
OLEMISC_SETCLIENTSITEFIRST = 0x20000,
OLEMISC_IMEMODE = 0x40000,
OLEMISC_IGNOREACTIVATEWHENVISIBLE = 0x80000,
OLEMISC_WANTSTOMENUMERGE = 0x100000,
OLEMISC_SUPPORTSMULTILEVELUNDO = 0x200000
}
[EnumName("LogicalColorSpace")]
public enum LCSCSTYPE : uint // DWORD
{
// Can be one of the following values
LCS_CALIBRATED_RGB = 0x00000000,
LCS_sRGB = 0x73524742,
LCS_WINDOWS_COLOR_SPACE = 0x57696E20,
PROFILE_LINKED = 0x4C494E4B,
PROFILE_EMBEDDED = 0x4D424544
}
[EnumName("GamutMappingIntent")]
public enum LCSGAMUTMATCH : uint // DWORD
{
// Can be one of the following values
LCS_GM_ABS_COLORIMETRIC = 0x00000008,