From 197de5908904af9313a73fcc0f239106b7621916 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 9 Nov 2022 19:09:30 -0800 Subject: [PATCH] Add PE assembly manifest deserialization --- BurnOutSharp.Builder/Extensions.cs | 23 ++ .../PortableExecutable/AssemblyManifest.cs | 306 ++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 BurnOutSharp.Models/PortableExecutable/AssemblyManifest.cs diff --git a/BurnOutSharp.Builder/Extensions.cs b/BurnOutSharp.Builder/Extensions.cs index 9f8690e5..7836b558 100644 --- a/BurnOutSharp.Builder/Extensions.cs +++ b/BurnOutSharp.Builder/Extensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; +using System.Xml.Serialization; namespace BurnOutSharp.Builder { @@ -418,6 +419,28 @@ namespace BurnOutSharp.Builder return table; } + /// + /// Read resource data as a side-by-side assembly manifest + /// + /// Resource data entry to parse into a side-by-side assembly manifest + /// A filled side-by-side assembly manifest on success, null on error + public static Models.PortableExecutable.AssemblyManifest AsAssemblyManifest(this Models.PortableExecutable.ResourceDataEntry entry) + { + // If we have an invalid entry, just skip + if (entry?.Data == null) + return null; + + try + { + XmlSerializer serializer = new XmlSerializer(typeof(Models.PortableExecutable.AssemblyManifest)); + return serializer.Deserialize(new MemoryStream(entry.Data)) as Models.PortableExecutable.AssemblyManifest; + } + catch + { + return null; + } + } + /// /// Read resource data as a string table resource /// diff --git a/BurnOutSharp.Models/PortableExecutable/AssemblyManifest.cs b/BurnOutSharp.Models/PortableExecutable/AssemblyManifest.cs new file mode 100644 index 00000000..8f526415 --- /dev/null +++ b/BurnOutSharp.Models/PortableExecutable/AssemblyManifest.cs @@ -0,0 +1,306 @@ +using System.Xml.Serialization; + +namespace BurnOutSharp.Models.PortableExecutable +{ + /// + [XmlRoot(ElementName = "assembly", Namespace = "urn:schemas-microsoft-com:asm.v1")] + public class AssemblyManifest + { + [XmlAttribute("manifestVersion")] + public string ManifestVersion; + + #region Group + + [XmlElement("assemblyIdentity")] + public AssemblyIdentity[] AssemblyIdentities; + + [XmlElement("noInheritable")] + public AssemblyNoInheritable[] NoInheritables; + + #endregion + + #region Group + + [XmlElement("description")] + public AssemblyDescription Description; + + [XmlElement("noInherit")] + public AssemblyNoInherit NoInherit; + + //[XmlElement("noInheritable")] + //public AssemblyNoInheritable NoInheritable; + + [XmlElement("comInterfaceExternalProxyStub")] + public AssemblyCOMInterfaceExternalProxyStub[] COMInterfaceExternalProxyStub; + + [XmlElement("dependency")] + public AssemblyDependency[] Dependency; + + [XmlElement("file")] + public AssemblyFile[] File; + + [XmlElement("clrClass")] + public AssemblyCommonLanguageRuntimeClass[] CLRClass; + + [XmlElement("clrSurrogate")] + public AssemblyCommonLanguageSurrogateClass[] CLRSurrogate; + + #endregion + + [XmlAnyElement] + public object[] EverythingElse; + } + + /// + public class AssemblyBindingRedirect + { + [XmlAttribute("oldVersion")] + public string OldVersion; + + [XmlAttribute("newVersion")] + public string NewVersion; + } + + /// + public class AssemblyCOMClass + { + [XmlAttribute("clsid")] + public string CLSID; + + [XmlAttribute("threadingModel")] + public string ThreadingModel; + + [XmlAttribute("progid")] + public string Progid; + + [XmlAttribute("tlbid")] + public string TLBID; + + [XmlAttribute("description")] + public string Description; + + [XmlElement("progid")] + public AssemblyProgID[] ProgIDs; + } + + /// + public class AssemblyCOMInterfaceExternalProxyStub + { + [XmlAttribute("iid")] + public string IID; + + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("tlbid")] + public string TLBID; + + [XmlAttribute("numMethods")] + public string NumMethods; + + [XmlAttribute("proxyStubClsid32")] + public string ProxyStubClsid32; + + [XmlAttribute("baseInterface")] + public string BaseInterface; + } + + /// + public class AssemblyCOMInterfaceProxyStub + { + [XmlAttribute("iid")] + public string IID; + + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("tlbid")] + public string TLBID; + + [XmlAttribute("numMethods")] + public string NumMethods; + + [XmlAttribute("proxyStubClsid32")] + public string ProxyStubClsid32; + + [XmlAttribute("baseInterface")] + public string BaseInterface; + } + + /// + public class AssemblyCommonLanguageRuntimeClass + { + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("clsid")] + public string CLSID; + + [XmlAttribute("progid")] + public string ProgID; + + [XmlAttribute("tlbid")] + public string TLBID; + + [XmlAttribute("description")] + public string Description; + + [XmlAttribute("runtimeVersion")] + public string RuntimeVersion; + + [XmlAttribute("threadingModel")] + public string ThreadingModel; + + [XmlElement("progid")] + public AssemblyProgID[] ProgIDs; + } + + /// + public class AssemblyCommonLanguageSurrogateClass + { + [XmlAttribute("clsid")] + public string CLSID; + + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("runtimeVersion")] + public string RuntimeVersion; + } + + /// + public class AssemblyDependency + { + [XmlElement("dependentAssembly")] + public AssemblyDependentAssembly DependentAssembly; + + [XmlAttribute("optional")] + public string Optional; + } + + /// + public class AssemblyDependentAssembly + { + [XmlElement("assemblyIdentity")] + public AssemblyIdentity AssemblyIdentity; + + [XmlElement("bindingRedirect")] + public AssemblyBindingRedirect[] BindingRedirect; + } + + /// + public class AssemblyDescription + { + [XmlText] + public string Value; + } + + /// + public class AssemblyFile + { + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("hash")] + public string Hash; + + [XmlAttribute("hashalg")] + public string HashAlgorithm; + + [XmlAttribute("size")] + public string Size; + + #region Group + + [XmlElement("comClass")] + public AssemblyCOMClass[] COMClass; + + [XmlElement("comInterfaceProxyStub")] + public AssemblyCOMInterfaceProxyStub[] COMInterfaceProxyStub; + + [XmlElement("typelib")] + public AssemblyTypeLib[] Typelib; + + [XmlElement("windowClass")] + public AssemblyWindowClass[] WindowClass; + + #endregion + } + + /// + public class AssemblyIdentity + { + [XmlAttribute("name")] + public string Name; + + [XmlAttribute("version")] + public string Version; + + [XmlAttribute("type")] + public string Type; + + [XmlAttribute("processorArchitecture")] + public string ProcessorArchitecture; + + [XmlAttribute("publicKeyToken")] + public string PublicKeyToken; + + [XmlAttribute("language")] + public string Language; + } + + /// + public class AssemblyNoInherit + { + } + + /// + public class AssemblyNoInheritable + { + } + + /// + public class AssemblyProgID + { + [XmlText] + public string Value; + } + + /// + public class AssemblySupportedOS + { + [XmlAttribute("Id")] + public string Id; + } + + /// + public class AssemblyTypeLib + { + [XmlElement("tlbid")] + public string TLBID; + + [XmlElement("version")] + public string Version; + + [XmlElement("helpdir")] + public string HelpDir; + + [XmlElement("resourceid")] + public string ResourceID; + + [XmlElement("flags")] + public string Flags; + } + + /// + public class AssemblyWindowClass + { + [XmlText] + public string Value; + + [XmlAttribute("versioned")] + public string Versioned; + } + + // TODO: Left off at +}