Ejemplo n.º 1
0
        static StackObject *CreateComInstanceFrom_17(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 4);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Configuration.Assemblies.AssemblyHashAlgorithm @hashAlgorithm = (System.Configuration.Assemblies.AssemblyHashAlgorithm) typeof(System.Configuration.Assemblies.AssemblyHashAlgorithm).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Byte[] @hashValue = (System.Byte[]) typeof(System.Byte[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.String @typeName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            System.String @assemblyName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = System.Activator.CreateComInstanceFrom(@assemblyName, @typeName, @hashValue, @hashAlgorithm);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Ejemplo n.º 2
0
        /// <include file='doc\Activator.uex' path='docs/doc[@for="Activator.CreateComInstanceFrom1"]/*' />
        public static ObjectHandle CreateComInstanceFrom(String assemblyName,
                                                         String typeName,
                                                         byte[] hashValue,
                                                         AssemblyHashAlgorithm hashAlgorithm)

        {
            // jit does not check for that, so we should do it ...
            Assembly assembly = Assembly.LoadFrom(assemblyName, null, hashValue, hashAlgorithm);

            Type t = assembly.GetTypeInternal(typeName, true, false, false);

            Object[] Attr = t.GetCustomAttributes(typeof(ComVisibleAttribute), false);
            if (Attr.Length > 0)
            {
                if (((ComVisibleAttribute)Attr[0]).Value == false)
                {
                    throw new TypeLoadException(Environment.GetResourceString("Argument_TypeMustBeVisibleFromCom"));
                }
            }

            Log(assembly != null, "CreateInstance:: ", "Loaded " + assembly.FullName, "Failed to Load: " + assemblyName);

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


            Object o = Activator.CreateInstance(t,
                                                Activator.ConstructorDefault,
                                                null,
                                                null,
                                                null,
                                                null);

            Log(o != null, "CreateInstance:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if (o == null)
            {
                return(null);
            }
            else
            {
                ObjectHandle Handle = new ObjectHandle(o);
                return(Handle);
            }
        }
Ejemplo n.º 3
0
        static private bool Verify(RSA rsa, AssemblyHashAlgorithm algorithm, byte[] hash, byte[] signature)
        {
            RSAPKCS1SignatureDeformatter vrfy = new RSAPKCS1SignatureDeformatter(rsa);

            switch (algorithm)
            {
            case AssemblyHashAlgorithm.MD5:
                vrfy.SetHashAlgorithm("MD5");
                break;

            case AssemblyHashAlgorithm.SHA1:
            case AssemblyHashAlgorithm.None:
            default:
                vrfy.SetHashAlgorithm("SHA1");
                break;
            }
            return(vrfy.VerifySignature(hash, signature));
        }
Ejemplo n.º 4
0
        public int ExecuteAsAssembly(string file, Evidence evidence, byte[] hash, AssemblyHashAlgorithm id)
        {
            new PermissionSet(PermissionState.Unrestricted).Assert();
            try
            {
                Assembly assembly = Assembly.LoadFrom(file, null, hash, id);

                ApartmentState apt = ApartmentState.Unknown;

                Object[] Attr = assembly.EntryPoint.GetCustomAttributes(typeof(STAThreadAttribute), false);
                if (Attr.Length > 0)
                {
                    apt = ApartmentState.STA;
                }
                Attr = assembly.EntryPoint.GetCustomAttributes(typeof(MTAThreadAttribute), false);
                if (Attr.Length > 0)
                {
                    if (apt == ApartmentState.Unknown)
                    {
                        apt = ApartmentState.MTA;
                    }
                    else
                    {
                        apt = ApartmentState.Unknown;
                    }
                }

                if (apt != ApartmentState.Unknown)
                {
                    Thread.CurrentThread.ApartmentState = apt;
                }
                return(AppDomain.CurrentDomain.ExecuteAssembly(file, null, null, hash, id));
            }
            catch (Exception e)
            {
                exception = new MemoryStream();
                BinaryFormatter formatter = new BinaryFormatter();
                formatter.Serialize(exception, e);
                exception.Position = 0;
                return(-1);
            }
        }
Ejemplo n.º 5
0
        public static ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName,
                                                         byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }

            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            if (assemblyName.Length == 0)
            {
                throw new ArgumentException("assemblyName");
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 6
0
        public bool Verify(Stream stream)
        {
            StrongNameSignature sn = StrongHash(stream, StrongNameOptions.Signature);

            if (sn.Hash == null)
            {
                return(false);
            }

            try {
                AssemblyHashAlgorithm algorithm = AssemblyHashAlgorithm.SHA1;
                if (tokenAlgorithm == "MD5")
                {
                    algorithm = AssemblyHashAlgorithm.MD5;
                }
                return(Verify(rsa, algorithm, sn.Hash, sn.Signature));
            }
            catch (CryptographicException) {
                // no exception allowed
                return(false);
            }
        }
Ejemplo n.º 7
0
		public ObjectHandle CreateComInstanceFrom (string assemblyFile, string typeName,
			byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
		{
			return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm);
		}
 public static System.Runtime.Remoting.ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
 }
Ejemplo n.º 9
0
 // Methods
 public int ExecuteAsAssembly(string file, System.Security.Policy.Evidence evidence, byte[] hash, System.Configuration.Assemblies.AssemblyHashAlgorithm id)
 {
 }
Ejemplo n.º 10
0
 public int ExecuteAssembly(string assemblyFile, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     throw null;
 }
Ejemplo n.º 11
0
        public int ExecuteAssembly(String assemblyFile,
                                   Evidence assemblySecurity,
                                   String[] args,
                                   byte[] hashValue, 
                                   AssemblyHashAlgorithm hashAlgorithm)
        {
            Assembly assembly = Assembly.LoadFrom(assemblyFile, 
                                                  assemblySecurity,
                                                  hashValue,
                                                  hashAlgorithm);
            if (args == null)
                args = new String[0];

            return nExecuteAssembly(assembly, args);
        }
Ejemplo n.º 12
0
 public int ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
 }
 private AssemblyHashAlgorithm _assemblyHashAlgorithmConvert(CfgAssemblyHashAlgorithm alg)
 {
     return((AssemblyHashAlgorithm)alg);
 }
Ejemplo n.º 14
0
        public static System.Runtime.Remoting.ObjectHandle CreateComInstanceFrom(string assemblyName, string typeName, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
        {
            Contract.Requires(assemblyName != null);
            Contract.Requires(typeName != null);

            Contract.Ensures(Contract.Result <System.Runtime.Remoting.ObjectHandle>() != null);

            return(default(System.Runtime.Remoting.ObjectHandle));
        }
Ejemplo n.º 15
0
        public int ExecuteAssembly(String assemblyFile,
                                   Evidence assemblySecurity,
                                   String[] args,
                                   byte[] hashValue, 
                                   AssemblyHashAlgorithm hashAlgorithm)
        {
#if FEATURE_CAS_POLICY
            if (assemblySecurity != null && !IsLegacyCasPolicyEnabled)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
            }
#endif // FEATURE_CAS_POLICY

            RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile, 
                                                                          assemblySecurity,
                                                                          hashValue,
                                                                          hashAlgorithm);
            if (args == null)
                args = new String[0];

            return nExecuteAssembly(assembly, args);
        }
