예제 #1
0
        /*^
         #pragma warning disable 2669
         * ^*/

        /// <summary>
        /// Allocates a factory for loading assemblies and modules persisted as portable executable (pe) files.
        /// </summary>
        /// <param name="metadataReaderHost">
        /// The host is used for providing access to pe files (OpenBinaryDocument),
        /// applying host specific unification policies (UnifyAssembly, UnifyAssemblyReference, UnifyModuleReference) and for deciding
        /// whether and how to load referenced assemblies and modules (ResolvingAssemblyReference, ResolvingModuleReference).
        /// </param>
        public PeReader(
            IMetadataReaderHost metadataReaderHost
            )
        {
            this.ErrorsReporter     = new MetadataReaderErrorsReporter();
            this.metadataReaderHost = metadataReaderHost;
            _internedIdToModuleMap  = new Hashtable <Module>();
            INameTable nameTable = metadataReaderHost.NameTable;

            this.value__               = nameTable.GetNameFor("value__");
            this.AsyncCallback         = nameTable.GetNameFor("AsyncCallback");
            this.ParamArrayAttribute   = nameTable.GetNameFor("ParamArrayAttribute");
            this.IAsyncResult          = nameTable.GetNameFor("IAsyncResult");
            this.ICloneable            = nameTable.GetNameFor("ICloneable");
            this.RuntimeArgumentHandle = nameTable.GetNameFor("RuntimeArgumentHandle");
            this.RuntimeFieldHandle    = nameTable.GetNameFor("RuntimeFieldHandle");
            this.RuntimeMethodHandle   = nameTable.GetNameFor("RuntimeMethodHandle");
            this.RuntimeTypeHandle     = nameTable.GetNameFor("RuntimeTypeHandle");
            this.ArgIterator           = nameTable.GetNameFor("ArgIterator");
            this.IList        = nameTable.GetNameFor("IList");
            this.IEnumerable  = nameTable.GetNameFor("IEnumerable");
            this.IList1       = nameTable.GetNameFor("IList`1");
            this.ICollection1 = nameTable.GetNameFor("ICollection`1");
            this.IEnumerable1 = nameTable.GetNameFor("IEnumerable`1");
            this.Mscorlib     = nameTable.GetNameFor("mscorlib");
            this.System_Collections_Generic = nameTable.GetNameFor("System.Collections.Generic");
            this._Deleted_ = nameTable.GetNameFor("_Deleted*");
            this._Module_  = nameTable.GetNameFor("<Module>");
        }
예제 #2
0
        public IModule CompileModuleFromCode(string code, IMetadataReaderHost host)
        {
            // CoreAssembly = Host.LoadAssembly(Host.CoreAssemblySymbolicIdentity);

            var tree = SyntaxTree.ParseText(code);

            var comp = Compilation.Create("MyCompilation",
                new CompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                .AddSyntaxTrees(tree)
                .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location));

            var outputFileName = Path.GetTempFileName();//Path.Combine(Path.GeGetTempPath(), "MyCompilation.lib");
            var ilStream = new FileStream(outputFileName, FileMode.OpenOrCreate);

            var result = comp.Emit(ilStream);
            ilStream.Close();
            if (!result.Success)
            {
                var aggregate = result.Diagnostics.Select(a => a.Info.GetMessage()).Aggregate((a, b) => a + "\n" + b);
                throw new InvalidProgramException(aggregate);
            }
            //using (var host = new PeReader.DefaultHost())
               // {
                var module = host.LoadUnitFrom(outputFileName) as IModule;
                if (module == null || module == Dummy.Module || module == Dummy.Assembly)
                {
                    throw new InvalidOperationException(outputFileName + " is not a PE file containing a CLR module or assembly.");
                }

                return Decompiler.GetCodeModelFromMetadataModel(host, module, null);

              //  }
        }
예제 #3
0
        public IModule CompileModuleFromCode(string code, IMetadataReaderHost host)
        {
            // CoreAssembly = Host.LoadAssembly(Host.CoreAssemblySymbolicIdentity);

            var tree = SyntaxTree.ParseText(code);

            var comp = Compilation.Create("MyCompilation",
                                          new CompilationOptions(OutputKind.DynamicallyLinkedLibrary))
                       .AddSyntaxTrees(tree)
                       .AddReferences(new MetadataFileReference(typeof(object).Assembly.Location));

            var outputFileName = Path.GetTempFileName();//Path.Combine(Path.GeGetTempPath(), "MyCompilation.lib");
            var ilStream       = new FileStream(outputFileName, FileMode.OpenOrCreate);

            var result = comp.Emit(ilStream);

            ilStream.Close();
            if (!result.Success)
            {
                var aggregate = result.Diagnostics.Select(a => a.Info.GetMessage()).Aggregate((a, b) => a + "\n" + b);
                throw new InvalidProgramException(aggregate);
            }
            //using (var host = new PeReader.DefaultHost())
            // {
            var module = host.LoadUnitFrom(outputFileName) as IModule;

            if (module == null || module == Dummy.Module || module == Dummy.Assembly)
            {
                throw new InvalidOperationException(outputFileName + " is not a PE file containing a CLR module or assembly.");
            }

            return(Decompiler.GetCodeModelFromMetadataModel(host, module, null));

            //  }
        }
예제 #4
0
        public ApiTraverser(IMetadataReaderHost host, IAssembly assembly)
        {
            if (host == null)
                throw new ArgumentNullException("ContractAwareHost arg should not be null.");

            _host = host;
            _assembly = new AssemblyApi(assembly);
        }
