Exemplo n.º 1
0
        //
        //  This helper converts a serialized CFG grammar header into an in-memory header
        //
        internal static ScriptRef[] LoadScriptRefs(StreamMarshaler streamHelper, CfgSerializedHeader pFH)
        {
            //
            //  Because in 64-bit code, pointers != sizeof(ULONG) we copy each member explicitly.
            //
            if (pFH.FormatId != CfgGrammar._SPGDF_ContextFree)
            {
                return(null);
            }

            //We know that in SAPI 5.0 grammar format pszWords follows header immediately.
            if (pFH.pszWords < Marshal.SizeOf <CfgSerializedHeader>())
            {
                // Must be SAPI 6.0 or above to hold a .NET script
                return(null);
            }

            // Get the symbols
            StringBlob symbols = LoadStringBlob(streamHelper, pFH.pszSymbols, pFH.cchSymbols);

            // Get the script refs
            CfgScriptRef[] cfgScripts = Load <CfgScriptRef>(streamHelper, pFH.pScripts, pFH.cScripts);

            // Convert the CFG script reference to ScriptRef
            ScriptRef[] scripts = new ScriptRef[cfgScripts.Length];
            for (int i = 0; i < cfgScripts.Length; i++)
            {
                CfgScriptRef cfgScript = cfgScripts[i];
                scripts[i] = new ScriptRef(symbols[cfgScript._idRule], symbols[cfgScript._idMethod], cfgScript._method);
            }

            return(scripts);
        }
Exemplo n.º 2
0
        internal static ScriptRef[] LoadScriptRefs(StreamMarshaler streamHelper, CfgSerializedHeader pFH)
        {
            if (pFH.FormatId != _SPGDF_ContextFree)
            {
                return(null);
            }
            if (pFH.pszWords < Marshal.SizeOf(typeof(CfgSerializedHeader)))
            {
                return(null);
            }
            StringBlob stringBlob = LoadStringBlob(streamHelper, pFH.pszSymbols, pFH.cchSymbols);

            CfgScriptRef[] array  = Load <CfgScriptRef>(streamHelper, pFH.pScripts, pFH.cScripts);
            ScriptRef[]    array2 = new ScriptRef[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                CfgScriptRef cfgScriptRef = array[i];
                array2[i] = new ScriptRef(stringBlob[cfgScriptRef._idRule], stringBlob[cfgScriptRef._idMethod], cfgScriptRef._method);
            }
            return(array2);
        }
Exemplo n.º 3
0
        private void CheckValidAssembly(int iCfg, byte[] il)
        {
            Assembly  executingAssembly = Assembly.GetExecutingAssembly();
            AppDomain appDomain         = null;

            try
            {
                appDomain = AppDomain.CreateDomain("Loading Domain");
                AppDomainCompilerProxy appDomainCompilerProxy = (AppDomainCompilerProxy)appDomain.CreateInstanceFromAndUnwrap(executingAssembly.GetName().CodeBase, "System.Speech.Internal.SrgsCompiler.AppDomainCompilerProxy");
                int      count  = _scriptRefs.Count;
                string[] array  = new string[count];
                string[] array2 = new string[count];
                int[]    array3 = new int[count];
                for (int i = 0; i < count; i++)
                {
                    ScriptRef scriptRef = _scriptRefs[i];
                    array[i]  = scriptRef._rule;
                    array2[i] = scriptRef._sMethod;
                    array3[i] = (int)scriptRef._method;
                }
                Exception ex = appDomainCompilerProxy.CheckAssembly(il, iCfg, _language, _namespace, array, array2, array3);
                if (ex != null)
                {
                    throw ex;
                }
                AssociateConstructorsWithRules(appDomainCompilerProxy, array, _rules, iCfg, _language);
            }
            finally
            {
                if (appDomain != null)
                {
                    AppDomain.Unload(appDomain);
                    appDomain = null;
                }
            }
        }