Example #1
0
        internal static AssemblyReference LoadDef(Module module)
        {
            var image = module.Image;

            var assemblyRef = image.AssemblyDefSignature;

            if (assemblyRef == null)
            {
                return(assemblyRef);
            }

            AssemblyRow row;

            image.GetAssembly(1, out row);

            assemblyRef          = new AssemblyReference();
            assemblyRef._name    = image.GetString(row.Name);
            assemblyRef._culture = image.GetString(row.Locale);
            assemblyRef._processorArchitecture = (ProcessorArchitecture)((int)(row.Flags & AssemblyFlags.PA_Mask) >> (int)AssemblyFlags.PA_Shift);
            assemblyRef._version = new Version(row.MajorVersion, row.MinorVersion, row.BuildNumber, row.RevisionNumber);

            var publicKey = image.GetBlob(row.PublicKey);

            if (publicKey != null && publicKey.Length > 0)
            {
                assemblyRef._publicKeyToken = StrongNameUtils.CreateTokenFromPublicKey(publicKey);
            }

            module.AddSignature(ref assemblyRef);
            image.AssemblyDefSignature = assemblyRef;

            return(assemblyRef);
        }
Example #2
0
        internal static AssemblyReference LoadRef(Module module, int rid)
        {
            var image = module.Image;

            var assemblyRef = image.AssemblyRefSignatures[rid - 1];

            if (assemblyRef != null)
            {
                return(assemblyRef);
            }

            AssemblyRefRow row;

            image.GetAssemblyRef(rid, out row);

            assemblyRef          = new AssemblyReference();
            assemblyRef._name    = image.GetString(row.Name);
            assemblyRef._culture = image.GetString(row.Locale);
            assemblyRef._processorArchitecture = (ProcessorArchitecture)((int)(row.Flags & AssemblyFlags.PA_Mask) >> (int)AssemblyFlags.PA_Shift);
            assemblyRef._version = new Version(row.MajorVersion, row.MinorVersion, row.BuildNumber, row.RevisionNumber);

            byte[] publicKeyToken = image.GetBlob(row.PublicKeyOrToken).NullIfEmpty();
            if ((row.Flags & AssemblyFlags.PublicKey) == AssemblyFlags.PublicKey &&
                publicKeyToken != null && publicKeyToken.Length > 0)
            {
                try
                {
                    publicKeyToken = StrongNameUtils.CreateTokenFromPublicKey(publicKeyToken);
                }
                catch (InvalidOperationException)
                {
                    publicKeyToken = null;
                }
            }

            assemblyRef._publicKeyToken = publicKeyToken;

            module.AddSignature(ref assemblyRef);
            image.AssemblyRefSignatures[rid - 1] = assemblyRef;

            return(assemblyRef);
        }
Example #3
0
        public static AssemblyReference GetAssemblyName(PEImage pe)
        {
            var metadata = MemoryMappedMetadata.Load(pe);

            AssemblyRow row;

            metadata.GetAssembly(1, out row);

            var assemblyRef = new AssemblyReference();

            assemblyRef._name    = metadata.GetString(row.Name);
            assemblyRef._culture = metadata.GetString(row.Locale);
            assemblyRef._processorArchitecture = (ProcessorArchitecture)((int)(row.Flags & AssemblyFlags.PA_Mask) >> (int)AssemblyFlags.PA_Shift);
            assemblyRef._version = new Version(row.MajorVersion, row.MinorVersion, row.BuildNumber, row.RevisionNumber);

            var publicKey = metadata.GetBlob(row.PublicKey);

            if (publicKey != null && publicKey.Length > 0)
            {
                assemblyRef._publicKeyToken = StrongNameUtils.CreateTokenFromPublicKey(publicKey);
            }

            return(assemblyRef);
        }