├── .gitignore ├── docs └── resfmt.txt ├── dotNET PE.sln ├── license.txt ├── readme.md ├── src ├── CommonAssemblyInfo.cs ├── Workshell.PE.Resources │ ├── Accelerators │ │ ├── AcceleratorEntry.cs │ │ ├── AcceleratorKeys.cs │ │ ├── AcceleratorsResource.cs │ │ └── AcceleratorsTable.cs │ ├── CharacterSet.cs │ ├── Dialogs │ │ ├── Dialog.cs │ │ ├── DialogBase.cs │ │ ├── DialogEx.cs │ │ ├── DialogItemEx.cs │ │ ├── DialogResource.cs │ │ └── Styles │ │ │ ├── ButtonStyle.cs │ │ │ ├── ComboBoxStyle.cs │ │ │ ├── DialogStyle.cs │ │ │ ├── EditStyle.cs │ │ │ ├── ListBoxStyle.cs │ │ │ ├── ScrollBarStyle.cs │ │ │ ├── StaticStyle.cs │ │ │ ├── WindowStyle.cs │ │ │ └── WindowStyleEx.cs │ ├── Graphics │ │ ├── BitmapResource.cs │ │ ├── CursorData.cs │ │ ├── CursorGroup.cs │ │ ├── CursorGroupEntry.cs │ │ ├── CursorGroupResource.cs │ │ ├── CursorInfo.cs │ │ ├── CursorResource.cs │ │ ├── GraphicResources.cs │ │ ├── GraphicUtils.cs │ │ ├── IconData.cs │ │ ├── IconGroup.cs │ │ ├── IconGroupEntry.cs │ │ ├── IconGroupResource.cs │ │ ├── IconInfo.cs │ │ └── IconResource.cs │ ├── Menus │ │ ├── Menu.cs │ │ ├── MenuItem.cs │ │ ├── MenuItemFlags.cs │ │ ├── MenuResource.cs │ │ └── PopupMenuItem.cs │ ├── Messages │ │ ├── MessageTable.cs │ │ ├── MessageTableBlock.cs │ │ ├── MessageTableEntry.cs │ │ └── MessageTableResource.cs │ ├── Native │ │ ├── ACCELTABLEENTRY.cs │ │ ├── BITMAPFILEHEADER.cs │ │ ├── BITMAPINFOHEADER.cs │ │ ├── CURSORDIR.cs │ │ ├── CURSOR_RESDIR.cs │ │ ├── ICONDIR.cs │ │ ├── ICON_RESDIR.cs │ │ ├── MESSAGETABLE.cs │ │ ├── NEWHEADER.cs │ │ └── VS_FIXEDFILEINFO.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── ResourceUtils.cs │ ├── Strings │ │ ├── StringTable.cs │ │ ├── StringTableEntry.cs │ │ └── StringTableResource.cs │ ├── Version │ │ ├── FileInfo.cs │ │ ├── FixedFileInfo.cs │ │ ├── StringFileInfo.cs │ │ ├── VarFileInfo.cs │ │ ├── VersionInfo.cs │ │ ├── VersionResource.cs │ │ ├── VersionString.cs │ │ ├── VersionStringTable.cs │ │ └── VersionVariable.cs │ └── Workshell.PE.Resources.csproj └── Workshell.PE │ ├── Annotations │ ├── EnumAnnotationAttribute.cs │ ├── EnumAnnotations.cs │ ├── FieldAnnotationAttribute.cs │ └── FieldAnnotations.cs │ ├── Content │ ├── CLR │ │ ├── CLR.cs │ │ ├── CLRDataDirectory.cs │ │ ├── CLRHeader.cs │ │ ├── CLRMetaData.cs │ │ ├── CLRMetaDataHeader.cs │ │ ├── CLRMetaDataStream.cs │ │ ├── CLRMetaDataStreamTable.cs │ │ ├── CLRMetaDataStreamTableEntry.cs │ │ └── CLRMetaDataStreams.cs │ ├── Certificate.cs │ ├── DataContent.cs │ ├── Debug │ │ ├── DebugData.cs │ │ ├── DebugDirectory.cs │ │ └── DebugDirectoryEntry.cs │ ├── Exceptions │ │ ├── ExceptionChainedUnwindInfo.cs │ │ ├── ExceptionTable.cs │ │ ├── ExceptionTable32.cs │ │ ├── ExceptionTable64.cs │ │ ├── ExceptionTableEntry.cs │ │ ├── ExceptionTableEntry32.cs │ │ ├── ExceptionTableEntry64.cs │ │ ├── ExceptionUnwindInfo.cs │ │ └── ExceptionUnwindInfoCode.cs │ ├── Exports │ │ ├── Export.cs │ │ ├── ExportDirectory.cs │ │ ├── ExportTable.cs │ │ └── Exports.cs │ ├── Imports │ │ ├── DelayedImportAddressTable.cs │ │ ├── DelayedImportAddressTableEntry.cs │ │ ├── DelayedImportAddressTables.cs │ │ ├── DelayedImportDirectory.cs │ │ ├── DelayedImportDirectoryEntry.cs │ │ ├── DelayedImportHintNameEntry.cs │ │ ├── DelayedImportHintNameTable.cs │ │ ├── DelayedImportLibrary.cs │ │ ├── DelayedImports.cs │ │ ├── ImportAddressTable.cs │ │ ├── ImportAddressTableBase.cs │ │ ├── ImportAddressTableEntry.cs │ │ ├── ImportAddressTableEntryBase.cs │ │ ├── ImportAddressTables.cs │ │ ├── ImportAddressTablesBase.cs │ │ ├── ImportDirectory.cs │ │ ├── ImportDirectoryBase.cs │ │ ├── ImportDirectoryEntry.cs │ │ ├── ImportDirectoryEntryBase.cs │ │ ├── ImportHintNameEntry.cs │ │ ├── ImportHintNameEntryBase.cs │ │ ├── ImportHintNameTable.cs │ │ ├── ImportHintNameTableBase.cs │ │ ├── ImportLibrary.cs │ │ ├── ImportLibraryBase.cs │ │ ├── ImportLibraryFunction.cs │ │ ├── Imports.cs │ │ └── ImportsBase.cs │ ├── LoadConfigurationCodeIntegrity.cs │ ├── LoadConfigurationDirectory.cs │ ├── Relocation │ │ ├── Relocation.cs │ │ ├── RelocationBlock.cs │ │ └── RelocationTable.cs │ ├── Resources │ │ ├── Resource.cs │ │ ├── ResourceCollection.cs │ │ ├── ResourceData.cs │ │ ├── ResourceDataEntry.cs │ │ ├── ResourceDirectory.cs │ │ ├── ResourceDirectoryEntry.cs │ │ ├── ResourceId.cs │ │ ├── ResourceLanguage.cs │ │ ├── ResourceLanguages.cs │ │ └── ResourceType.cs │ └── TLSDirectory.cs │ ├── DOSHeader.cs │ ├── DOSStub.cs │ ├── DataDirectories.cs │ ├── DataDirectory.cs │ ├── Extensions │ ├── Conversion.cs │ └── Stream.cs │ ├── FileHeader.cs │ ├── Location.cs │ ├── LocationCalculator.cs │ ├── NTHeaders.cs │ ├── Native │ ├── IMAGE_BASE_RELOCATION.cs │ ├── IMAGE_COR20_HEADER.cs │ ├── IMAGE_DATA_DIRECTORY.cs │ ├── IMAGE_DEBUG_DIRECTORY.cs │ ├── IMAGE_DELAY_IMPORT_DESCRIPTOR.cs │ ├── IMAGE_DOS_HEADER.cs │ ├── IMAGE_EXPORT_DIRECTORY.cs │ ├── IMAGE_FILE_HEADER.cs │ ├── IMAGE_IMPORT_DESCRIPTOR.cs │ ├── IMAGE_LOAD_CONFIG_DIRECTORY.cs │ ├── IMAGE_OPTIONAL_HEADER.cs │ ├── IMAGE_RESOURCE_DATA_ENTRY.cs │ ├── IMAGE_RESOURCE_DIRECTORY.cs │ ├── IMAGE_RESOURCE_DIRECTORY_ENTRY.cs │ ├── IMAGE_RUNTIME_FUNCTION.cs │ ├── IMAGE_SECTION_HEADER.cs │ ├── IMAGE_TLS_DIRECTORY.cs │ └── WIN_CERTIFICATE.cs │ ├── OptionalHeader.cs │ ├── PortableExecutableImage.cs │ ├── PortableExecutableImageException.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Section.cs │ ├── SectionTable.cs │ ├── Supports.cs │ ├── Utils.cs │ └── Workshell.PE.csproj ├── tests └── Workshell.PE.Tests │ ├── DOSHeaderTests.cs │ ├── DataDirectoryTests.cs │ ├── FileHeaderTests.cs │ ├── Files │ ├── clrtest.any.dll │ ├── clrtest.x64.dll │ ├── clrtest.x86.dll │ ├── license.txt │ ├── nativetest.x64.dll │ └── nativetest.x86.dll │ ├── GeneralTests.cs │ ├── LocationCalculatorTests.cs │ ├── NTHeadersTests.cs │ ├── OptionalHeaderTests.cs │ ├── SectionTableTests.cs │ ├── SectionTests.cs │ ├── TestingUtils.cs │ ├── UtilsTests.cs │ └── Workshell.PE.Tests.csproj └── version.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | .vs/ 3 | [Bb]in/ 4 | [Oo]bj/ 5 | [Pp]ackages/ 6 | [Tt]ools/ 7 | 8 | # mstest test results 9 | TestResults 10 | 11 | ## Ignore Visual Studio temporary files, build results, and 12 | ## files generated by popular Visual Studio add-ons. 13 | 14 | # User-specific files 15 | *.suo 16 | *.user 17 | *.sln.docstates 18 | *.snk 19 | 20 | # Build results 21 | [Dd]ebug/ 22 | [Rr]elease/ 23 | x64/ 24 | *_i.c 25 | *_p.c 26 | *.ilk 27 | *.meta 28 | *.obj 29 | *.pch 30 | *.pdb 31 | *.pgc 32 | *.pgd 33 | *.rsp 34 | *.sbr 35 | *.tlb 36 | *.tli 37 | *.tlh 38 | *.tmp 39 | *.log 40 | *.vspscc 41 | *.vssscc 42 | .builds 43 | *.nupkg 44 | 45 | # Visual C++ cache files 46 | ipch/ 47 | *.aps 48 | *.ncb 49 | *.opensdf 50 | *.sdf 51 | 52 | # Visual Studio profiler 53 | *.psess 54 | *.vsp 55 | *.vspx 56 | 57 | # Guidance Automation Toolkit 58 | *.gpState 59 | 60 | # ReSharper is a .NET coding add-in 61 | _ReSharper* 62 | 63 | # NCrunch 64 | *.ncrunch* 65 | .*crunch*.local.xml 66 | 67 | # Installshield output folder 68 | [Ee]xpress 69 | 70 | # DocProject is a documentation generator add-in 71 | DocProject/buildhelp/ 72 | DocProject/Help/*.HxT 73 | DocProject/Help/*.HxC 74 | DocProject/Help/*.hhc 75 | DocProject/Help/*.hhk 76 | DocProject/Help/*.hhp 77 | DocProject/Help/Html2 78 | DocProject/Help/html 79 | 80 | # Click-Once directory 81 | publish 82 | 83 | # Publish Web Output 84 | *.Publish.xml 85 | 86 | # NuGet Packages Directory 87 | packages 88 | 89 | # Windows Azure Build Output 90 | csx 91 | *.build.csdef 92 | 93 | # Windows Store app package directory 94 | AppPackages/ 95 | 96 | # Others 97 | [Bb]in 98 | [Oo]bj 99 | sql 100 | TestResults 101 | [Tt]est[Rr]esult* 102 | *.Cache 103 | ClientBin 104 | [Ss]tyle[Cc]op.* 105 | ~$* 106 | *.dbmdl 107 | Generated_Code #added for RIA/Silverlight projects 108 | 109 | # Backup & report files from converting an old project file to a newer 110 | # Visual Studio version. Backup files are not needed, because we have git ;-) 111 | _UpgradeReport_Files/ 112 | Backup*/ 113 | UpgradeLog*.XML -------------------------------------------------------------------------------- /dotNET PE.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29503.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE", "src\Workshell.PE\Workshell.PE.csproj", "{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE.Resources", "src\Workshell.PE.Resources\Workshell.PE.Resources.csproj", "{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{85C1A49C-0316-4C2D-B2E3-17B1F8200EE7}" 11 | ProjectSection(SolutionItems) = preProject 12 | src\CommonAssemblyInfo.cs = src\CommonAssemblyInfo.cs 13 | readme.md = readme.md 14 | version.txt = version.txt 15 | EndProjectSection 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE.Tests", "tests\Workshell.PE.Tests\Workshell.PE.Tests.csproj", "{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | CI|Any CPU = CI|Any CPU 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.CI|Any CPU.ActiveCfg = CI|Any CPU 27 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.CI|Any CPU.Build.0 = CI|Any CPU 28 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.CI|Any CPU.ActiveCfg = CI|Any CPU 33 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.CI|Any CPU.Build.0 = CI|Any CPU 34 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.CI|Any CPU.ActiveCfg = CI|Any CPU 39 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.CI|Any CPU.Build.0 = CI|Any CPU 40 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Release|Any CPU.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {D281E078-262D-4616-9157-CE1C42C0026C} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Workshell Ltd 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /src/CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/src/CommonAssemblyInfo.cs -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Accelerators/AcceleratorEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using Workshell.PE.Annotations; 27 | 28 | namespace Workshell.PE.Resources.Accelerators 29 | { 30 | [Flags] 31 | public enum AcceleratorFlags : ushort 32 | { 33 | [EnumAnnotation("FVIRTKEY")] 34 | VirtualKey = 0x0001, 35 | [EnumAnnotation("FNOINVERT")] 36 | NoInvert = 0x0002, 37 | [EnumAnnotation("FSHIFT")] 38 | Shift = 0x0004, 39 | [EnumAnnotation("FCONTROL")] 40 | Control = 0x0008, 41 | [EnumAnnotation("FALT")] 42 | Alt = 0x0010, 43 | End = 0x0080 44 | } 45 | 46 | public sealed class AcceleratorEntry 47 | { 48 | internal AcceleratorEntry(ushort flags, ushort key, ushort id) 49 | { 50 | Flags = flags; 51 | Key = key; 52 | Id = id; 53 | } 54 | 55 | #region Methods 56 | 57 | public override string ToString() 58 | { 59 | return $"Id: {Id}; Key: {GetKey()}; Flags: {GetFlags()}"; 60 | } 61 | 62 | public AcceleratorFlags GetFlags() 63 | { 64 | return (AcceleratorFlags)Flags; 65 | } 66 | 67 | public AcceleratorKeys GetKey() 68 | { 69 | return (AcceleratorKeys)Key; 70 | } 71 | 72 | #endregion 73 | 74 | #region Properties 75 | 76 | public ushort Flags { get; } 77 | public ushort Key { get; } 78 | public ushort Id {get;} 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Accelerators/AcceleratorsTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Accelerators 29 | { 30 | public sealed class AcceleratorsTable : IEnumerable 31 | { 32 | private readonly AcceleratorEntry[] _entries; 33 | 34 | internal AcceleratorsTable(AcceleratorsResource resource, uint language, AcceleratorEntry[] entries) 35 | { 36 | _entries = entries; 37 | 38 | Resource = resource; 39 | Language = language; 40 | Count = entries.Length; 41 | } 42 | 43 | #region Methods 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | foreach(var entry in _entries) 48 | yield return entry; 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | #endregion 57 | 58 | #region Properties 59 | 60 | public AcceleratorsResource Resource { get; } 61 | public ResourceLanguage Language { get; } 62 | public int Count { get; } 63 | public AcceleratorEntry this[int index] => _entries[index]; 64 | 65 | #endregion 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/CharacterSet.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | using Workshell.PE.Annotations; 28 | 29 | namespace Workshell.PE.Resources 30 | { 31 | public enum CharacterSet : byte 32 | { 33 | [EnumAnnotation("ANSI_CHARSET")] 34 | ANSI = 0, 35 | [EnumAnnotation("DEFAULT_CHARSET")] 36 | Default = 0x01, 37 | [EnumAnnotation("SYMBOL_CHARSET")] 38 | Symbol = 0x02, 39 | [EnumAnnotation("MAC_CHARSET")] 40 | Mac = 0x4D, 41 | [EnumAnnotation("SHIFTJIS_CHARSET")] 42 | ShiftJis = 0x80, 43 | [EnumAnnotation("HANGUL_CHARSET")] 44 | Hangul = 0x81, 45 | [EnumAnnotation("JOHAB_CHARSET")] 46 | Johab = 0x82, 47 | [EnumAnnotation("GB2312_CHARSET")] 48 | GB2312 = 0x86, 49 | [EnumAnnotation("CHINESEBIG5_CHARSET")] 50 | ChineseBig5 = 0x88, 51 | [EnumAnnotation("GREEK_CHARSET")] 52 | Greek = 0xA1, 53 | [EnumAnnotation("TURKISH_CHARSET")] 54 | Turkish = 0xA2, 55 | [EnumAnnotation("VIETNAMESE_CHARSET")] 56 | Vietnamese = 0xA3, 57 | [EnumAnnotation("HEBREW_CHARSET")] 58 | Hebrew = 0xB1, 59 | [EnumAnnotation("ARABIC_CHARSET")] 60 | Arabic = 0xB2, 61 | [EnumAnnotation("BALTIC_CHARSET")] 62 | Baltic = 0xBA, 63 | [EnumAnnotation("RUSSIAN_CHARSET")] 64 | Russian = 0xCC, 65 | [EnumAnnotation("THAI_CHARSET")] 66 | Thai = 0xDE, 67 | [EnumAnnotation("EASTEUROPE_CHARSET")] 68 | EastEurope = 0xEE, 69 | [EnumAnnotation("OEM_CHARSET")] 70 | OEM = 0xFF 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Dialog.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs 28 | { 29 | public sealed class Dialog : DialogBase 30 | { 31 | internal Dialog(DialogResource resource, uint language) : base(resource, language, false) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/DialogBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs 28 | { 29 | public abstract class DialogBase 30 | { 31 | protected internal DialogBase(DialogResource resource, uint language, bool isExtended) 32 | { 33 | Resource = resource; 34 | Language = language; 35 | IsExtended = isExtended; 36 | } 37 | 38 | #region Properties 39 | 40 | public DialogResource Resource { get; } 41 | public ResourceLanguage Language { get; } 42 | public bool IsExtended { get; } 43 | 44 | #endregion 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/ButtonStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum ButtonStyle : uint 31 | { 32 | BS_PUSHBUTTON = 0x00000000, 33 | BS_DEFPUSHBUTTON = 0x00000001, 34 | BS_CHECKBOX = 0x00000002, 35 | BS_AUTOCHECKBOX = 0x00000003, 36 | BS_RADIOBUTTON = 0x00000004, 37 | BS_3STATE = 0x00000005, 38 | BS_AUTO3STATE = 0x00000006, 39 | BS_GROUPBOX = 0x00000007, 40 | BS_USERBUTTON = 0x00000008, 41 | BS_AUTORADIOBUTTON = 0x00000009, 42 | BS_PUSHBOX = 0x0000000A, 43 | BS_OWNERDRAW = 0x0000000B, 44 | BS_TYPEMASK = 0x0000000F, 45 | BS_LEFTTEXT = 0x00000020, 46 | BS_TEXT = 0x00000000, 47 | BS_ICON = 0x00000040, 48 | BS_BITMAP = 0x00000080, 49 | BS_LEFT = 0x00000100, 50 | BS_RIGHT = 0x00000200, 51 | BS_CENTER = 0x00000300, 52 | BS_TOP = 0x00000400, 53 | BS_BOTTOM = 0x00000800, 54 | BS_VCENTER = 0x00000C00, 55 | BS_PUSHLIKE = 0x00001000, 56 | BS_MULTILINE = 0x00002000, 57 | BS_NOTIFY = 0x00004000, 58 | BS_FLAT = 0x00008000, 59 | BS_RIGHTBUTTON = BS_LEFTTEXT 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/ComboBoxStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum ComboBoxStyle : uint 31 | { 32 | CBS_SIMPLE = 0x0001, 33 | CBS_DROPDOWN = 0x0002, 34 | CBS_DROPDOWNLIST = 0x0003, 35 | CBS_OWNERDRAWFIXED = 0x0010, 36 | CBS_OWNERDRAWVARIABLE = 0x0020, 37 | CBS_AUTOHSCROLL = 0x0040, 38 | CBS_OEMCONVERT = 0x0080, 39 | CBS_SORT = 0x0100, 40 | CBS_HASSTRINGS = 0x0200, 41 | CBS_NOINTEGRALHEIGHT = 0x0400, 42 | CBS_DISABLENOSCROLL = 0x0800, 43 | CBS_UPPERCASE = 0x2000, 44 | CBS_LOWERCASE = 0x4000, 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/DialogStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum DialogStyle : uint 31 | { 32 | DS_ABSALIGN = 0x01, 33 | DS_SYSMODAL = 0x02, 34 | DS_LOCALEDIT = 0x20, 35 | DS_SETFONT = 0x40, 36 | DS_MODALFRAME = 0x80, 37 | DS_NOIDLEMSG = 0x100, 38 | DS_SETFOREGROUND = 0x200, 39 | 40 | DS_3DLOOK = 0x0004, 41 | DS_FIXEDSYS = 0x0008, 42 | DS_NOFAILCREATE = 0x0010, 43 | DS_CONTROL = 0x0400, 44 | DS_CENTER = 0x0800, 45 | DS_CENTERMOUSE = 0x1000, 46 | DS_CONTEXTHELP = 0x2000, 47 | 48 | DS_SHELLFONT = (DS_SETFONT | DS_FIXEDSYS), 49 | DS_USEPIXELS = 0x8000 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/EditStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum EditStyle : uint 31 | { 32 | ES_LEFT = 0x0000, 33 | ES_CENTER = 0x0001, 34 | ES_RIGHT = 0x0002, 35 | ES_MULTILINE = 0x0004, 36 | ES_UPPERCASE = 0x0008, 37 | ES_LOWERCASE = 0x0010, 38 | ES_PASSWORD = 0x0020, 39 | ES_AUTOVSCROLL = 0x0040, 40 | ES_AUTOHSCROLL = 0x0080, 41 | ES_NOHIDESEL = 0x0100, 42 | ES_OEMCONVERT = 0x0400, 43 | ES_READONLY = 0x0800, 44 | ES_WANTRETURN = 0x1000, 45 | ES_NUMBER = 0x2000, 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/ListBoxStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum ListBoxStyle : uint 31 | { 32 | LBS_NOTIFY = 0x0001, 33 | LBS_SORT = 0x0002, 34 | LBS_NOREDRAW = 0x0004, 35 | LBS_MULTIPLESEL = 0x0008, 36 | LBS_OWNERDRAWFIXED = 0x0010, 37 | LBS_OWNERDRAWVARIABLE = 0x0020, 38 | LBS_HASSTRINGS = 0x0040, 39 | LBS_USETABSTOPS = 0x0080, 40 | LBS_NOINTEGRALHEIGHT = 0x0100, 41 | LBS_MULTICOLUMN = 0x0200, 42 | LBS_WANTKEYBOARDINPUT = 0x0400, 43 | LBS_EXTENDEDSEL = 0x0800, 44 | LBS_DISABLENOSCROLL = 0x1000, 45 | LBS_NODATA = 0x2000, 46 | LBS_NOSEL = 0x4000, 47 | LBS_COMBOBOX = 0x8000, 48 | LBS_STANDARD = (LBS_NOTIFY | LBS_SORT | WindowStyle.WS_VSCROLL | WindowStyle.WS_BORDER), 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/ScrollBarStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum ScrollBarStyle : uint 31 | { 32 | SBS_HORZ = 0x0000, 33 | SBS_VERT = 0x0001, 34 | SBS_TOPALIGN = 0x0002, 35 | SBS_LEFTALIGN = 0x0002, 36 | SBS_BOTTOMALIGN = 0x0004, 37 | SBS_RIGHTALIGN = 0x0004, 38 | SBS_SIZEBOXTOPLEFTALIGN = 0x0002, 39 | SBS_SIZEBOXBOTTOMRIGHTALIGN = 0x0004, 40 | SBS_SIZEBOX = 0x0008, 41 | SBS_SIZEGRIP = 0x0010 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/StaticStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum StaticStyle 31 | { 32 | SS_LEFT = 0x00000000, 33 | SS_CENTER = 0x00000001, 34 | SS_RIGHT = 0x00000002, 35 | SS_ICON = 0x00000003, 36 | SS_BLACKRECT = 0x00000004, 37 | SS_GRAYRECT = 0x00000005, 38 | SS_WHITERECT = 0x00000006, 39 | SS_BLACKFRAME = 0x00000007, 40 | SS_GRAYFRAME = 0x00000008, 41 | SS_WHITEFRAME = 0x00000009, 42 | SS_USERITEM = 0x0000000A, 43 | SS_SIMPLE = 0x0000000B, 44 | SS_LEFTNOWORDWRAP = 0x0000000C, 45 | SS_OWNERDRAW = 0x0000000D, 46 | SS_BITMAP = 0x0000000E, 47 | SS_ENHMETAFILE = 0x0000000F, 48 | SS_ETCHEDHORZ = 0x00000010, 49 | SS_ETCHEDVERT = 0x00000011, 50 | SS_ETCHEDFRAME = 0x00000012, 51 | SS_TYPEMASK = 0x0000001F, 52 | SS_REALSIZECONTROL = 0x00000040, 53 | SS_NOPREFIX = 0x00000080, 54 | SS_NOTIFY = 0x00000100, 55 | SS_CENTERIMAGE = 0x00000200, 56 | SS_RIGHTJUST = 0x00000400, 57 | SS_REALSIZEIMAGE = 0x00000800, 58 | SS_SUNKEN = 0x00001000, 59 | SS_EDITCONTROL = 0x00002000, 60 | SS_ENDELLIPSIS = 0x00004000, 61 | SS_PATHELLIPSIS = 0x00008000, 62 | SS_WORDELLIPSIS = 0x0000C000, 63 | SS_ELLIPSISMASK = 0x0000C000, 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/WindowStyle.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum WindowStyle : uint 31 | { 32 | WS_OVERLAPPED = 0x00000000, 33 | WS_POPUP = 0x80000000, 34 | WS_CHILD = 0x40000000, 35 | WS_MINIMIZE = 0x20000000, 36 | WS_VISIBLE = 0x10000000, 37 | WS_DISABLED = 0x08000000, 38 | WS_CLIPSIBLINGS = 0x04000000, 39 | WS_CLIPCHILDREN = 0x02000000, 40 | WS_MAXIMIZE = 0x01000000, 41 | WS_CAPTION = 0x00C00000, // WS_BORDER | WS_DLGFRAME 42 | WS_BORDER = 0x00800000, 43 | WS_DLGFRAME = 0x00400000, 44 | WS_VSCROLL = 0x00200000, 45 | WS_HSCROLL = 0x00100000, 46 | WS_SYSMENU = 0x00080000, 47 | WS_THICKFRAME = 0x00040000, 48 | WS_GROUP = 0x00020000, 49 | WS_TABSTOP = 0x00010000, 50 | 51 | WS_MINIMIZEBOX = 0x00020000, 52 | WS_MAXIMIZEBOX = 0x00010000, 53 | 54 | WS_TILED = WS_OVERLAPPED, 55 | WS_ICONIC = WS_MINIMIZE, 56 | WS_SIZEBOX = WS_THICKFRAME, 57 | WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW, 58 | 59 | WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX), 60 | WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU), 61 | WS_CHILDWINDOW = WS_CHILD 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Dialogs/Styles/WindowStyleEx.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Dialogs.Styles 28 | { 29 | [Flags] 30 | public enum WindowStyleEx : uint 31 | { 32 | WS_EX_DLGMODALFRAME = 0x00000001, 33 | WS_EX_NOPARENTNOTIFY = 0x00000004, 34 | WS_EX_TOPMOST = 0x00000008, 35 | WS_EX_ACCEPTFILES = 0x00000010, 36 | WS_EX_TRANSPARENT = 0x00000020, 37 | WS_EX_MDICHILD = 0x00000040, 38 | WS_EX_TOOLWINDOW = 0x00000080, 39 | WS_EX_WINDOWEDGE = 0x00000100, 40 | WS_EX_CLIENTEDGE = 0x00000200, 41 | WS_EX_CONTEXTHELP = 0x00000400, 42 | WS_EX_RIGHT = 0x00001000, 43 | WS_EX_LEFT = 0x00000000, 44 | WS_EX_RTLREADING = 0x00002000, 45 | WS_EX_LTRREADING = 0x00000000, 46 | WS_EX_LEFTSCROLLBAR = 0x00004000, 47 | WS_EX_RIGHTSCROLLBAR = 0x00000000, 48 | WS_EX_CONTROLPARENT = 0x00010000, 49 | WS_EX_STATICEDGE = 0x00020000, 50 | WS_EX_APPWINDOW = 0x00040000, 51 | WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE), 52 | WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST), 53 | WS_EX_LAYERED = 0x00080000, 54 | WS_EX_NOINHERITLAYOUT = 0x00100000, // Disable inheritence of mirroring by children 55 | WS_EX_LAYOUTRTL = 0x00400000, // Right to left mirroring 56 | WS_EX_COMPOSITED = 0x02000000, 57 | WS_EX_NOACTIVATE = 0x08000000 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/CursorData.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Graphics 28 | { 29 | internal struct CursorData 30 | { 31 | public ushort HotspotX; 32 | public ushort HotspotY; 33 | public ushort Width; 34 | public ushort Height; 35 | public byte ColorCount; 36 | public byte[] DIB; 37 | public bool IsPNG; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/CursorGroupEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | using Workshell.PE.Resources.Native; 28 | 29 | namespace Workshell.PE.Resources.Graphics 30 | { 31 | public sealed class CursorGroupEntry 32 | { 33 | internal CursorGroupEntry(CURSOR_RESDIR resDir) 34 | { 35 | Width = resDir.Cursor.Width; 36 | Height = resDir.Cursor.Height; 37 | Planes = resDir.Planes; 38 | BitCount = resDir.BitCount; 39 | BytesInRes = resDir.BytesInRes; 40 | CursorId = resDir.CursorId; 41 | } 42 | 43 | #region Methods 44 | 45 | public override string ToString() 46 | { 47 | return $"{Width}x{Height} {BitCount}-bit, ID: {CursorId}"; 48 | } 49 | 50 | #endregion 51 | 52 | #region Properties 53 | 54 | public ushort Width { get; } 55 | public ushort Height { get; } 56 | public ushort Planes { get; } 57 | public ushort BitCount { get; } 58 | public uint BytesInRes { get; } 59 | public ushort CursorId { get; } 60 | 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/CursorInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Drawing; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Graphics 29 | { 30 | public sealed class CursorInfo 31 | { 32 | internal CursorInfo(CursorResource cursor, ResourceLanguage language, ushort hotspotX, ushort hotspotY, ushort width, ushort height, byte colors, byte[] dib, bool isPNG) 33 | { 34 | Cursor = cursor; 35 | Language = language; 36 | Hotspot = new Point(hotspotX, hotspotY); 37 | Size = new Size(width, height); 38 | Colors = colors; 39 | DIB = dib; 40 | IsPNG = isPNG; 41 | } 42 | 43 | #region Properties 44 | 45 | public CursorResource Cursor { get; } 46 | public ResourceLanguage Language { get; } 47 | public Point Hotspot { get; } 48 | public Size Size { get; } 49 | public byte Colors { get; } 50 | public byte[] DIB { get; } 51 | public bool IsPNG { get; } 52 | 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/GraphicResources.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Graphics 28 | { 29 | public static class GraphicResources 30 | { 31 | #region Methods 32 | 33 | public static void Register() 34 | { 35 | BitmapResource.Register(); 36 | CursorGroupResource.Register(); 37 | CursorResource.Register(); 38 | IconGroupResource.Register(); 39 | IconResource.Register(); 40 | } 41 | 42 | #endregion 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/GraphicUtils.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | 29 | namespace Workshell.PE.Resources.Graphics 30 | { 31 | internal static class GraphicUtils 32 | { 33 | #region Methods 34 | 35 | public static bool IsPNG(byte[] data) 36 | { 37 | if (data.Length < 8) 38 | return false; 39 | 40 | var signature = BitConverter.ToUInt64(data, 0); 41 | 42 | return (signature == 727905341920923785L); 43 | } 44 | 45 | public static bool IsPNG(Stream stream) 46 | { 47 | return IsPNGAsync(stream).GetAwaiter().GetResult(); 48 | } 49 | 50 | public static async Task IsPNGAsync(Stream stream) 51 | { 52 | var buffer = new byte[sizeof(ulong)]; 53 | var numRead = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); 54 | 55 | if (numRead < sizeof(ulong)) 56 | return false; 57 | 58 | return IsPNG(buffer); 59 | } 60 | 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/IconData.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Graphics 28 | { 29 | internal struct IconData 30 | { 31 | public ushort Width; 32 | public ushort Height; 33 | public byte ColorCount; 34 | public byte[] DIB; 35 | public bool IsPNG; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/IconGroupEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | using Workshell.PE.Resources.Native; 28 | 29 | namespace Workshell.PE.Resources.Graphics 30 | { 31 | public sealed class IconGroupEntry 32 | { 33 | internal IconGroupEntry(ICON_RESDIR resDir) 34 | { 35 | Width = resDir.Icon.Width; 36 | Height = resDir.Icon.Height; 37 | ColorCount = resDir.Icon.ColorCount; 38 | Planes = resDir.Planes; 39 | BitCount = resDir.BitCount; 40 | BytesInRes = resDir.BytesInRes; 41 | IconId = resDir.IconId; 42 | 43 | if (Width == 0) 44 | Width = 256; 45 | 46 | if (Height == 0) 47 | Height = 256; 48 | } 49 | 50 | #region Methods 51 | 52 | public override string ToString() 53 | { 54 | return $"{Width}x{Height} {BitCount}-bit, ID: {IconId}"; 55 | } 56 | 57 | #endregion 58 | 59 | #region Properties 60 | 61 | public ushort Width { get; } 62 | public ushort Height { get; } 63 | public byte ColorCount { get; } 64 | public ushort Planes { get; } 65 | public ushort BitCount { get; } 66 | public uint BytesInRes { get; } 67 | public ushort IconId { get; } 68 | 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Graphics/IconInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Drawing; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Graphics 29 | { 30 | public sealed class IconInfo 31 | { 32 | internal IconInfo(IconResource resource, ResourceLanguage language, ushort width, ushort height, byte colors, byte[] dib, bool isPNG) 33 | { 34 | Icon = resource; 35 | Language = language; 36 | Size = new Size(width, height); 37 | Colors = colors; 38 | DIB = dib; 39 | IsPNG = isPNG; 40 | } 41 | 42 | #region Properties 43 | 44 | public IconResource Icon { get; } 45 | public ResourceLanguage Language { get; } 46 | public Size Size { get; } 47 | public byte Colors { get; } 48 | public byte[] DIB { get; } 49 | public bool IsPNG { get; } 50 | 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Menus/Menu.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Menus 29 | { 30 | public sealed class Menu : IEnumerable 31 | { 32 | private readonly MenuItem[] _items; 33 | 34 | internal Menu(MenuResource resource, uint languageId, MenuItem[] items) 35 | { 36 | _items = items; 37 | 38 | Count = _items.Length; 39 | Resource = resource; 40 | Language = languageId; 41 | } 42 | 43 | #region Methods 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | foreach (var item in _items) 48 | yield return item; 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | #endregion 57 | 58 | #region Properties 59 | 60 | public MenuResource Resource { get; } 61 | public ResourceLanguage Language { get; } 62 | 63 | public int Count { get; } 64 | public MenuItem this[int index] => _items[index]; 65 | 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Menus/MenuItem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Menus 28 | { 29 | public class MenuItem 30 | { 31 | internal MenuItem(ushort id, string text, ushort flags) 32 | { 33 | Id = id; 34 | 35 | var parts = text.Split(new [] { '\t' }, 2); 36 | 37 | Text = parts[0]; 38 | Shortcut = (parts.Length > 1 ? parts[1] : string.Empty); 39 | Flags = (MenuItemFlags)flags; 40 | } 41 | 42 | #region Methods 43 | 44 | public override string ToString() 45 | { 46 | if (IsSeperator) 47 | return "-"; 48 | 49 | var result = Text; 50 | 51 | if (IsPopup) 52 | result = "+" + result; 53 | 54 | if (Shortcut != string.Empty) 55 | result += " | " + Shortcut; 56 | 57 | return result; 58 | } 59 | 60 | #endregion 61 | 62 | #region Properties 63 | 64 | public ushort Id { get; } 65 | public string Text { get; } 66 | public string Shortcut { get; } 67 | public MenuItemFlags Flags { get; } 68 | public bool IsPopup => (Id == 0); 69 | public bool IsSeperator => (Id == 0 && Flags == MenuItemFlags.Enabled && Shortcut == string.Empty); 70 | 71 | #endregion 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Menus/MenuItemFlags.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Menus 28 | { 29 | [Flags] 30 | public enum MenuItemFlags : ushort 31 | { 32 | Enabled = 0, 33 | Grayed = 0x0001, 34 | Disabled = 0x0002, 35 | Bitmap = 0x0004, 36 | OwnerDraw = 0x0100, 37 | Checked = 0x0008, 38 | Popup = 0x0010, 39 | MenubarBreak = 0x0020, 40 | MenuBreak = 0x0040, 41 | EndMenu = 0x0080, 42 | Seperator = 0x0800 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Menus/PopupMenuItem.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Menus 29 | { 30 | public sealed class PopupMenuItem : MenuItem, IEnumerable 31 | { 32 | private readonly MenuItem[] _items; 33 | 34 | internal PopupMenuItem(ushort id, string text, ushort flags, MenuItem[] items) : base(id, text, flags) 35 | { 36 | _items = items; 37 | 38 | Count = _items.Length; 39 | } 40 | 41 | #region Methods 42 | 43 | public IEnumerator GetEnumerator() 44 | { 45 | foreach (var item in _items) 46 | yield return item; 47 | } 48 | 49 | IEnumerator IEnumerable.GetEnumerator() 50 | { 51 | return GetEnumerator(); 52 | } 53 | 54 | #endregion 55 | 56 | #region Properties 57 | 58 | public int Count { get; } 59 | public MenuItem this[int index] => _items[index]; 60 | 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Messages/MessageTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Messages 29 | { 30 | public sealed class MessageTable : IEnumerable 31 | { 32 | private readonly MessageTableBlock[] _blocks; 33 | 34 | internal MessageTable(MessageTableResource resource, uint languageId, MessageTableBlock[] blocks) 35 | { 36 | _blocks = blocks; 37 | 38 | Resource = resource; 39 | Language = languageId; 40 | Count = _blocks.Length; 41 | } 42 | 43 | #region Methods 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | foreach (var block in _blocks) 48 | yield return block; 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | #endregion 57 | 58 | #region Properties 59 | 60 | public MessageTableResource Resource { get; } 61 | public ResourceLanguage Language { get; } 62 | 63 | public int Count { get; } 64 | public MessageTableBlock this[int index] => _blocks[index]; 65 | 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Messages/MessageTableBlock.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Messages 29 | { 30 | public sealed class MessageTableBlock : IEnumerable 31 | { 32 | private readonly MessageTableEntry[] _entries; 33 | 34 | internal MessageTableBlock(uint lowId, uint highId, uint offsetToEntries, MessageTableEntry[] entries) 35 | { 36 | _entries = entries; 37 | 38 | LowId = lowId; 39 | HighId = highId; 40 | OffsetToEntries = offsetToEntries; 41 | Count = _entries.Length; 42 | } 43 | 44 | #region Methods 45 | 46 | public IEnumerator GetEnumerator() 47 | { 48 | foreach (var entry in _entries) 49 | yield return entry; 50 | } 51 | 52 | IEnumerator IEnumerable.GetEnumerator() 53 | { 54 | return GetEnumerator(); 55 | } 56 | 57 | #endregion 58 | 59 | #region Properties 60 | 61 | public uint LowId { get; } 62 | public uint HighId { get; } 63 | public uint OffsetToEntries { get; } 64 | 65 | public int Count { get; } 66 | public MessageTableEntry this[int index] => _entries[index]; 67 | 68 | #endregion 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Messages/MessageTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Messages 28 | { 29 | public sealed class MessageTableEntry 30 | { 31 | internal MessageTableEntry(uint id, string message, bool isUnicode) 32 | { 33 | Id = id; 34 | Message = message; 35 | IsUnicode = isUnicode; 36 | } 37 | 38 | #region Methods 39 | 40 | public override string ToString() 41 | { 42 | return $"0x{Id:X8}: {Message}"; 43 | } 44 | 45 | #endregion 46 | 47 | #region Properties 48 | 49 | public uint Id { get; } 50 | public string Message { get; } 51 | public bool IsUnicode { get; } 52 | 53 | #endregion 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/ACCELTABLEENTRY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct ACCELTABLEENTRY 32 | { 33 | public ushort fFlags; 34 | public ushort wAnsi; 35 | public ushort wId; 36 | public ushort padding; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/BITMAPFILEHEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | public struct BITMAPFILEHEADER 32 | { 33 | public ushort Tag; 34 | public uint Size; 35 | public ushort Reserved1; 36 | public ushort Reserved2; 37 | public uint BitmapOffset; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/BITMAPINFOHEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | public enum BitmapCompressionMode : uint 31 | { 32 | BI_RGB = 0, 33 | BI_RLE8 = 1, 34 | BI_RLE4 = 2, 35 | BI_BITFIELDS = 3, 36 | BI_JPEG = 4, 37 | BI_PNG = 5 38 | } 39 | 40 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 41 | public struct BITMAPINFOHEADER 42 | { 43 | public uint biSize; 44 | public int biWidth; 45 | public int biHeight; 46 | public ushort biPlanes; 47 | public ushort biBitCount; 48 | public BitmapCompressionMode biCompression; 49 | public uint biSizeImage; 50 | public int biXPelsPerMeter; 51 | public int biYPelsPerMeter; 52 | public uint biClrUsed; 53 | public uint biClrImportant; 54 | 55 | public void Initialize() 56 | { 57 | biSize = (uint)Utils.SizeOf(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/CURSORDIR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct CURSORDIR 32 | { 33 | public ushort Width; 34 | public ushort Height; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/CURSOR_RESDIR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct CURSOR_RESDIR 32 | { 33 | public CURSORDIR Cursor; 34 | public ushort Planes; 35 | public ushort BitCount; 36 | public uint BytesInRes; 37 | public ushort CursorId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/ICONDIR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct ICONDIR 32 | { 33 | public byte Width; 34 | public byte Height; 35 | public byte ColorCount; 36 | public byte Reserved; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/ICON_RESDIR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct ICON_RESDIR 32 | { 33 | public ICONDIR Icon; 34 | public ushort Planes; 35 | public ushort BitCount; 36 | public uint BytesInRes; 37 | public ushort IconId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/MESSAGETABLE.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | public struct MESSAGE_RESOURCE_DATA 32 | { 33 | public uint NumberOfBlocks; 34 | } 35 | 36 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 37 | public struct MESSAGE_RESOURCE_BLOCK 38 | { 39 | public uint LowId; 40 | public uint HighId; 41 | public uint OffsetToEntries; 42 | } 43 | 44 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 45 | public struct MESSAGE_RESOURCE_ENTRY 46 | { 47 | public ushort Length; 48 | public ushort Flags; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/NEWHEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct NEWHEADER 32 | { 33 | public const ushort RES_ICON = 1; 34 | public const ushort RES_CURSOR = 2; 35 | 36 | public ushort Reserved; 37 | public ushort ResType; 38 | public ushort ResCount; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Native/VS_FIXEDFILEINFO.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct VS_FIXEDFILEINFO 32 | { 33 | public uint dwSignature; 34 | public uint dwStrucVersion; 35 | public uint dwFileVersionMS; 36 | public uint dwFileVersionLS; 37 | public uint dwProductVersionMS; 38 | public uint dwProductVersionLS; 39 | public uint dwFileFlagsMask; 40 | public uint dwFileFlags; 41 | public uint dwFileOS; 42 | public uint dwFileType; 43 | public uint dwFileSubtype; 44 | public uint dwFileDateMS; 45 | public uint dwFileDateLS; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System.Reflection; 24 | 25 | [assembly: AssemblyTitle("Workshell.PE.Resources")] 26 | [assembly: AssemblyDescription("A set of classes for dealing with resources within a PE file.")] 27 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/ResourceUtils.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | 29 | using Workshell.PE.Extensions; 30 | 31 | namespace Workshell.PE.Resources 32 | { 33 | internal static class ResourceUtils 34 | { 35 | #region Methods 36 | 37 | public static async Task> OrdOrSzAsync(Stream stream) 38 | { 39 | var value = await stream.ReadUInt16Async().ConfigureAwait(false); 40 | 41 | if (value == 0) 42 | return new Tuple(0, string.Empty); 43 | 44 | if (value == 0xFFFF) 45 | { 46 | value = await stream.ReadUInt16Async().ConfigureAwait(false); 47 | 48 | return new Tuple(value, string.Empty); 49 | } 50 | 51 | var builder = new StringBuilder(256); 52 | 53 | while (true) 54 | { 55 | if (value == 0) 56 | break; 57 | 58 | builder.Append((char)value); 59 | 60 | value = await stream.ReadUInt16Async().ConfigureAwait(false); 61 | } 62 | 63 | return new Tuple(value, builder.ToString()); 64 | } 65 | 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Strings/StringTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Strings 29 | { 30 | public sealed class StringTable : IEnumerable 31 | { 32 | private readonly StringTableEntry[] _entries; 33 | 34 | internal StringTable(StringTableResource resource, uint languageId, StringTableEntry[] entries) 35 | { 36 | _entries = entries; 37 | 38 | Count = _entries.Length; 39 | Resource = resource; 40 | Language = languageId; 41 | } 42 | 43 | #region Methods 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | foreach (var entry in _entries) 48 | yield return entry; 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | #endregion 57 | 58 | #region Properties 59 | 60 | public StringTableResource Resource { get; } 61 | public ResourceLanguage Language { get; } 62 | 63 | public int Count { get; } 64 | public StringTableEntry this[int index] => _entries[index]; 65 | 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Strings/StringTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Strings 28 | { 29 | public sealed class StringTableEntry 30 | { 31 | internal StringTableEntry(ushort id, string value) 32 | { 33 | Id = id; 34 | Value = value; 35 | } 36 | 37 | #region Methods 38 | 39 | public override string ToString() 40 | { 41 | if (Id == 0) 42 | return "(Empty)"; 43 | 44 | return $"{Id} = {Value}"; 45 | } 46 | 47 | #endregion 48 | 49 | #region Properties 50 | 51 | public ushort Id { get; } 52 | public string Value { get; } 53 | public bool IsEmpty => (Id == 0); 54 | 55 | #endregion 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Version/FileInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Workshell.PE.Resources.Version 8 | { 9 | internal sealed class FileInfo 10 | { 11 | public ushort Length { get; set; } 12 | public ushort ValueLength { get; set; } 13 | public ushort Type { get; set; } 14 | public string Key { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Version/VersionInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Resources.Version 29 | { 30 | public sealed class VersionInfo 31 | { 32 | private readonly IReadOnlyCollection _strings; 33 | private readonly IReadOnlyCollection _variables; 34 | 35 | internal VersionInfo(VersionResource resource, uint languageId, FixedFileInfo fixedInfo, IReadOnlyCollection stringInfo, IReadOnlyCollection varInfo) 36 | { 37 | Resource = resource; 38 | Language = languageId; 39 | Fixed = fixedInfo; 40 | _strings = stringInfo; 41 | _variables = varInfo; 42 | } 43 | 44 | #region Properties 45 | 46 | public VersionResource Resource { get; } 47 | public ResourceLanguage Language { get; } 48 | public FixedFileInfo Fixed { get; } 49 | public StringFileInfo Strings => _strings.FirstOrDefault(); 50 | public VarFileInfo Variables => _variables.FirstOrDefault(); 51 | 52 | #endregion 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Version/VersionString.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Version 28 | { 29 | public sealed class VersionString 30 | { 31 | internal VersionString(string key, string value) 32 | { 33 | Key = key; 34 | Value = value; 35 | } 36 | 37 | #region Methods 38 | 39 | public override string ToString() 40 | { 41 | return $"{Key} = {Value}"; 42 | } 43 | 44 | #endregion 45 | 46 | #region Properties 47 | 48 | public string Key { get; } 49 | public string Value { get; } 50 | 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Version/VersionStringTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | using System.Text; 28 | 29 | namespace Workshell.PE.Resources.Version 30 | { 31 | public sealed class VersionStringTable : IEnumerable 32 | { 33 | private readonly VersionString[] _strings; 34 | 35 | internal VersionStringTable(string key, VersionString[] strings) 36 | { 37 | _strings = strings; 38 | 39 | Key = key; 40 | Count = _strings.Length; 41 | } 42 | 43 | #region Methods 44 | 45 | public override string ToString() 46 | { 47 | return $"Key: {Key}, Strings: {Count:n0}"; 48 | } 49 | 50 | public IEnumerator GetEnumerator() 51 | { 52 | foreach (var str in _strings) 53 | yield return str; 54 | } 55 | 56 | IEnumerator IEnumerable.GetEnumerator() 57 | { 58 | return GetEnumerator(); 59 | } 60 | 61 | #endregion 62 | 63 | #region Properties 64 | 65 | public string Key { get; } 66 | public int Count { get; } 67 | public VersionString this[int index] => _strings[index]; 68 | public VersionString this[string key] => _strings.FirstOrDefault(s => string.Compare(key, s.Key, StringComparison.OrdinalIgnoreCase) == 0); 69 | 70 | #endregion 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Version/VersionVariable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Resources.Version 28 | { 29 | public sealed class VersionVariable 30 | { 31 | internal VersionVariable(string key, uint value) 32 | { 33 | Key = key; 34 | Value = value; 35 | } 36 | 37 | #region Methods 38 | 39 | public override string ToString() 40 | { 41 | return $"{Key} = 0x{Value:X8}"; 42 | } 43 | 44 | #endregion 45 | 46 | #region Properties 47 | 48 | public string Key { get; } 49 | public uint Value { get; } 50 | 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Workshell.PE.Resources/Workshell.PE.Resources.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0;net7.0;net6.0 5 | false 6 | false 7 | Workshell.snk 8 | Debug;Release;CI 9 | 10 | 11 | 12 | Workshell.PE.Resources 13 | A set of classes that extends the Workshell.PE class library to help deal with the standard resource types within an executable such as bitmaps, icons, cursors etc. 14 | https://github.com/Workshell/pe 15 | http://img.workshell.co.uk/logo_128.png 16 | workshell pe executable native resources 17 | license.txt 18 | Workshell Ltd 19 | Workshell Ltd 20 | https://github.com/Workshell/pe 21 | git 22 | 0.0.0.1 23 | 24 | 25 | 26 | 27 | 28 | 29 | ..\..\bin\debug 30 | TRACE 31 | 32 | 33 | 34 | ..\..\bin\release 35 | TRACE 36 | 37 | 38 | 39 | ..\..\bin\ci 40 | TRACE;SIGNED 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/Workshell.PE/Annotations/EnumAnnotationAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Annotations 28 | { 29 | [AttributeUsage(AttributeTargets.Field)] 30 | public sealed class EnumAnnotationAttribute : Attribute 31 | { 32 | public EnumAnnotationAttribute(string name) 33 | { 34 | Name = name; 35 | } 36 | 37 | #region Properties 38 | 39 | public string Name { get; } 40 | public string Description { get; set; } 41 | 42 | #endregion 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Workshell.PE/Annotations/FieldAnnotationAttribute.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Annotations 28 | { 29 | [AttributeUsage(AttributeTargets.Property)] 30 | public sealed class FieldAnnotationAttribute : Attribute 31 | { 32 | public FieldAnnotationAttribute(string desc) 33 | { 34 | Description = desc; 35 | ArrayLength = 0; 36 | Flags = false; 37 | FlagType = null; 38 | Order = int.MinValue; 39 | } 40 | 41 | #region Properties 42 | 43 | public string Description { get; set; } 44 | public int ArrayLength { get; set; } 45 | public bool Flags { get; set; } 46 | public Type FlagType { get; set; } 47 | public int Order { get; set; } 48 | 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/CLR/CLRDataDirectory.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using Workshell.PE.Native; 27 | 28 | namespace Workshell.PE.Content 29 | { 30 | public sealed class CLRDataDirectory 31 | { 32 | internal CLRDataDirectory(uint virtualAddress, uint size) 33 | { 34 | VirtualAddress = virtualAddress; 35 | Size = size; 36 | } 37 | 38 | #region Static Methods 39 | 40 | public static bool IsNullOrEmpty(DataDirectory dataDirectory) 41 | { 42 | if (dataDirectory == null) 43 | return true; 44 | 45 | if (dataDirectory.VirtualAddress == 0) 46 | return true; 47 | 48 | if (dataDirectory.Size == 0) 49 | return true; 50 | 51 | return false; 52 | } 53 | 54 | #endregion 55 | 56 | #region Methods 57 | 58 | public override string ToString() 59 | { 60 | return $"0x{VirtualAddress:X8}+{Size}"; 61 | } 62 | 63 | #endregion 64 | 65 | #region Properties 66 | 67 | public uint VirtualAddress { get; } 68 | public uint Size { get; } 69 | 70 | #endregion 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/CLR/CLRMetaDataStreamTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | using Workshell.PE.Extensions; 29 | 30 | namespace Workshell.PE.Content 31 | { 32 | public sealed class CLRMetaDataStreamTableEntry : ISupportsLocation, ISupportsBytes 33 | { 34 | private readonly PortableExecutableImage _image; 35 | 36 | internal CLRMetaDataStreamTableEntry(PortableExecutableImage image, Location location, uint offset, uint size, string name) 37 | { 38 | _image = image; 39 | 40 | Location = location; 41 | Offset = offset; 42 | Size = size; 43 | Name = name; 44 | } 45 | 46 | #region Methods 47 | 48 | public override string ToString() 49 | { 50 | return $"Offset: 0x{Offset:X8}, Size: {Size}, Name: {Name}"; 51 | } 52 | 53 | public byte[] GetBytes() 54 | { 55 | return GetBytesAsync().GetAwaiter().GetResult(); 56 | } 57 | 58 | public async Task GetBytesAsync() 59 | { 60 | var stream = _image.GetStream(); 61 | var buffer = await stream.ReadBytesAsync(Location).ConfigureAwait(false); 62 | 63 | return buffer; 64 | } 65 | 66 | #endregion 67 | 68 | #region Properties 69 | 70 | public Location Location { get; } 71 | public uint Offset { get; } 72 | public uint Size { get; } 73 | public string Name { get; } 74 | 75 | #endregion 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/DataContent.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | using Workshell.PE.Extensions; 28 | 29 | namespace Workshell.PE.Content 30 | { 31 | public class DataContent : ISupportsLocation, ISupportsBytes 32 | { 33 | public DataContent(PortableExecutableImage image, DataDirectory dataDirectory, Location location) 34 | { 35 | DataDirectory = dataDirectory; 36 | Location = location; 37 | Image = image; 38 | } 39 | 40 | #region Methods 41 | 42 | public byte[] GetBytes() 43 | { 44 | return GetBytesAsync().GetAwaiter().GetResult(); 45 | } 46 | 47 | public async Task GetBytesAsync() 48 | { 49 | var stream = Image.GetStream(); 50 | var result = await stream.ReadBytesAsync(Location).ConfigureAwait(false); 51 | 52 | return result; 53 | } 54 | 55 | #endregion 56 | 57 | #region Properties 58 | 59 | public DataDirectory DataDirectory { get; } 60 | public Location Location { get; } 61 | protected PortableExecutableImage Image { get; } 62 | 63 | #endregion 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exceptions/ExceptionChainedUnwindInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Linq; 27 | using System.Text; 28 | using System.Threading.Tasks; 29 | using Workshell.PE.Annotations; 30 | using Workshell.PE.Extensions; 31 | 32 | namespace Workshell.PE.Content.Exceptions 33 | { 34 | public sealed class ExceptionChainedUnwindInfo 35 | { 36 | internal ExceptionChainedUnwindInfo(uint startAddress, uint endAddress, uint infoAddress) 37 | { 38 | StartAddress = startAddress; 39 | EndAddress = endAddress; 40 | UnwindInfoAddress = infoAddress; 41 | } 42 | 43 | #region Properties 44 | 45 | [FieldAnnotation("Start Address", Order = 1)] 46 | public uint StartAddress { get; } 47 | 48 | [FieldAnnotation("End Address", Order = 2)] 49 | public uint EndAddress { get; } 50 | 51 | [FieldAnnotation("Unwind Info Address", Order = 3)] 52 | public uint UnwindInfoAddress { get; } 53 | 54 | #endregion 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exceptions/ExceptionTable32.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Runtime.InteropServices; 27 | using System.Text; 28 | using System.Threading.Tasks; 29 | using Workshell.PE.Extensions; 30 | using Workshell.PE.Native; 31 | 32 | namespace Workshell.PE.Content 33 | { 34 | public sealed class ExceptionTable32 : ExceptionTable 35 | { 36 | private ExceptionTable32(PortableExecutableImage image, DataDirectory dataDirectory, Location location, ExceptionTableEntry[] entries) : base(image, dataDirectory, location, entries) 37 | { 38 | } 39 | 40 | #region Static Methods 41 | 42 | internal static Task GetAsync(PortableExecutableImage image, DataDirectory dataDirectory, Location location) 43 | { 44 | ExceptionTable table = new ExceptionTable32(image, dataDirectory, location, new ExceptionTableEntry[0]); 45 | 46 | return Task.FromResult(table); 47 | } 48 | 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exceptions/ExceptionTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | using Workshell.PE.Extensions; 28 | 29 | namespace Workshell.PE.Content 30 | { 31 | public abstract class ExceptionTableEntry : ISupportsLocation, ISupportsBytes 32 | { 33 | protected internal ExceptionTableEntry(PortableExecutableImage image, Location location) 34 | { 35 | Image = image; 36 | Location = location; 37 | } 38 | 39 | #region Methods 40 | 41 | public byte[] GetBytes() 42 | { 43 | return GetBytesAsync().GetAwaiter().GetResult(); 44 | } 45 | 46 | public async Task GetBytesAsync() 47 | { 48 | var stream = Image.GetStream(); 49 | var buffer = await stream.ReadBytesAsync(Location).ConfigureAwait(false); 50 | 51 | return buffer; 52 | } 53 | 54 | #endregion 55 | 56 | #region Properties 57 | 58 | public Location Location { get; } 59 | protected PortableExecutableImage Image { get; } 60 | 61 | #endregion 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exceptions/ExceptionTableEntry32.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class ExceptionTableEntry32 : ExceptionTableEntry 30 | { 31 | internal ExceptionTableEntry32(PortableExecutableImage image, Location location) : base(image, location) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exceptions/ExceptionUnwindInfoCode.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using Workshell.PE.Annotations; 27 | 28 | namespace Workshell.PE.Content.Exceptions 29 | { 30 | public enum ExceptionUnwindCode : byte 31 | { 32 | [EnumAnnotation("UWOP_PUSH_NONVOL")] 33 | PushNonVolatile = 0, 34 | [EnumAnnotation("UWOP_ALLOC_LARGE ")] 35 | AllocLarge = 1, 36 | [EnumAnnotation("UWOP_ALLOC_SMALL")] 37 | AllocSmall = 2, 38 | [EnumAnnotation("UWOP_SET_FPREG")] 39 | SetFramePointerRegister = 3, 40 | [EnumAnnotation("UWOP_SAVE_NONVOL")] 41 | SaveNonVolatile = 4, 42 | [EnumAnnotation("UWOP_SAVE_NONVOL_FAR ")] 43 | SaveNonVolatileFar = 5, 44 | [EnumAnnotation("UWOP_SAVE_XMM128")] 45 | SaveXMM128 = 8, 46 | [EnumAnnotation("UWOP_SAVE_XMM128_FAR")] 47 | SaveXMM128Far = 9, 48 | [EnumAnnotation("UWOP_PUSH_MACHFRAME")] 49 | PushMachineFrame = 10 50 | } 51 | 52 | public sealed class ExceptionUnwindInfoCode 53 | { 54 | internal ExceptionUnwindInfoCode(ushort value) 55 | { 56 | var bytes = BitConverter.GetBytes(value); 57 | 58 | Value = value; 59 | Offset = bytes[0]; 60 | Code = (ExceptionUnwindCode)Convert.ToByte(bytes[1] & ((1 << 4) - 1)); 61 | Operation = Convert.ToByte(bytes[1] >> 4 & ((1 << 4) - 1)); 62 | } 63 | 64 | #region Methods 65 | 66 | public override string ToString() 67 | { 68 | return $"Offset: 0x{Offset:X2}, Code: {Code}, Operation: 0x{Operation:X2}"; 69 | } 70 | 71 | #endregion 72 | 73 | #region Properties 74 | 75 | public ushort Value { get; } 76 | public byte Offset { get; } 77 | public ExceptionUnwindCode Code { get; } 78 | public byte Operation { get; } 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Exports/Export.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class Export 30 | { 31 | internal Export(uint entryPoint, string name, uint ord, string forwardName) 32 | { 33 | EntryPoint = entryPoint; 34 | Name = name ?? string.Empty; 35 | Ordinal = ord; 36 | ForwardName = forwardName ?? string.Empty; 37 | } 38 | 39 | #region Methods 40 | 41 | public override string ToString() 42 | { 43 | string result; 44 | 45 | if (string.IsNullOrWhiteSpace(ForwardName)) 46 | { 47 | result = $"0x{EntryPoint:X8} {Ordinal:D4} {Name}"; 48 | } 49 | else 50 | { 51 | result = $"0x{EntryPoint:X8} {Ordinal:D4} {Name} -> {ForwardName}"; 52 | } 53 | 54 | return result; 55 | } 56 | 57 | #endregion 58 | 59 | #region Properties 60 | 61 | public uint EntryPoint { get; } 62 | public string Name { get; } 63 | public uint Ordinal { get; } 64 | public string ForwardName { get; } 65 | 66 | #endregion 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/DelayedImportAddressTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | using Workshell.PE.Extensions; 29 | 30 | namespace Workshell.PE.Content 31 | { 32 | public sealed class DelayedImportAddressTable : ImportAddressTableBase 33 | { 34 | internal DelayedImportAddressTable(PortableExecutableImage image, uint rva, ulong[] entries, ImportDirectoryEntryBase directoryEntry) : base(image, rva, entries, directoryEntry, true) 35 | { 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/DelayedImportAddressTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class DelayedImportAddressTableEntry : ImportAddressTableEntryBase 30 | { 31 | internal DelayedImportAddressTableEntry(PortableExecutableImage image, long entryOffset, ulong entryValue, uint entryAddress, ushort entryOrdinal, bool isOrdinal) : base(image, entryOffset, entryValue, entryAddress, entryOrdinal, isOrdinal, true) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/DelayedImportHintNameEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class DelayedImportHintNameEntry : ImportHintNameEntryBase 30 | { 31 | internal DelayedImportHintNameEntry(PortableExecutableImage image, long offset, uint size, ushort entryHint, string entryName, bool isPadded) : base(image, offset, size, entryHint, entryName, isPadded, true) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/DelayedImportLibrary.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Content 29 | { 30 | public sealed class DelayedImportLibrary : ImportLibraryBase 31 | { 32 | internal DelayedImportLibrary(ImportLibraryFunction[] functions, string name) : base(functions, name, true) 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportAddressTable.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class ImportAddressTable : ImportAddressTableBase 30 | { 31 | internal ImportAddressTable(PortableExecutableImage image, uint rva, ulong[] entries, ImportDirectoryEntryBase directoryEntry) : base(image, rva, entries, directoryEntry, false) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportAddressTableEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class ImportAddressTableEntry : ImportAddressTableEntryBase 30 | { 31 | internal ImportAddressTableEntry(PortableExecutableImage image, long entryOffset, ulong entryValue, uint entryAddress, ushort entryOrdinal, bool isOrdinal) : base(image, entryOffset, entryValue, entryAddress, entryOrdinal, isOrdinal, false) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportDirectoryBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.IO; 27 | using System.Text; 28 | using System.Threading.Tasks; 29 | 30 | using Workshell.PE.Extensions; 31 | 32 | namespace Workshell.PE.Content 33 | { 34 | public abstract class ImportDirectoryBase : DataContent, IEnumerable where T : ImportDirectoryEntryBase 35 | { 36 | private readonly T[] _entries; 37 | 38 | protected internal ImportDirectoryBase(PortableExecutableImage image, DataDirectory dataDirectory, Location location, T[] entries) : base(image, dataDirectory, location) 39 | { 40 | _entries = entries; 41 | 42 | Count = _entries.Length; 43 | } 44 | 45 | #region Static Methods 46 | 47 | protected internal static async Task GetNameAsync(LocationCalculator calc, Stream stream, uint nameRVA) 48 | { 49 | var fileOffset = calc.RVAToOffset(nameRVA); 50 | 51 | stream.Seek(fileOffset, SeekOrigin.Begin); 52 | 53 | var result = await stream.ReadStringAsync().ConfigureAwait(false); 54 | 55 | return result; 56 | } 57 | 58 | #endregion 59 | 60 | #region Methods 61 | 62 | public IEnumerator GetEnumerator() 63 | { 64 | foreach(var entry in _entries) 65 | yield return entry; 66 | } 67 | 68 | IEnumerator IEnumerable.GetEnumerator() 69 | { 70 | return GetEnumerator(); 71 | } 72 | 73 | #endregion 74 | 75 | #region Properties 76 | 77 | public int Count { get; } 78 | public T this[int index] => _entries[index]; 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportDirectoryEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using Workshell.PE.Annotations; 27 | using Workshell.PE.Native; 28 | 29 | namespace Workshell.PE.Content 30 | { 31 | public sealed class ImportDirectoryEntry : ImportDirectoryEntryBase 32 | { 33 | private readonly string _name; 34 | 35 | internal ImportDirectoryEntry(PortableExecutableImage image, Location location, IMAGE_IMPORT_DESCRIPTOR descriptor, string name) : base(image, location, false) 36 | { 37 | _name = name; 38 | 39 | OriginalFirstThunk = descriptor.OriginalFirstThunk; 40 | TimeDateStamp = descriptor.TimeDateStamp; 41 | ForwarderChain = descriptor.ForwarderChain; 42 | Name = descriptor.Name; 43 | FirstThunk = descriptor.FirstThunk; 44 | } 45 | 46 | #region Methods 47 | 48 | public DateTime GetTimeDateStamp() 49 | { 50 | return Utils.ConvertTimeDateStamp(TimeDateStamp); 51 | } 52 | 53 | public string GetName() 54 | { 55 | return _name; 56 | } 57 | 58 | #endregion 59 | 60 | #region Properties 61 | 62 | [FieldAnnotation("Original First Thunk", Order = 1)] 63 | public uint OriginalFirstThunk { get; } 64 | 65 | [FieldAnnotation("Date/Time Stamp", Order = 2)] 66 | public uint TimeDateStamp { get; } 67 | 68 | [FieldAnnotation("Forwarder Chain", Order = 3)] 69 | public uint ForwarderChain { get; } 70 | 71 | [FieldAnnotation("Name", Order = 4)] 72 | public override uint Name { get; } 73 | 74 | [FieldAnnotation("First Thunk", Order = 5)] 75 | public uint FirstThunk { get; } 76 | 77 | #endregion 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportHintNameEntry.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE.Content 28 | { 29 | public sealed class ImportHintNameEntry : ImportHintNameEntryBase 30 | { 31 | internal ImportHintNameEntry(PortableExecutableImage image, long offset, uint size, ushort entryHint, string entryName, bool isPadded) : base(image, offset, size, entryHint, entryName, isPadded, false) 32 | { 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportLibrary.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Content 29 | { 30 | public sealed class ImportLibrary : ImportLibraryBase 31 | { 32 | internal ImportLibrary(ImportLibraryFunction[] functions, string name) : base(functions, name, false) 33 | { 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Imports/ImportsBase.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | using System.Text; 28 | 29 | namespace Workshell.PE.Content 30 | { 31 | public abstract class ImportsBase : IEnumerable 32 | where TLibrary : ImportLibraryBase 33 | { 34 | private readonly TLibrary[] _libraries; 35 | 36 | protected internal ImportsBase(TLibrary[] libraries) 37 | { 38 | _libraries = libraries; 39 | 40 | Count = _libraries.Length; 41 | } 42 | 43 | #region Methods 44 | 45 | public IEnumerator GetEnumerator() 46 | { 47 | foreach (var library in _libraries) 48 | yield return library; 49 | } 50 | 51 | IEnumerator IEnumerable.GetEnumerator() 52 | { 53 | return GetEnumerator(); 54 | } 55 | 56 | #endregion 57 | 58 | #region Properties 59 | 60 | public int Count { get; } 61 | public TLibrary this[int index] => _libraries[index]; 62 | public TLibrary this[string name] => _libraries.FirstOrDefault(lib => string.Compare(name, lib.Name, StringComparison.OrdinalIgnoreCase) == 0); 63 | 64 | #endregion 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/LoadConfigurationCodeIntegrity.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Linq; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | 29 | using Workshell.PE.Native; 30 | 31 | namespace Workshell.PE.Content 32 | { 33 | public sealed class LoadConfigurationCodeIntegrity 34 | { 35 | private readonly LoadConfigurationDirectory _directory; 36 | private readonly IMAGE_LOAD_CONFIG_CODE_INTEGRITY _codeIntegrity; 37 | 38 | internal LoadConfigurationCodeIntegrity(LoadConfigurationDirectory directory, IMAGE_LOAD_CONFIG_CODE_INTEGRITY codeIntegrity) 39 | { 40 | _directory = directory; 41 | _codeIntegrity = codeIntegrity; 42 | } 43 | 44 | #region Properties 45 | 46 | public ushort Flags => _codeIntegrity.Flags; 47 | public ushort Catalog => _codeIntegrity.Catalog; 48 | public ulong CatalogOffset => _codeIntegrity.CatalogOffset; 49 | public ulong Reserved => _codeIntegrity.Reserved; 50 | 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Workshell.PE/Content/Resources/ResourceData.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | 29 | using Workshell.PE.Content; 30 | 31 | namespace Workshell.PE.Resources 32 | { 33 | public sealed class ResourceData : DataContent 34 | { 35 | internal ResourceData(PortableExecutableImage image, DataDirectory dataDirectory, Location location, ResourceDataEntry entry) : base(image, dataDirectory, location) 36 | { 37 | Entry = entry; 38 | } 39 | 40 | #region Methods 41 | 42 | public void CopyTo(Stream stream) 43 | { 44 | CopyToAsync(stream).GetAwaiter().GetResult(); 45 | } 46 | 47 | public async Task CopyToAsync(Stream stream) 48 | { 49 | var buffer = await GetBytesAsync().ConfigureAwait(false); 50 | 51 | await stream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false); 52 | } 53 | 54 | #endregion 55 | 56 | #region Properties 57 | 58 | public ResourceDataEntry Entry { get; } 59 | 60 | #endregion 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Workshell.PE/DOSStub.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.IO; 26 | using System.Text; 27 | using System.Threading.Tasks; 28 | using Workshell.PE.Extensions; 29 | 30 | namespace Workshell.PE 31 | { 32 | public sealed class DOSStub : ISupportsLocation, ISupportsBytes 33 | { 34 | private readonly PortableExecutableImage _image; 35 | 36 | internal DOSStub(PortableExecutableImage image, uint stubOffset, uint stubSize, ulong imageBase) 37 | { 38 | _image = image; 39 | 40 | Location = new Location(image, stubOffset, stubOffset, imageBase + stubOffset, stubSize, stubSize); 41 | } 42 | 43 | #region Methods 44 | 45 | public override string ToString() 46 | { 47 | return "MS-DOS Stub"; 48 | } 49 | 50 | public byte[] GetBytes() 51 | { 52 | return GetBytesAsync().GetAwaiter().GetResult(); 53 | } 54 | 55 | public async Task GetBytesAsync() 56 | { 57 | var stream = _image.GetStream(); 58 | var buffer = await stream.ReadBytesAsync(Location).ConfigureAwait(false); 59 | 60 | return buffer; 61 | } 62 | 63 | #endregion 64 | 65 | #region Properties 66 | 67 | public Location Location { get; } 68 | 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_BASE_RELOCATION.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_BASE_RELOCATION 32 | { 33 | public uint VirtualAddress; 34 | public uint SizeOfBlock; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_COR20_HEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_COR20_HEADER 32 | { 33 | public uint cb; 34 | public ushort MajorRuntimeVersion; 35 | public ushort MinorRuntimeVersion; 36 | public IMAGE_DATA_DIRECTORY MetaData; 37 | public uint Flags; 38 | public uint EntryPointTokenOrRVA; 39 | public IMAGE_DATA_DIRECTORY Resources; 40 | public IMAGE_DATA_DIRECTORY StrongNameSignature; 41 | public IMAGE_DATA_DIRECTORY CodeManagerTable; 42 | public IMAGE_DATA_DIRECTORY VTableFixups; 43 | public IMAGE_DATA_DIRECTORY ExportAddressTableJumps; 44 | public IMAGE_DATA_DIRECTORY ManagedNativeHeader; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_DATA_DIRECTORY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_DATA_DIRECTORY 32 | { 33 | public uint VirtualAddress; 34 | public uint Size; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_DEBUG_DIRECTORY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_DEBUG_DIRECTORY 32 | { 33 | public uint Characteristics; 34 | public uint TimeDateStamp; 35 | public ushort MajorVersion; 36 | public ushort MinorVersion; 37 | public uint Type; 38 | public uint SizeOfData; 39 | public uint AddressOfRawData; 40 | public uint PointerToRawData; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_DELAY_IMPORT_DESCRIPTOR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_DELAY_IMPORT_DESCRIPTOR 32 | { 33 | public uint Attributes; 34 | public uint Name; 35 | public uint ModuleHandle; 36 | public uint DelayAddressTable; 37 | public uint DelayNameTable; 38 | public uint BoundDelayIAT; 39 | public uint UnloadDelayIAT; 40 | public uint TimeDateStamp; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_DOS_HEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_DOS_HEADER 32 | { 33 | public ushort e_magic; // Magic number 34 | public ushort e_cblp; // Bytes on last page of file 35 | public ushort e_cp; // Pages in file 36 | public ushort e_crlc; // Relocations 37 | public ushort e_cparhdr; // Size of header in paragraphs 38 | public ushort e_minalloc; // Minimum extra paragraphs needed 39 | public ushort e_maxalloc; // Maximum extra paragraphs needed 40 | public ushort e_ss; // Initial (relative) SS value 41 | public ushort e_sp; // Initial SP value 42 | public ushort e_csum; // Checksum 43 | public ushort e_ip; // Initial IP value 44 | public ushort e_cs; // Initial (relative) CS value 45 | public ushort e_lfarlc; // File address of relocation table 46 | public ushort e_ovno; // Overlay number 47 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 48 | public ushort[] e_res_1; // Reserved words 49 | public ushort e_oemid; // OEM identifier (for e_oeminfo) 50 | public ushort e_oeminfo; // OEM information; e_oemid specific 51 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] 52 | public ushort[] e_res_2; // Reserved words 53 | public uint e_lfanew; // File address of new exe header 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_EXPORT_DIRECTORY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_EXPORT_DIRECTORY 32 | { 33 | public uint Characteristics; 34 | public uint TimeDateStamp; 35 | public ushort MajorVersion; 36 | public ushort MinorVersion; 37 | public uint Name; 38 | public uint Base; 39 | public uint NumberOfFunctions; 40 | public uint NumberOfNames; 41 | public uint AddressOfFunctions; // RVA from base of image 42 | public uint AddressOfNames; // RVA from base of image 43 | public uint AddressOfNameOrdinals; // RVA from base of image 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_FILE_HEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_FILE_HEADER 32 | { 33 | public ushort Machine; 34 | public ushort NumberOfSections; 35 | public uint TimeDateStamp; 36 | public uint PointerToSymbolTable; 37 | public uint NumberOfSymbols; 38 | public ushort SizeOfOptionalHeader; 39 | public ushort Characteristics; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_IMPORT_DESCRIPTOR.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_IMPORT_DESCRIPTOR 32 | { 33 | public uint OriginalFirstThunk; 34 | public uint TimeDateStamp; 35 | public uint ForwarderChain; 36 | public uint Name; 37 | public uint FirstThunk; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_RESOURCE_DATA_ENTRY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_RESOURCE_DATA_ENTRY 32 | { 33 | public uint OffsetToData; 34 | public uint Size; 35 | public uint CodePage; 36 | public uint Reserved; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_RESOURCE_DIRECTORY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct IMAGE_RESOURCE_DIRECTORY 32 | { 33 | public uint Characteristics; 34 | public uint TimeDateStamp; 35 | public ushort MajorVersion; 36 | public ushort MinorVersion; 37 | public ushort NumberOfNamedEntries; 38 | public ushort NumberOfIdEntries; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_RESOURCE_DIRECTORY_ENTRY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_RESOURCE_DIRECTORY_ENTRY 32 | { 33 | public uint Name; 34 | public uint OffsetToData; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_RUNTIME_FUNCTION.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_RUNTIME_FUNCTION_32 32 | { 33 | public uint BeginAddress; 34 | public uint EndAddress; 35 | public uint ExceptionHandler; 36 | public uint ExceptionData; 37 | public uint PrologEndAddress; 38 | } 39 | 40 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 41 | internal struct IMAGE_RUNTIME_FUNCTION_64 42 | { 43 | public uint StartAddress; 44 | public uint EndAddress; 45 | public uint UnwindInfoAddress; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_SECTION_HEADER.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Explicit, Pack = 1)] 31 | internal struct IMAGE_SECTION_HEADER 32 | { 33 | [FieldOffset(0)] 34 | [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] 35 | public char[] Name; 36 | 37 | [FieldOffset(8)] 38 | public uint VirtualSize; 39 | 40 | [FieldOffset(12)] 41 | public uint VirtualAddress; 42 | 43 | [FieldOffset(16)] 44 | public uint SizeOfRawData; 45 | 46 | [FieldOffset(20)] 47 | public uint PointerToRawData; 48 | 49 | [FieldOffset(24)] 50 | public uint PointerToRelocations; 51 | 52 | [FieldOffset(28)] 53 | public uint PointerToLineNumbers; 54 | 55 | [FieldOffset(32)] 56 | public ushort NumberOfRelocations; 57 | 58 | [FieldOffset(34)] 59 | public ushort NumberOfLineNumbers; 60 | 61 | [FieldOffset(36)] 62 | public uint Characteristics; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/IMAGE_TLS_DIRECTORY.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 31 | internal struct IMAGE_TLS_DIRECTORY32 32 | { 33 | public uint StartAddress; 34 | public uint EndAddress; 35 | public uint AddressOfIndex; 36 | public uint AddressOfCallbacks; 37 | public uint SizeOfZeroFill; 38 | public uint Characteristics; 39 | } 40 | 41 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 42 | internal struct IMAGE_TLS_DIRECTORY64 43 | { 44 | public ulong StartAddress; 45 | public ulong EndAddress; 46 | public ulong AddressOfIndex; 47 | public ulong AddressOfCallbacks; 48 | public uint SizeOfZeroFill; 49 | public uint Characteristics; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Workshell.PE/Native/WIN_CERTIFICATE.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Runtime.InteropServices; 26 | using System.Text; 27 | 28 | namespace Workshell.PE.Native 29 | { 30 | [StructLayout(LayoutKind.Sequential)] 31 | internal struct WIN_CERTIFICATE 32 | { 33 | public uint dwLength; 34 | public ushort wRevision; 35 | public ushort wCertificateType; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Workshell.PE/PortableExecutableImageException.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | 27 | namespace Workshell.PE 28 | { 29 | public sealed class PortableExecutableImageException : Exception 30 | { 31 | public PortableExecutableImageException(PortableExecutableImage image) 32 | { 33 | Image = image; 34 | } 35 | 36 | public PortableExecutableImageException(PortableExecutableImage image, string message) : base(message) 37 | { 38 | Image = image; 39 | } 40 | 41 | public PortableExecutableImageException(PortableExecutableImage image, string message, Exception innerException) : base(message, innerException) 42 | { 43 | Image = image; 44 | } 45 | 46 | #region Properties 47 | 48 | public PortableExecutableImage Image { get; } 49 | 50 | #endregion 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Workshell.PE/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System.Reflection; 24 | using System.Runtime.CompilerServices; 25 | 26 | #if !SIGNED 27 | [assembly: InternalsVisibleTo("Workshell.PE.Resources")] 28 | [assembly: InternalsVisibleTo("Workshell.PE.Tests")] 29 | #else 30 | [assembly: InternalsVisibleTo("Workshell.PE.Resources, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed0db04e6ef7cb7ae6c0dbecb36b42bc629609ae4f059d5aacd1f467be55281c480336bfd79e4c28a5304ccb6448502b5c4f5184dcf76f264ea7d2f78f6e7ab134ca12d526e2257b2ee88b8429dc7ace03ad9c21b6b2710ca2b82e770e62683382924c50f7e554402e838dd4fd90bfcc2ec730ef2cb9c9c9b9992061d37ed789")] 31 | [assembly: InternalsVisibleTo("Workshell.PE.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100ed0db04e6ef7cb7ae6c0dbecb36b42bc629609ae4f059d5aacd1f467be55281c480336bfd79e4c28a5304ccb6448502b5c4f5184dcf76f264ea7d2f78f6e7ab134ca12d526e2257b2ee88b8429dc7ace03ad9c21b6b2710ca2b82e770e62683382924c50f7e554402e838dd4fd90bfcc2ec730ef2cb9c9c9b9992061d37ed789")] 32 | #endif 33 | 34 | [assembly: AssemblyTitle("Workshell.PE")] 35 | [assembly: AssemblyDescription("A .NET class library for reading the PE executable format")] -------------------------------------------------------------------------------- /src/Workshell.PE/Supports.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | // Copyright(c) Workshell Ltd 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in all 12 | // copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | // SOFTWARE. 21 | #endregion 22 | 23 | using System; 24 | using System.Collections.Generic; 25 | using System.Text; 26 | using System.Threading.Tasks; 27 | 28 | namespace Workshell.PE 29 | { 30 | public interface ISupportsLocation 31 | { 32 | #region Properties 33 | 34 | Location Location { get; } 35 | 36 | #endregion 37 | } 38 | 39 | public interface ISupportsBytes 40 | { 41 | #region Methods 42 | 43 | byte[] GetBytes(); 44 | Task GetBytesAsync(); 45 | 46 | #endregion 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Workshell.PE/Workshell.PE.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0;net7.0;net6.0 5 | false 6 | false 7 | Workshell.snk 8 | Debug;Release;CI 9 | 10 | 11 | 12 | Workshell.PE 13 | A full featured class library for reading the Portable Executable file format covering all major sections. 14 | https://github.com/Workshell/pe 15 | http://img.workshell.co.uk/logo_128.png 16 | workshell pe executable native 17 | license.txt 18 | Workshell Ltd 19 | Workshell Ltd 20 | https://github.com/Workshell/pe 21 | git 22 | 0.0.0.1 23 | 24 | 25 | 26 | 27 | 28 | 29 | ..\..\bin\debug 30 | TRACE 31 | 32 | 33 | 34 | ..\..\bin\release 35 | TRACE 36 | 37 | 38 | 39 | ..\..\bin\ci 40 | TRACE;SIGNED 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/DOSHeaderTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using FluentAssertions; 6 | using NUnit.Framework; 7 | 8 | namespace Workshell.PE.Tests 9 | { 10 | [TestFixture] 11 | public sealed class DOSHeaderTests 12 | { 13 | [Test] 14 | public void DOSHeader_Is_Not_Null() 15 | { 16 | var file = TestingUtils.GetFileFromResources(TestingUtils.GetRandomTestFilename()); 17 | 18 | using (var image = PortableExecutableImage.FromStream(file)) 19 | { 20 | image.DOSHeader.Should().NotBeNull(); 21 | } 22 | } 23 | 24 | [TestCase("clrtest.any.dll", 0x0090)] 25 | [TestCase("clrtest.x86.dll", 0x0090)] 26 | [TestCase("clrtest.x64.dll", 0x0090)] 27 | [TestCase("nativetest.x86.dll", 0x0050)] 28 | [TestCase("nativetest.x64.dll", 0x0050)] 29 | public void Bytes_On_Last_Page_Of_File_Is_Correct(string fileName, int expectedValue) 30 | { 31 | var file = TestingUtils.GetFileFromResources(fileName); 32 | 33 | using (var image = PortableExecutableImage.FromStream(file)) 34 | { 35 | var value = image.DOSHeader.BytesOnLastPage; 36 | 37 | value.Should().Be(Convert.ToUInt16(expectedValue)); 38 | } 39 | } 40 | 41 | [TestCase("clrtest.any.dll", 0x0040)] 42 | [TestCase("clrtest.x86.dll", 0x0040)] 43 | [TestCase("clrtest.x64.dll", 0x0040)] 44 | [TestCase("nativetest.x86.dll", 0x0040)] 45 | [TestCase("nativetest.x64.dll", 0x0040)] 46 | public void File_Address_Relocation_Table_Is_Correct(string fileName, int expectedValue) 47 | { 48 | var file = TestingUtils.GetFileFromResources(fileName); 49 | 50 | using (var image = PortableExecutableImage.FromStream(file)) 51 | { 52 | var value = image.DOSHeader.FileAddressRelocationTable; 53 | 54 | value.Should().Be(Convert.ToUInt16(expectedValue)); 55 | } 56 | } 57 | 58 | [TestCase("clrtest.any.dll", 0x00000080U)] 59 | [TestCase("clrtest.x86.dll", 0x00000080U)] 60 | [TestCase("clrtest.x64.dll", 0x00000080U)] 61 | [TestCase("nativetest.x86.dll", 0x00000100U)] 62 | [TestCase("nativetest.x64.dll", 0x00000100U)] 63 | public void File_Address_New_Header_Is_Correct(string fileName, uint expectedValue) 64 | { 65 | var file = TestingUtils.GetFileFromResources(fileName); 66 | 67 | using (var image = PortableExecutableImage.FromStream(file)) 68 | { 69 | var value = image.DOSHeader.FileAddressNewHeader; 70 | 71 | value.Should().Be(expectedValue); 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/clrtest.any.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/tests/Workshell.PE.Tests/Files/clrtest.any.dll -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/clrtest.x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/tests/Workshell.PE.Tests/Files/clrtest.x64.dll -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/clrtest.x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/tests/Workshell.PE.Tests/Files/clrtest.x86.dll -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Workshell Ltd 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/nativetest.x64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/tests/Workshell.PE.Tests/Files/nativetest.x64.dll -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Files/nativetest.x86.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Workshell/pe/728ac3b74e874698dde48b1587137f2d69218534/tests/Workshell.PE.Tests/Files/nativetest.x86.dll -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/NTHeadersTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | using FluentAssertions; 6 | using NUnit.Framework; 7 | 8 | namespace Workshell.PE.Tests 9 | { 10 | [TestFixture] 11 | public sealed class NTHeadersTests 12 | { 13 | [Test] 14 | public void NTHeaders_Is_Not_Null() 15 | { 16 | var file = TestingUtils.GetFileFromResources(TestingUtils.GetRandomTestFilename()); 17 | 18 | using (var image = PortableExecutableImage.FromStream(file)) 19 | { 20 | image.NTHeaders.Should().NotBeNull(); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/SectionTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using FluentAssertions; 7 | using NUnit.Framework; 8 | 9 | namespace Workshell.PE.Tests 10 | { 11 | [TestFixture] 12 | public sealed class SectionTests 13 | { 14 | [TestCase("clrtest.any.dll")] 15 | [TestCase("clrtest.x86.dll")] 16 | [TestCase("clrtest.x64.dll")] 17 | [TestCase("nativetest.x86.dll")] 18 | [TestCase("nativetest.x64.dll")] 19 | public void Sections_Is_Not_Null(string fileName) 20 | { 21 | var file = TestingUtils.GetFileFromResources(fileName); 22 | 23 | using (var image = PortableExecutableImage.FromStream(file)) 24 | { 25 | image.Sections.Should().NotBeNull(); 26 | } 27 | } 28 | 29 | [TestCase("clrtest.any.dll")] 30 | [TestCase("clrtest.x86.dll")] 31 | [TestCase("clrtest.x64.dll")] 32 | [TestCase("nativetest.x86.dll")] 33 | [TestCase("nativetest.x64.dll")] 34 | public void Sections_Has_Expected_Count(string fileName) 35 | { 36 | var file = TestingUtils.GetFileFromResources(fileName); 37 | 38 | using (var image = PortableExecutableImage.FromStream(file)) 39 | { 40 | image.Sections.Count.Should().Be(image.SectionTable.Count); 41 | } 42 | } 43 | 44 | [TestCase("clrtest.any.dll")] 45 | [TestCase("clrtest.x86.dll")] 46 | [TestCase("clrtest.x64.dll")] 47 | [TestCase("nativetest.x86.dll")] 48 | [TestCase("nativetest.x64.dll")] 49 | public void Section_Has_Expected_Offset(string fileName) 50 | { 51 | var file = TestingUtils.GetFileFromResources(fileName); 52 | 53 | using (var image = PortableExecutableImage.FromStream(file)) 54 | { 55 | foreach (var section in image.Sections) 56 | { 57 | section.Location.FileOffset.Should().Be(section.TableEntry.PointerToRawData); 58 | } 59 | } 60 | } 61 | 62 | [TestCase("clrtest.any.dll")] 63 | [TestCase("clrtest.x86.dll")] 64 | [TestCase("clrtest.x64.dll")] 65 | [TestCase("nativetest.x86.dll")] 66 | [TestCase("nativetest.x64.dll")] 67 | public void Section_Has_Expected_Size(string fileName) 68 | { 69 | var file = TestingUtils.GetFileFromResources(fileName); 70 | 71 | using (var image = PortableExecutableImage.FromStream(file)) 72 | { 73 | foreach (var section in image.Sections) 74 | { 75 | var buffer = section.GetBytes(); 76 | 77 | buffer.LongLength.Should().Be(Convert.ToInt64(section.TableEntry.SizeOfRawData)); 78 | } 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/TestingUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Reflection; 5 | using System.Text; 6 | 7 | namespace Workshell.PE.Tests 8 | { 9 | internal static class TestingUtils 10 | { 11 | private static readonly string[] _testFilenames = new string[] 12 | { 13 | "clrtest.any.dll", 14 | "clrtest.x86.dll", 15 | "clrtest.x64.dll", 16 | "nativetest.x86.dll", 17 | "nativetest.x64.dll" 18 | }; 19 | private static readonly Random _random = new Random(); 20 | 21 | #region Methods 22 | 23 | public static Stream GetFileFromResources(string fileName) 24 | { 25 | var path = $"Workshell.PE.Tests.Files.{fileName}"; 26 | var assembly = Assembly.GetExecutingAssembly(); 27 | var stream = assembly.GetManifestResourceStream(path); 28 | 29 | return stream; 30 | } 31 | 32 | public static string GetRandomTestFilename() 33 | { 34 | var idx = _random.Next(0, _testFilenames.Length - 1); 35 | 36 | return _testFilenames[idx]; 37 | } 38 | 39 | #endregion 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Workshell.PE.Tests/Workshell.PE.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net6.0 5 | false 6 | false 7 | Workshell.snk 8 | Debug;Release;CI 9 | 10 | 11 | 12 | TRACE;SIGNED 13 | ..\..\bin\release 14 | 15 | 16 | 17 | TRACE;SIGNED 18 | ..\..\bin\ci 19 | 20 | 21 | 22 | ..\..\bin\debug 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 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 4.0.0 --------------------------------------------------------------------------------