Ejemplo n.º 16
0
        public int ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
        {
            Contract.Ensures((args.Length - Contract.OldValue(args.Length)) <= 0);

            return(default(int));
        }
Ejemplo n.º 17
0
 public static Assembly LoadFrom(string assemblyFile, Byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     Contract.Requires(assemblyFile != null);
     Contract.Ensures(Contract.Result <Assembly>() != null);
     return(default(Assembly));
 }
Ejemplo n.º 18
0
 public AssemblyAlgorithmIdAttribute(System.Configuration.Assemblies.AssemblyHashAlgorithm algorithmId)
 {
 }
Ejemplo n.º 19
0
        public virtual Object CreateInstanceWithSecurity(int dwFlag,
                                                         int dwZone,
                                                         string pURL,
                                                         string uniqueIdString,
                                                         string link,
                                                         string licenses)
        {
            if (pURL == null || Manager.UrlIs(pURL, Manager.URL_IS.URLIS_FILEURL))
            {
                throw new ArgumentException("pURL");
            }
            if ((dwFlag & CORIESECURITY_ZONE) == CORIESECURITY_ZONE && dwZone == 0)
            {
                throw new SecurityException();
            }
            new PermissionSet(PermissionState.Unrestricted).Assert();
            AppDomain proxy  = null;
            Object    result = null;
            string    CodeBase;
            string    Application = null;

            try {
                Manager.CanonizeURL(link, Manager.URL_CANONFLAGS.URL_WININET_COMPATIBILITY);
                if (!Manager.IsValidURL(pURL))
                {
                    throw new ArgumentException("pURL");
                }

                Manager.Log(this, true, "Creating instance of the object in the correct domain", "");
                Manager.Log(this, true, "pUrl = " + pURL, "");
                Manager.Log(this, true, "id = " + uniqueIdString, "");
                Manager.Log(this, true, "link = " + link, "");
                Manager.Log(this, true, "licenses = " + licenses, "");


                // Hack to convert unique id back into byte array;
                byte[] uniqueId = Manager.DecodeDomainId(uniqueIdString);

                if (uniqueId == null)
                {
                    Manager.Log(this, true, "No unqiue id was sent", "");
                    return(null);
                }

                // Get the codebase from the URL, it will be a protocol or a file location. File locations
                // do not have CodeBase set
                bool fHasCodeBase = Manager.GetCodeBase(pURL, out CodeBase, out Application);
                if (CodeBase != null)
                {
                    CodeBase = Manager.CanonizeURL(CodeBase, Manager.URL_CANONFLAGS.URL_UNESCAPE);
                }

                if (Application != null)
                {
                    Application = Application.Replace('\\', '/');
                }

                Manager.Log(this,
                            CodeBase != null,
                            "URL codeBase: " + CodeBase,
                            "URL codeBase: <null>");
                Manager.Log(this,
                            Application != null,
                            "URL application: " + Application,
                            "URL application: <null>");

                // If we have a link tag then get the code base from that.
                string configSite              = null; // Site where the configuration file is located
                string configLocation          = null; // Path from the site to the configuration file
                string configFile              = null; // Name of the configuration file
                bool   fFoundConfigurationSite = false;

                // If there is no link tag then the Application base is always the site.
                // When there is a link tag then the Application base is where the config
                // file is relative to the page.
                if (licenses != null && licenses.Length > 0)
                {
                    licenses = Manager.MakeFullLink(licenses, CodeBase, Application);
                }


                if (link != null && link.Length > 0)
                {
                    link = Manager.MakeFullLink(link, CodeBase, Application);

                    if (!Manager.IsValidURL(link))
                    {
                        throw new ArgumentException("link");
                    }

                    Manager.Log(this, true, "final link = " + link, "");

                    fFoundConfigurationSite = Manager.GetCodeBase(link,
                                                                  out configSite,
                                                                  out configLocation);
                    if (configSite != null)
                    {
                        configSite = Manager.CanonizeURL(configSite, Manager.URL_CANONFLAGS.URL_UNESCAPE);
                    }

                    Manager.GetConfigurationFile(link, out configLocation, out configFile);

                    Manager.Log(this,
                                configSite != null,
                                "Configuration site: " + configSite,
                                "Configuration site: <null>");

                    Manager.Log(this,
                                configLocation != null,
                                "Configuration location: " + configLocation,
                                "Configuration location: <null>");

                    Manager.Log(this,
                                configFile != null,
                                "Configuration fileName: " + configFile,
                                "Configuration fileName: <null>");

                    // We have a configuration site then it must match the pages site
                    if (configSite != null)
                    {
                        if (CodeBase == null ||
                            !Manager.AreTheSame(CodeBase, configSite))
                        {
                            throw new TypeLoadException(_typeName);
                        }
                    }

                    // If they put a site on the configuration file then the code base is set to the configFile
                    // location.
                    //                    if(fFoundConfigurationSite)
                    CodeBase = configLocation;
                    //                    else {
                    //                        StringBuilder sb = new StringBuilder();
                    //                        if(fHasCodeBase) {
                    //                            sb.Append(CodeBase);
                    //                            sb.Append("/");
                    //                        }
                    //                        sb.Append(Application);
                    //                        sb.Append("/");
                    //                        sb.Append(configLocation);
                    //                        CodeBase = sb.ToString();
                    //                    }
                }
                else if (!fHasCodeBase)
                {
                    CodeBase = Application;
                }

                // Rules:
                // 1. If we have a directory associated with the configuration file
                //    then application base is the codebase plus the directory
                string domainName = null;
                Manager.Log(this, true,
                            "Locating domain for " + CodeBase,
                            "");
                domainName = CodeBase;

                proxy = _host.LocateDomain(uniqueId, domainName);
                if (proxy == null)
                {
                    lock (_host) {
                        proxy = _host.LocateDomain(uniqueId, domainName);
                        if (proxy == null)
                        {
                            proxy = CreateProxy(dwZone,
                                                dwFlag,
                                                domainName,
                                                fHasCodeBase,
                                                CodeBase,
                                                pURL,
                                                configFile,
                                                uniqueId,
                                                licenses);
                        }
                        else
                        {
                            Manager.Log(this, true, "SOME ONE CREATED THE DOMAIN BEFORE I HAD a CHANCE", "");
                        }
                    }
                }
                else
                {
                    Manager.Log(this, true, "Do not have to create new domain", "");
                    Manager.Log(this, true, "Existing Domain:", "");
                    Manager.Log(this, true, proxy.ToString(), "");
                }

                // The assembly is assigned the attributes stored with this factory.
                // There is a new factory for each assembly downloaded from the web
                // so the attributes are unique to a specific assembly.

                Manager.Log(this, true, "Trying to create instance of type " + _assemblyName.CodeBase + "#" + _typeName, "");
                AssemblyHashAlgorithm id = AssemblyHashAlgorithm.SHA1;
                result = proxy.CreateComInstanceFrom(_assemblyName.CodeBase,
                                                     _typeName,
                                                     _fileHash,
                                                     id);

                Manager.Log(this, result == null, "Unable to create instance of type " + _assemblyName + "::" + _typeName,
                            "Created instance of type " + _assemblyName.CodeBase + "::" + _typeName);
                // @BUGBUG We need to do this why does it not work???
                if (result == null)
                {
                    throw new TypeLoadException(_typeName);
                }


#if _DEBUG
                if (configFile != null)
                {
                    String s = "Configuration file name " + proxy.SetupInformation.ConfigurationFile;
                    Manager.Log(this, true, s, "");
                }
#endif
            }
            catch (Exception e) {
                Manager.Log(this, true, e.ToString(), "");
                string entry = null;
                if (_assemblyName.CodeBase != null)
                {
                    int k = _assemblyName.CodeBase.LastIndexOf('/');
                    if (k != -1)
                    {
                        entry = _assemblyName.CodeBase.Substring(k + 1);
                    }
                }
                LogException(e, entry);
                throw e;
            }
            return(result);
        }
 private static AssemblyHashAlgorithm ConvertAssemblyHashAlgorithm(CfgAssemblyHashAlgorithm alg)
 {
     return((AssemblyHashAlgorithm)alg);
 }
