// // 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); }
internal void Serialize(StringBlob symbols, StreamMarshaler streamBuffer) { CfgScriptRef cfgScriptRef = default(CfgScriptRef); cfgScriptRef._idRule = symbols.Find(_rule); cfgScriptRef._method = _method; cfgScriptRef._idMethod = _idSymbol; streamBuffer.WriteStream(cfgScriptRef); }
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); }