예제 #5
0
        public ApiTraverser(IMetadataReaderHost host, IAssembly assembly)
        {
            if (host == null)
            {
                throw new ArgumentNullException("ContractAwareHost arg should not be null.");
            }

            _host     = host;
            _assembly = new AssemblyApi(assembly);
        }
예제 #6
0
        internal ClassHierarchy(IEnumerable <ITypeDefinition> allTypes, IMetadataReaderHost host)
        {
            this.host = host;

            foreach (ITypeDefinition typeDefinition in allTypes)
            {
                Contract.Assert(GarbageCollectHelper.TypeDefinitionIsUnspecialized(typeDefinition));

                foreach (ITypeDefinition superType in GarbageCollectHelper.BaseClasses(typeDefinition))
                {
                    NoteClassIsSubClassOfClass(typeDefinition, GarbageCollectHelper.UnspecializeAndResolveTypeReference(superType));
                }

                // We treat every interface type as a subtype of System.Object
                if (typeDefinition.IsInterface)
                {
                    //NoteClassIsSubClassOfClass(instantiatedSubType, host.PlatformType.SystemObject.ResolvedType);
                    NoteClassIsSubClassOfClass(typeDefinition, host.PlatformType.SystemObject.ResolvedType);
                }
            }
        }
예제 #7
0
 /*^
 #pragma warning disable 2669
 ^*/
 /// <summary>
 /// Allocates a factory for loading assemblies and modules persisted as portable executable (pe) files.
 /// </summary>
 /// <param name="metadataReaderHost">
 /// The host is used for providing access to pe files (OpenBinaryDocument),
 /// applying host specific unification policies (UnifyAssembly, UnifyAssemblyReference, UnifyModuleReference) and for deciding
 /// whether and how to load referenced assemblies and modules (ResolvingAssemblyReference, ResolvingModuleReference).    
 /// </param>
 public PeReader(
   IMetadataReaderHost metadataReaderHost
 ) {
   this.ErrorsReporter = new MetadataReaderErrorsReporter();
   this.metadataReaderHost = metadataReaderHost;
   this.InternedIdToModuleMap = new Hashtable<Module>();
   INameTable nameTable = metadataReaderHost.NameTable;
   this.Value__ = nameTable.GetNameFor("value__");
   this.AsyncCallback = nameTable.GetNameFor("AsyncCallback");
   this.ParamArrayAttribute = nameTable.GetNameFor("ParamArrayAttribute");
   this.IAsyncResult = nameTable.GetNameFor("IAsyncResult");
   this.ICloneable = nameTable.GetNameFor("ICloneable");
   this.RuntimeArgumentHandle = nameTable.GetNameFor("RuntimeArgumentHandle");
   this.RuntimeFieldHandle = nameTable.GetNameFor("RuntimeFieldHandle");
   this.RuntimeMethodHandle = nameTable.GetNameFor("RuntimeMethodHandle");
   this.RuntimeTypeHandle = nameTable.GetNameFor("RuntimeTypeHandle");
   this.ArgIterator = nameTable.GetNameFor("ArgIterator");
   this.IList = nameTable.GetNameFor("IList");
   this.Mscorlib = nameTable.GetNameFor("mscorlib");
   this.System_Runtime = nameTable.GetNameFor("System.Runtime");
   this._Deleted_ = nameTable.GetNameFor("_Deleted*");
 }
예제 #8
0
    private static ISet<IAssembly> GetRootAssembliesFromOptions(ILGarbageCollectorOptions options, IMetadataReaderHost host) {
      ISet<IAssembly> rootAssemblies = new HashSet<IAssembly>();

      foreach (var pathToAssembly in GetRootAssemblyPathsFromOptions(options)) {
        var assembly = host.LoadUnitFrom(pathToAssembly) as IAssembly;
        if (assembly == null) {
          throw new FileNotFoundException("Couldn't load assembly " + pathToAssembly);
        }

        rootAssemblies.Add(assembly);
      }

      return rootAssemblies;
    }
예제 #9
0
        private static ISet <IAssembly> GetRootAssembliesFromOptions(ILGarbageCollectorOptions options, IMetadataReaderHost host)
        {
            ISet <IAssembly> rootAssemblies = new HashSet <IAssembly>();

            foreach (var pathToAssembly in GetRootAssemblyPathsFromOptions(options))
            {
                var assembly = host.LoadUnitFrom(pathToAssembly) as IAssembly;
                if (assembly == null)
                {
                    throw new FileNotFoundException("Couldn't load assembly " + pathToAssembly);
                }

                rootAssemblies.Add(assembly);
            }

            return(rootAssemblies);
        }
 public PhoneControlFeedbackMetadataTraverser(IMetadataReaderHost host) : base() {
   this.host = host;
 }
예제 #11
0
 public TypeVerifier(AssemblyVerifier assemblyVerifier, INamedTypeDefinition type, IMetadataReaderHost env)
 {
     this.assemblyVerifier = assemblyVerifier;
     this.type             = type;
     this.env = env;
 }
예제 #12
0
파일: Assert.cs 프로젝트: ugurak/nemerle
 internal AssemblyVerifier(IAssembly assembly, IMetadataReaderHost env)
 {
     this.assembly = assembly;
     this.env      = env;
 }
 public PhoneControlFeedbackMetadataTraverser(IMetadataReaderHost host) : base()
 {
     this.host = host;
 }