Beispiel #1
0
        private unsafe InternalManifestResourceInfo GetInternalManifestResourceInfo(string resourceName)
        {
            InternalManifestResourceInfo     result            = new InternalManifestResourceInfo();
            ManifestResourceHandleCollection manifestResources = MetadataReader.ManifestResources;

            foreach (var resourceHandle in manifestResources)
            {
                ManifestResource resource = MetadataReader.GetManifestResource(resourceHandle);
                if (MetadataReader.StringComparer.Equals(resource.Name, resourceName))
                {
                    result.Found = true;
                    if (resource.Implementation.IsNil)
                    {
                        checked
                        {
                            // Embedded data resource
                            result.ResourceLocation = ResourceLocation.Embedded | ResourceLocation.ContainedInManifestFile;
                            PEReader pe = PEReader;

                            PEMemoryBlock resourceDirectory = pe.GetSectionData(pe.PEHeaders.CorHeader.ResourcesDirectory.RelativeVirtualAddress);
                            BlobReader    reader            = resourceDirectory.GetReader((int)resource.Offset, resourceDirectory.Length - (int)resource.Offset);
                            uint          length            = reader.ReadUInt32();
                            result.PointerToResource = reader.CurrentPointer;

                            // Length check the size of the resource to ensure it fits in the PE file section, note, this is only safe as its in a checked region
                            if (length + sizeof(Int32) > reader.Length)
                            {
                                throw new BadImageFormatException();
                            }
                            result.SizeOfResource = length;
                        }
                    }
                    else
                    {
                        if (resource.Implementation.Kind == HandleKind.AssemblyFile)
                        {
                            // Get file name
                            result.ResourceLocation = default(ResourceLocation);
                            AssemblyFile file = MetadataReader.GetAssemblyFile((AssemblyFileHandle)resource.Implementation);
                            if (file.ContainsMetadata)
                            {
                                result.ResourceLocation = ResourceLocation.Embedded;
                                throw new PlatformNotSupportedException(); // Support for multi-module assemblies is not implemented on this platform
                            }
                            result.FileName = MetadataReader.GetString(file.Name);
                        }
                        else if (resource.Implementation.Kind == HandleKind.AssemblyReference)
                        {
                            // Resolve assembly reference
                            result.ResourceLocation = ResourceLocation.ContainedInAnotherAssembly;
                            RuntimeAssemblyName destinationAssemblyName = ((AssemblyReferenceHandle)resource.Implementation).ToRuntimeAssemblyName(MetadataReader);
                            result.ReferencedAssembly = RuntimeAssembly.GetRuntimeAssemblyIfExists(destinationAssemblyName);
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #2
0
 public FileEntry(PEFile module, AssemblyFileHandle handle)
 {
     this.metadataOffset = module.Reader.PEHeaders.MetadataStartOffset;
     this.module         = module;
     this.metadata       = module.Metadata;
     this.handle         = handle;
     this.assemblyFile   = metadata.GetAssemblyFile(handle);
 }
        private Mapping <AssemblyFileHandle> MapAssemblyFileImpl(AssemblyFileHandle handle)
        {
            AssemblyFile assemblyFile = _sourceMetadata.GetAssemblyFile(handle);
            string       name         = _sourceMetadata.GetString(assemblyFile.Name);

            foreach (var targetHandle in _targetMetadata.AssemblyFiles)
            {
                AssemblyFile target = _targetMetadata.GetAssemblyFile(targetHandle);
                if (!_targetMetadata.StringComparer.Equals(target.Name, name))
                {
                    continue;
                }

                return(new Mapping <AssemblyFileHandle>(targetHandle));
            }

            return(new Mapping <AssemblyFileHandle>());
        }
        private void WriteFile()
        {
            AddHeader(
                "Name",
                "Metadata",
                "HashValue"
                );

            foreach (var handle in reader.AssemblyFiles)
            {
                var entry = reader.GetAssemblyFile(handle);

                AddRow(
                    Literal(entry.Name),
                    entry.ContainsMetadata ? "Yes" : "No",
                    Literal(entry.HashValue)
                    );
            }

            WriteRows("File (0x26):");
        }
Beispiel #5
0
        public ModuleReferenceTreeNode(AssemblyTreeNode parentAssembly, ModuleReferenceHandle r, MetadataReader module)
        {
            this.parentAssembly = parentAssembly ?? throw new ArgumentNullException(nameof(parentAssembly));
            if (r.IsNil)
            {
                throw new ArgumentNullException(nameof(r));
            }
            this.metadata   = module;
            this.handle     = r;
            this.reference  = module.GetModuleReference(r);
            this.moduleName = metadata.GetString(reference.Name);

            foreach (var h in module.AssemblyFiles)
            {
                var file = module.GetAssemblyFile(h);
                if (module.StringComparer.Equals(file.Name, moduleName))
                {
                    this.file             = file;
                    this.fileHandle       = h;
                    this.containsMetadata = file.ContainsMetadata;
                    break;
                }
            }
        }
Beispiel #6
0
 public static string ToString(this MetadataReader reader, AssemblyFileHandle x) => reader.ToString(reader.GetAssemblyFile(x));
Beispiel #7
0
 // So code can be written in a way that flows from left to right...
 public static AssemblyFile GetAssemblyFile(this AssemblyFileHandle handle, MetadataReader reader) => reader.GetAssemblyFile(handle);