Ejemplo n.º 21
0
 public int ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, String[] args, Byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     return(default(int));
 }
 public static System.Reflection.Assembly LoadFrom(string assemblyFile, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     return(default(System.Reflection.Assembly));
 }
Ejemplo n.º 23
0
 public static Assembly LoadFrom(string assemblyFile, System.Security.Policy.Evidence securityEvidence, Byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     return(default(Assembly));
 }
Ejemplo n.º 24
0
		public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
		{
			Assembly a = Assembly.LoadFrom (assemblyFile, null, hashValue, hashAlgorithm);
			return ExecuteAssemblyInternal (a, args);
		}
Ejemplo n.º 25
0
 public static Assembly LoadFrom(string assemblyFile, byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
 {
     throw null;
 }
Ejemplo n.º 26
0
		/// <summary>
		///  Fills the row from the array of bytes.
		/// </summary>
		unsafe public void FromRawData(byte [] buff, int offs)
		{
			if (buff == null) throw new Exception("buff == null");
			if (offs + Size > buff.Length) throw new Exception("bounds");

		
			this.HashAlgId = (System.Configuration.Assemblies.AssemblyHashAlgorithm) LEBitConverter.ToInt32(buff, offs);
			offs += sizeof (int);
			this.MajorVersion = LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.MinorVersion = LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.BuildNumber = LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.RevisionNumber = LEBitConverter.ToInt16(buff, offs);
			offs += sizeof (short);
			this.Flags = (AssemblyFlags) LEBitConverter.ToUInt32(buff, offs);
			offs += sizeof (uint);
			this.PublicKey = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Name = LEBitConverter.ToInt32(buff, offs);
			offs += 4;
			this.Culture = LEBitConverter.ToInt32(buff, offs);
			
		}
Ejemplo n.º 27
0
        public ObjectHandle CreateComInstanceFrom(String assemblyFile,
                                                  String typeName,
                                                  byte[] hashValue, 
                                                  AssemblyHashAlgorithm hashAlgorithm)
                                         
        {
            if (this == null)
                throw new NullReferenceException();
            Contract.EndContractBlock();

            return Activator.CreateComInstanceFrom(assemblyFile,
                                                   typeName,
                                                   hashValue, 
                                                   hashAlgorithm);
        }
Ejemplo n.º 28
0
		static private bool Verify (RSA rsa, AssemblyHashAlgorithm algorithm, byte[] hash, byte[] signature) 
		{
			RSAPKCS1SignatureDeformatter vrfy = new RSAPKCS1SignatureDeformatter (rsa);
			switch (algorithm) {
			case AssemblyHashAlgorithm.MD5:
				vrfy.SetHashAlgorithm ("MD5");
				break;
			case AssemblyHashAlgorithm.SHA1:
			case AssemblyHashAlgorithm.None:
			default:
				vrfy.SetHashAlgorithm ("SHA1");
				break;
			}
			return vrfy.VerifySignature (hash, signature);
		}
Ejemplo n.º 29
0
        public int ExecuteAssembly(string assemblyFile,
                                   string[] args,
                                   byte[] hashValue,
                                   AssemblyHashAlgorithm hashAlgorithm)
        {
            RuntimeAssembly assembly = (RuntimeAssembly)Assembly.LoadFrom(assemblyFile,
                                                                          hashValue,
                                                                          hashAlgorithm);
            if (args == null)
                args = new String[0];

            return nExecuteAssembly(assembly, args);
        }
        public static Assembly LoadFrom(string !assemblyFile, System.Security.Policy.Evidence securityEvidence, Byte[] hashValue, System.Configuration.Assemblies.AssemblyHashAlgorithm hashAlgorithm)
        {
            CodeContract.Requires(assemblyFile != null);

            return(default(Assembly));
        }