コード例 #1
0
 public string GetAssemblyName(IMetadataScope scope)
 {
     if (scope is ModuleDefinition scopeModule)
     {
         return(scopeModule.Assembly.FullName);
     }
     if (scope is AssemblyNameReference assemblyNameReference)
     {
         return(assemblyNameReference.FullName);
     }
     else
     {
         throw new Exception($"Assembly ensure does not support scope '{scope.GetType().FullName}'");
     }
 }
コード例 #2
0
        /// <summary>
        /// Returns the full assembly name corresponding to <paramref name="scope"/>.
        /// </summary>
        public static string GetFullName(this IMetadataScope scope)
        {
            var md = scope as ModuleDefinition;

            if (md != null)
            {
                return(md.Assembly.Name.FullName);
            }

            var nr = scope as AssemblyNameReference;

            if (nr != null)
            {
                return(nr.FullName);
            }

            throw new NotSupportedException(String.Format("Unknown metadata scope type {0}",
                                                          scope.GetType().FullName));
        }
コード例 #3
0
 void EmitScope(IMetadataScope s, StringBuilder sb)
 {
     if (s is AssemblyNameReference)
     {
         AssemblyNameReference aname = (s as AssemblyNameReference);
         sb.Append("[" + EscapeName(aname.Name) + "]");
     }
     else if (s is ModuleDefinition)
     {
         if (s != main)
         {
             throw new NotImplementedException();
         }
     }
     else
     {
         throw new NotImplementedException(s.GetType().ToString());
     }
 }
コード例 #4
0
        private string GetScopeName(IMetadataScope scope)
        {
            if (scope == null)
            {
                return(String.Empty);
            }

            ModuleDefinition md = (scope as ModuleDefinition);

            if (md != null)
            {
                return(md.Name.Replace(", ", ",\\n"));
            }

            AssemblyNameReference anr = (scope as AssemblyNameReference);

            if (anr != null)
            {
                return(anr.FullName.Replace(", ", ",\\n"));
            }

            Console.WriteLine("GetScopeName {0}", scope.GetType());
            return(String.Empty);
        }
コード例 #5
0
        public static string getCanonicalizedScopeName(IMetadataScope scope)
        {
            AssemblyNameReference asmRef = null;

            switch (scope.MetadataScopeType) {
            case MetadataScopeType.AssemblyNameReference:
                asmRef = (AssemblyNameReference)scope;
                break;
            case MetadataScopeType.ModuleDefinition:
                var module = (ModuleDefinition)scope;
                if (module.Assembly != null)
                    asmRef = module.Assembly.Name;
                break;
            case MetadataScopeType.ModuleReference:
                break;
            default:
                throw new ApplicationException(string.Format("Invalid scope type: {0}", scope.GetType()));
            }

            if (asmRef != null) {
                // The version number should be ignored. Older code may reference an old version of
                // the assembly, but if the newer one has been loaded, that one is used.
                return asmRef.Name.ToLowerInvariant();
            }
            return string.Format("{0}", scope.ToString().ToLowerInvariant());
        }
コード例 #6
0
		private string GetScopeName (IMetadataScope scope)
		{
			if (scope == null)
				return String.Empty;
			
			ModuleDefinition md = (scope as ModuleDefinition);
			if (md != null)
				return md.Name.Replace (", ", ",\\n");
				
			AssemblyNameReference anr = (scope as AssemblyNameReference);
			if (anr != null)
				return anr.FullName.Replace (", ", ",\\n");
			
			Console.WriteLine ("GetScopeName {0}", scope.GetType ());
			return String.Empty;
		}
コード例 #7
0
ファイル: DotNetUtils.cs プロジェクト: ostuda/de4dot
        public static AssemblyNameReference getAssemblyNameReference(IMetadataScope scope)
        {
            if (scope is ModuleDefinition) {
                var moduleDefinition = (ModuleDefinition)scope;
                return moduleDefinition.Assembly.Name;
            }
            else if (scope is AssemblyNameReference)
                return (AssemblyNameReference)scope;

            throw new ApplicationException(string.Format("Unknown IMetadataScope type: {0}", scope.GetType()));
        }
コード例 #8
0
ファイル: ildasm.cs プロジェクト: sesef/mono
	void EmitScope (IMetadataScope s, StringBuilder sb) {
		if (s is AssemblyNameReference) {
			AssemblyNameReference aname = (s as AssemblyNameReference);
			sb.Append ("[" + EscapeName (aname.Name) + "]");
		} else if (s is ModuleDefinition) {
			if (s != main)
				throw new NotImplementedException ();
		} else {
			throw new NotImplementedException (s.GetType ().ToString ());
		}
	}
コード例 #9
0
ファイル: DefinitionsRenamer.cs プロジェクト: ostuda/de4dot
        // Returns null if it's a non-loaded module/assembly
        IEnumerable<Module> findModules(IMetadataScope scope)
        {
            if (scope is AssemblyNameReference) {
                var assemblyRef = (AssemblyNameReference)scope;
                var moduleHash = assemblyHash.lookup(assemblyRef.ToString());
                if (moduleHash != null)
                    return moduleHash.Modules;
            }
            else if (scope is ModuleDefinition) {
                var moduleDefinition = (ModuleDefinition)scope;
                var module = modulesDict.lookup(moduleDefinition.FullyQualifiedName);
                if (module != null)
                    return new List<Module> { module };
            }
            else
                throw new ApplicationException(string.Format("IMetadataScope is an unsupported type: {0}", scope.GetType()));

            return null;
        }