Ejemplo n.º 1
0
        public AssemblyNameReference(string name, Version version)
        {
            if (name == null)
                throw new ArgumentNullException ("name");

            this.name = name;
            this.version = Mixin.CheckVersion (version);
            this.hash_algorithm = AssemblyHashAlgorithm.None;
            this.token = new MetadataToken (TokenType.AssemblyRef);
        }
Ejemplo n.º 2
0
 internal AssemblyNameReference()
 {
     this.version = Mixin.ZeroVersion;
     this.token = new MetadataToken (TokenType.AssemblyRef);
 }
Ejemplo n.º 3
0
 private NamespaceDefinition(string name)
 {
     ns = name;
     MetadataToken = new MetadataToken(NamespaceTokenType, (uint)name.GetHashCode());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers metadata token to TypeRef table from metadata scope A to metadata scope B.
        /// </summary>
        /// <param name="token">Token in metadata scope A.</param>
        /// <returns>Token in metadata scope B.</returns>
        private MetadataToken registerTypeRef(MetadataToken token)
        {
            string name;
            uint scope,newToken;

            NewImporter.GetTypeRefProps(token.ToUInt32(),out name,out scope);
            MetadataToken assmToken = TranslateToken(new MetadataToken(scope));
            OldEmitter.CorMetaDataEmit.DefineTypeRefByName(assmToken.ToUInt32(),name,out newToken);
            return new MetadataToken(newToken);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Registers metadata token to TypeSpec table from metadata scope A to metadata scope B.
 /// </summary>
 /// <param name="token">Token in metadata scope A.</param>
 /// <returns>Token in metadata scope B.</returns>
 private MetadataToken registerTypeSpec(MetadataToken token)
 {
     uint nToken;
     byte[] signature = NewImporter.GetTypeSpec(token.ToUInt32());
     Signature sig = new Signature(signature);
     sig.Migrate(this);
     signature = sig.Compress();
     OldEmitter.CorMetaDataEmit.GetTokenFromTypeSpec(signature,(uint)signature.Length,out nToken);
     return new MetadataToken(nToken);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Registers any metadata token from tables
        /// (MemberRef,UserString,TypeRef,Method,TypeDef,Field,ModuleRef,AssemblyRef)
        /// from metadata scope A to metadata scope B.
        /// </summary>
        /// <param name="token">Token in metadata scope A.(new assembly)</param>
        /// <returns>Token in metadata scope B.(running assembly)</returns>
        public MetadataToken TranslateToken(MetadataToken cecToken)
        {
            uint token = cecToken.ToUInt32();
            MetadataToken new_token;
            // Look in cache first
            if(cache.TryGetValue(token,out new_token)){
                return new_token;
            }
            switch(cecToken.TokenType){
                case TokenType.MemberRef:
                    new_token = registerMemberRef(cecToken);
                    break;
                case TokenType.String:
                    {
                        uint nToken;
                        string str = NewImporter.GetUserString(token);
                        OldEmitter.CorMetaDataEmit.DefineUserString(str,(uint)str.Length,out nToken);
                        new_token = new MetadataToken(nToken);
                    }
                    break;
                case TokenType.TypeRef:
                    new_token = registerTypeRef(cecToken);
                    break;
                case TokenType.Method:
                    {
                        if(addedMethods.TryGetValue(token,out new_token)){
                            break;
                        }
                        string name;uint classTk;byte[] signature;uint attr;uint rva;uint flags;
                        NewImporter.GetMethodProps(token,out name,out classTk,out attr,out signature,out rva,out flags);
                        MetadataToken classToken = TranslateToken(new MetadataToken(classTk));
                        Signature sig = new Signature(signature);
                        sig.Migrate(this);
                        signature = sig.Compress();
                        new_token = new MetadataToken(OldImporter.FindMethod(classToken.ToUInt32(), name, signature));
                    }
                    break;
                case TokenType.Field:
                    {
                        FieldProps fProps = NewImporter.GetFieldProps(token);
                        uint newMClass = TranslateToken(new MetadataToken(fProps.mClass)).ToUInt32();
                        fProps.sigBlob = Signature.Migrate(fProps.sigBlob, this, 1);
                        //metadata.OldEmitter.CorMetaDataEmit.DefineMemberRef(newMClass,fProps.fName,fProps.sigBlob,(uint)fProps.sigBlob.Length,out new_token);
                        uint nCorToken = OldImporter.FindField(newMClass, fProps.fName, fProps.sigBlob);
                        if (nCorToken == 0) {
                            OldEmitter.CorMetaDataEmit.DefineField(newMClass,fProps.fName,fProps.pdwAttr,fProps.sigBlob,(uint)fProps.sigBlob.Length,fProps.pdwCPlusTypeFlag,fProps.ppValue,(uint)fProps.ppValue.Length,out nCorToken);
                        }
                        new_token = new MetadataToken(nCorToken);
                    }
                    break;
                case TokenType.TypeDef:
                    TypeDefProps tProps = NewImporter.GetTypeDefProps(token);
                    new_token = new MetadataToken(OldImporter.FindTypeDef(tProps.tName));
                    break;
                case TokenType.ModuleRef:
                    {
                        uint nToken;
                        string name = NewImporter.GetModuleRefProps(token);
                        OldEmitter.CorMetaDataEmit.DefineModuleRef(name,out nToken);
                        new_token = new MetadataToken(nToken);
                    }
                    break;
                case TokenType.AssemblyRef:
                    {
                        int index = manager.ResourceManager.NewAssembly.Modules[0].AssemblyReferences.FindIndex(delegate(AssemblyNameReference asmRef){
                            return (asmRef.MetadataToken.ToUInt32() == token);
                        });
                        string scopeName = manager.ResourceManager.NewAssembly.Modules[0].AssemblyReferences[index].FullName;

                        index = manager.ResourceManager.OldAssembly.Modules[0].AssemblyReferences.FindIndex(delegate(AssemblyNameReference asmRef){
                            return (asmRef.FullName == scopeName);
                        });
                        if(index == -1){
                            throw new TranslatingException("Assembly reference not found, maybe it wasn't in used in original version");
                        } else {
                            new_token = manager.ResourceManager.OldAssembly.Modules[0].AssemblyReferences[index].MetadataToken;
                        }
                    }
                    break;
                case TokenType.TypeSpec:
                    new_token = registerTypeSpec(cecToken);
                    break;
                case TokenType.MethodSpec:
                    uint new_token_cor;
                    MethodSpecProps props = newImporter.GetMethodSpecProps(token);
                    props.tkParent = TranslateToken(new MetadataToken(props.tkParent)).ToUInt32();
                    props.signature = Signature.Migrate(props.signature,this);
                    OldEmitter.CorMetaDataEmit.DefineMethodSpec(props.tkParent,props.signature,(uint)props.signature.Length,out new_token_cor);
                    new_token = new MetadataToken(new_token_cor);
                    break;
                case TokenType.Property:
                default:
                    throw new NotImplementedException();

            }
            // Add to cache
            cache.Add(token,new_token);
            return new_token;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Registers metadata token to MemberRef table from metadata scope A to metadata scope B.
        /// </summary>
        /// <param name="token">Token in metadata scope A.</param>
        /// <returns>Token in metadata scope B.</returns>
        private MetadataToken registerMemberRef(MetadataToken token)
        {
            string name;
            byte[] sig;
            uint ptk,nToken;

            NewImporter.GetMemberRefProps(token.ToUInt32(),out name,out ptk,out sig);
            MetadataToken scope = TranslateToken(new MetadataToken(ptk));
            Signature signa = new Signature(sig);
            signa.Migrate(this);
            sig = signa.Compress();
            OldEmitter.CorMetaDataEmit.DefineMemberRef(scope.ToUInt32(),name,sig,(uint)sig.Length,out nToken);
            return new MetadataToken(nToken);
        }
Ejemplo n.º 8
0
 public MemberID(string assemblyName, string moduleName, MetadataToken token)
 {
     AssemblyQualifiedTypeName = assemblyName;
       ModuleName = moduleName;
       Token = token.ToInt32();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Used to be able to reference methods created in this round from code changed also in the same round. Must not be in cache,
 /// because it can be cleared.
 /// </summary>
 /// <param name="newToken">Token in new assembly.</param>
 /// <param name="registeredToken">Token in running assembly.</param>
 public void RegisterNewMethod(MetadataToken newToken, MetadataToken registeredToken)
 {
     addedMethods.Add(newToken.ToUInt32(),registeredToken);
 }
Ejemplo n.º 10
0
        public static uint CompressMetadataToken(this CodedIndex self, MetadataToken token)
        {
            uint ret = 0;

            if (token.RID == 0)
            {
                return(ret);
            }
            switch (self)
            {
            case CodedIndex.TypeDefOrRef:
                ret = token.RID << 2;
                switch (token.TokenType)
                {
                case TokenType.TypeDef:
                    return(ret | 0);

                case TokenType.TypeRef:
                    return(ret | 1);

                case TokenType.TypeSpec:
                    return(ret | 2);

                default:
                    goto exit;
                }

            case CodedIndex.HasConstant:
                ret = token.RID << 2;
                switch (token.TokenType)
                {
                case TokenType.Field:
                    return(ret | 0);

                case TokenType.Param:
                    return(ret | 1);

                case TokenType.Property:
                    return(ret | 2);

                default:
                    goto exit;
                }

            case CodedIndex.HasCustomAttribute:
                ret = token.RID << 5;
                switch (token.TokenType)
                {
                case TokenType.Method:
                    return(ret | 0);

                case TokenType.Field:
                    return(ret | 1);

                case TokenType.TypeRef:
                    return(ret | 2);

                case TokenType.TypeDef:
                    return(ret | 3);

                case TokenType.Param:
                    return(ret | 4);

                case TokenType.InterfaceImpl:
                    return(ret | 5);

                case TokenType.MemberRef:
                    return(ret | 6);

                case TokenType.Module:
                    return(ret | 7);

                case TokenType.Permission:
                    return(ret | 8);

                case TokenType.Property:
                    return(ret | 9);

                case TokenType.Event:
                    return(ret | 10);

                case TokenType.Signature:
                    return(ret | 11);

                case TokenType.ModuleRef:
                    return(ret | 12);

                case TokenType.TypeSpec:
                    return(ret | 13);

                case TokenType.Assembly:
                    return(ret | 14);

                case TokenType.AssemblyRef:
                    return(ret | 15);

                case TokenType.File:
                    return(ret | 16);

                case TokenType.ExportedType:
                    return(ret | 17);

                case TokenType.ManifestResource:
                    return(ret | 18);

                case TokenType.GenericParam:
                    return(ret | 19);

                case TokenType.GenericParamConstraint:
                    return(ret | 20);

                case TokenType.MethodSpec:
                    return(ret | 21);

                default:
                    goto exit;
                }

            case CodedIndex.HasFieldMarshal:
                ret = token.RID << 1;
                switch (token.TokenType)
                {
                case TokenType.Field:
                    return(ret | 0);

                case TokenType.Param:
                    return(ret | 1);

                default:
                    goto exit;
                }

            case CodedIndex.HasDeclSecurity:
                ret = token.RID << 2;
                switch (token.TokenType)
                {
                case TokenType.TypeDef:
                    return(ret | 0);

                case TokenType.Method:
                    return(ret | 1);

                case TokenType.Assembly:
                    return(ret | 2);

                default:
                    goto exit;
                }

            case CodedIndex.MemberRefParent:
                ret = token.RID << 3;
                switch (token.TokenType)
                {
                case TokenType.TypeDef:
                    return(ret | 0);

                case TokenType.TypeRef:
                    return(ret | 1);

                case TokenType.ModuleRef:
                    return(ret | 2);

                case TokenType.Method:
                    return(ret | 3);

                case TokenType.TypeSpec:
                    return(ret | 4);

                default:
                    goto exit;
                }

            case CodedIndex.HasSemantics:
                ret = token.RID << 1;
                switch (token.TokenType)
                {
                case TokenType.Event:
                    return(ret | 0);

                case TokenType.Property:
                    return(ret | 1);

                default:
                    goto exit;
                }

            case CodedIndex.MethodDefOrRef:
                ret = token.RID << 1;
                switch (token.TokenType)
                {
                case TokenType.Method:
                    return(ret | 0);

                case TokenType.MemberRef:
                    return(ret | 1);

                default:
                    goto exit;
                }

            case CodedIndex.MemberForwarded:
                ret = token.RID << 1;
                switch (token.TokenType)
                {
                case TokenType.Field:
                    return(ret | 0);

                case TokenType.Method:
                    return(ret | 1);

                default:
                    goto exit;
                }

            case CodedIndex.Implementation:
                ret = token.RID << 2;
                switch (token.TokenType)
                {
                case TokenType.File:
                    return(ret | 0);

                case TokenType.AssemblyRef:
                    return(ret | 1);

                case TokenType.ExportedType:
                    return(ret | 2);

                default:
                    goto exit;
                }

            case CodedIndex.CustomAttributeType:
                ret = token.RID << 3;
                switch (token.TokenType)
                {
                case TokenType.Method:
                    return(ret | 2);

                case TokenType.MemberRef:
                    return(ret | 3);

                default:
                    goto exit;
                }

            case CodedIndex.ResolutionScope:
                ret = token.RID << 2;
                switch (token.TokenType)
                {
                case TokenType.Module:
                    return(ret | 0);

                case TokenType.ModuleRef:
                    return(ret | 1);

                case TokenType.AssemblyRef:
                    return(ret | 2);

                case TokenType.TypeRef:
                    return(ret | 3);

                default:
                    goto exit;
                }

            case CodedIndex.TypeOrMethodDef:
                ret = token.RID << 1;
                switch (token.TokenType)
                {
                case TokenType.TypeDef:
                    return(ret | 0);

                case TokenType.Method:
                    return(ret | 1);

                default:
                    goto exit;
                }

            default:
                goto exit;
            }
exit:
            throw new ArgumentException();
        }
Ejemplo n.º 11
0
 public IMetadataTokenProvider LookupToken(MetadataToken token)
 {
     return(Read(token, (MetadataToken t, MetadataReader reader) => reader.LookupToken(t)));
 }
 internal AssemblyNameReference()
 {
     this.version = Mixin.ZeroVersion;
     this.token   = new MetadataToken(TokenType.AssemblyRef);
 }
Ejemplo n.º 13
0
 public IMetadataTokenProvider LookupByToken(MetadataToken token)
 {
     return(m_controller.Reader.LookupByToken(token));
 }
Ejemplo n.º 14
0
 private TypeReference GetTypeDefOrRef(MetadataToken token) =>
 this.reader.GetTypeDefOrRef(token);
Ejemplo n.º 15
0
        public void WriteSequencePoints(MethodDebugInformation info)
        {
            int num  = -1;
            int num2 = -1;

            base.WriteCompressedUInt32(info.local_var_token.RID);
            if (!info.TryGetUniqueDocument(out Document document))
            {
                document = null;
            }
            for (int i = 0; i < info.SequencePoints.Count; i++)
            {
                SequencePoint sequencePoint = info.SequencePoints[i];
                Document      document2     = sequencePoint.Document;
                if (document != document2)
                {
                    MetadataToken documentToken = metadata.GetDocumentToken(document2);
                    if (document != null)
                    {
                        base.WriteCompressedUInt32(0u);
                    }
                    base.WriteCompressedUInt32(documentToken.RID);
                    document = document2;
                }
                if (i > 0)
                {
                    base.WriteCompressedUInt32((uint)(sequencePoint.Offset - info.SequencePoints[i - 1].Offset));
                }
                else
                {
                    base.WriteCompressedUInt32((uint)sequencePoint.Offset);
                }
                if (sequencePoint.IsHidden)
                {
                    base.WriteInt16(0);
                }
                else
                {
                    int num3  = sequencePoint.EndLine - sequencePoint.StartLine;
                    int value = sequencePoint.EndColumn - sequencePoint.StartColumn;
                    base.WriteCompressedUInt32((uint)num3);
                    if (num3 == 0)
                    {
                        base.WriteCompressedUInt32((uint)value);
                    }
                    else
                    {
                        base.WriteCompressedInt32(value);
                    }
                    if (num < 0)
                    {
                        base.WriteCompressedUInt32((uint)sequencePoint.StartLine);
                        base.WriteCompressedUInt32((uint)sequencePoint.StartColumn);
                    }
                    else
                    {
                        base.WriteCompressedInt32(sequencePoint.StartLine - num);
                        base.WriteCompressedInt32(sequencePoint.StartColumn - num2);
                    }
                    num  = sequencePoint.StartLine;
                    num2 = sequencePoint.StartColumn;
                }
            }
        }
Ejemplo n.º 16
0
        public MethodProps GetMethodProps(uint token)
        {
            MethodProps props = new MethodProps();
            props.mToken = token;

            GetMethodProps(token,out props.mName,out props.pClass,out props.pdwAttr,out props.ppvSigBlob,
                           out props.pulCodeRVA,out props.pdwImplFlags);

            MetadataToken mToken = new MetadataToken(props.pClass);
            if(mToken.TokenType == TokenType.TypeDef){
                TypeDefProps tdProps = GetTypeDefProps(props.pClass);
                props.parentProps = tdProps;
            }
            return props;
        }