当前位置: 首页>>代码示例>>C#>>正文


C# Marshaller.Get方法代码示例

本文整理汇总了C#中Marshaller.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.Get方法的具体用法?C# Marshaller.Get怎么用?C# Marshaller.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Marshaller的用法示例。


在下文中一共展示了Marshaller.Get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetResultCode

 private TpmRc GetResultCode(byte[] responseBuf)
 {
     var mOut = new Marshaller(responseBuf);
     // ReSharper disable once UnusedVariable
     var responseTag = mOut.Get<TpmSt>();
     // ReSharper disable once UnusedVariable
     var responseParamSize = mOut.Get<uint>();
     var resultCode = mOut.Get<TpmRc>();
     return resultCode;
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:10,代码来源:SlotManager.cs

示例2: ParseResponse

        public static string ParseResponse(string commandCode, byte[] buf)
        {
            TpmHandle[] outHandles;
            SessionOut[] outSessions;
            byte[] responseParmsNoHandles;
            byte[] responseParmsWithHandles;
            string response = "";
            if (1 != CommandInformation.Info.Count(item => item.CommandCode.ToString() == commandCode))
            {
                response = "Command code not recognized.  Defined command codes are:\n";
                // ReSharper disable once LoopCanBeConvertedToQuery
                foreach (CommandInfo info in CommandInformation.Info)
                {
                    response += info.CommandCode.ToString() + " ";
                }
                return response;
            }

            CommandInfo command = CommandInformation.Info.First(item => item.CommandCode.ToString() == commandCode);
            TpmSt tag;
            uint paramSize;
            TpmRc responseCode;

            SplitResponse(buf,
                          command.HandleCountOut,
                          out tag,
                          out paramSize,
                          out responseCode,
                          out outHandles,
                          out outSessions,
                          out responseParmsNoHandles,
                          out responseParmsWithHandles);
            if (responseCode != TpmRc.Success)
            {
                TpmRc resultCode;
                response += "Error:\n";
                response += Tpm2.GetErrorString(command.InStructType, (uint)responseCode, out resultCode);
                return response;
            }

            // At this point in the processing stack we cannot deal with encrypted responses
            bool responseIsEncrypted = false;
            foreach (SessionOut s in outSessions)
            {
                if (s.attributes.HasFlag(SessionAttr.Encrypt)
                    &&
                    (command.TheParmCryptInfo.HasFlag(ParmCryptInfo.DecOut2) ||
                     command.TheParmCryptInfo.HasFlag(ParmCryptInfo.DecOut2))
                    )
                    responseIsEncrypted = true;
            }

            response += "Response Header:\n";
            response += "    Tag=" + tag.ToString() + "\n";
            response += "    Response code=" + responseCode.ToString() + "\n";

            response += "Response Parameters:\n";
            if (!responseIsEncrypted)
            {
                var m2 = new Marshaller(responseParmsWithHandles);
                Object inParms = m2.Get(command.OutStructType, "");
                response += inParms + "\n";
            }
            else
            {
                var m2 = new Marshaller(responseParmsWithHandles);
                Object encOutParms;
                switch (command.TheParmCryptInfo)
                {
                    // TODO: this is not the right type if we ever do size-checks
                    case ParmCryptInfo.DecOut2:
                        encOutParms = m2.Get(typeof (Tpm2bMaxBuffer), "");
                        break;
                    default:
                        throw new NotImplementedException("NOT IMPLEMENTED");
                }
                response += "Encrypted: " + encOutParms + "\n";
            }

            response += "Sessions [" + outSessions.Length + "]\n";
            for (int j = 0; j < outSessions.Length; j++)
            {
                // ReSharper disable once FormatStringProblem
                response += String.Format("{0}: 0x{1:x}\n", j, outSessions[j]);
            }
            return response;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:87,代码来源:Tpm2.cs

示例3: ToHost

 internal virtual void ToHost(Marshaller m)
 {
     var members = GetFieldsToMarshal(true);
     dbg.Indent();
     for (int i = 0; i < members.Length; ++i)
     {
         TpmStructMemberInfo memInfo = members[i];
         Type memType = Globs.GetMemberType(memInfo);
         var wt = members[i].WireType;
         switch(wt)
         {
             case MarshalType.Union:
             {
                 dbg.Trace("Union " + memType.Name + " with selector " + memInfo.Tag.Value);
                 memInfo.Value = m.Get(UnionElementFromSelector(memType, memInfo.Tag.Value), memType.Name);
                 break;
             }
             case MarshalType.FixedLengthArray:
             {
                 object arr = Globs.GetMember(memInfo, this);
                 memInfo.Value = m.GetArray(memType.GetElementType(), (arr as Array).Length, memInfo.Name);
                 break;
             }
             case MarshalType.VariableLengthArray:
             {
                 int size = m.GetSizeTag(memInfo.SizeLength, memInfo.SizeName);
                 memInfo.Value = m.GetArray(memType.GetElementType(), size, memInfo.Name);
                 Debug.Assert(size == ((Array)memInfo.Value).Length);
                 dbg.Trace("Received Array " + memInfo.Name + " of size " + size);
                 break;
             }
             case MarshalType.SizedStruct:
             {
                 int size = m.GetSizeTag(memInfo.SizeLength, memInfo.SizeName);
                 if (size != 0)
                 {
                     memInfo.Value = m.Get(memType, memInfo.Name);
                     Debug.Assert(size == Marshaller.GetTpmRepresentation(memInfo.Value).Length);
                 }
                 dbg.Trace("Received Struct " + memInfo.Name + " of size " + size);
                 break;
             }
             default:
                 // Only attempt unmarshaling a field, if it is not sized or
                 // if its size is non-zero.
                 if (memInfo.Tag == null ||
                     memInfo.Tag.GetValueAsUInt() != 0)
                 {
                     memInfo.Value = m.Get(memType, memInfo.Name);
                 }
                 break;
         }
         dbg.Trace((i + 1) + ": " + memInfo.Name +  " = " + memInfo.Value);
         // Some property values are dynamically obtained from their linked fields.
         // Correspondingly, they do not have a setter, so we bypass them here.
         Debug.Assert(wt != MarshalType.LengthOfStruct && wt != MarshalType.ArrayCount);
         if (wt != MarshalType.UnionSelector)
         {
             Globs.SetMember(memInfo, this, memInfo.Value);
         }
     }
     dbg.Unindent();
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:63,代码来源:TpmBaseClasses.cs

示例4: ParseCommand

        public static string ParseCommand(byte[] buf)
        {
            CommandHeader commandHeader;
            TpmHandle[] inHandles;
            SessionIn[] inSessions;
            byte[] commandParmsNoHandles;
            string response = "";

            bool ok = CrackCommand(buf, out commandHeader, out inHandles, out inSessions, out commandParmsNoHandles);
            if (!ok)
            {
                response = "The TPM command is not properly formatted.  Doing the best I can...\n";
            }
            CommandInfo command = Tpm2.CommandInfoFromCommandCode(commandHeader.CommandCode);
            if (command == null)
            {
                response += String.Format("The command-code {0} is not defined.  Aborting\n", commandHeader.CommandCode);
                return response;
            }
            response += "Header:\n";
            response += commandHeader + "\n";

            var m2 = new Marshaller();
            foreach (TpmHandle h in inHandles)
            {
                m2.Put(h, "");
            }

            byte[] commandParmsWithHandles = Globs.Concatenate(new[] {m2.GetBytes(), commandParmsNoHandles});
            var m = new Marshaller(commandParmsWithHandles);
            object inParms = m.Get(command.InStructType, "");
            response += "Command Parameters:\n";
            response += inParms + "\n";
            response += "Sessions [" + inSessions.Length + "]\n";
            for (int j = 0; j < inSessions.Length; j++)
            {
                // ReSharper disable once FormatStringProblem
                response += String.Format("{0}: 0x{1:x}\n", j, inSessions[j]);
            }
            return response;
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:41,代码来源:Tpm2.cs

示例5: GetResponseCode

        public static TpmRc GetResponseCode(byte[] response)
        {
            if (response.Length > 10)
                return TpmRc.Success;

            var m = new Marshaller(response);
            // ReSharper disable once UnusedVariable
            var tag = m.Get<TpmSt>();
            // ReSharper disable once UnusedVariable
            var paramSize = m.Get<uint>();
            var responseCode = m.Get<TpmRc>();
            TpmRc maskedResponse = Tpm2.GetBaseErrorCode(responseCode);
            return maskedResponse;

        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:15,代码来源:Tpm2.cs

示例6: CrackCommand

 /// <summary>
 /// Opens a properly-formed TPM command stream into its constituent components.
 /// Note: commandParams does NOT include handles.
 /// </summary>
 /// <param name="command"></param>
 /// <param name="header"></param>
 /// <param name="handles"></param>
 /// <param name="sessions"></param>
 /// <param name="commandParms"></param>
 public static bool CrackCommand(
     byte[] command,
     out CommandHeader header,
     out TpmHandle[] handles,
     out SessionIn[] sessions,
     out byte[] commandParms)
 {
     var m = new Marshaller(command);
     header = m.Get<CommandHeader>();
     CommandInfo commandInfo = Tpm2.CommandInfoFromCommandCode(header.CommandCode);
     if (header.Tag == TpmSt.Null)
     {
         // A diagnostics command. Pass through unmodified
         handles = null;
         sessions = null;
         commandParms = null;
         return false;
     }
     handles = new TpmHandle[commandInfo.HandleCountIn];
     for (int j = 0; j < handles.Length; j++)
     {
         handles[j] = m.Get<TpmHandle>();
     }
     // Note sessions are only present if the command tag indicates sessions
     if (header.Tag == TpmSt.Sessions)
     {
         var sessionLength = m.Get<uint>();
         uint sessionEnd = m.GetGetPos() + sessionLength;
         var inSessions = new List<SessionIn>();
         while (m.GetGetPos() < sessionEnd)
         {
             var s = m.Get<SessionIn>();
             inSessions.Add(s);
         }
         sessions = inSessions.ToArray();
     }
     else
     {
         sessions = new SessionIn[0];
     }
     // And finally parameters
     commandParms = m.GetArray<byte>((int)(m.GetValidLength() - m.GetGetPos()));
     if (m.GetValidLength() != header.CommandSize)
     {
         throw new Exception("Command length in header does not match input byte-stream");
     }
     return true;
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:57,代码来源:Tpm2.cs

示例7: SplitResponse

        public static void SplitResponse(
            byte[] response,
            uint numHandles,
            out TpmSt tag,
            out uint paramSize,
            out TpmRc responseCode,
            out TpmHandle[] handles,
            out SessionOut[] sessions,
            out byte[] responseParmsNoHandles,
            out byte[] responseParmsWithHandles)
        {
            var m = new Marshaller(response);
            tag = m.Get<TpmSt>();
            paramSize = m.Get<uint>();
            responseCode = m.Get<TpmRc>();
            // If error we only get the header
            if (responseCode != TpmRc.Success)
            {
                handles = new TpmHandle[0];
                sessions = new SessionOut[0];
                responseParmsNoHandles = new byte[0];
                responseParmsWithHandles = new byte[0];
                return;
            }

            handles = new TpmHandle[numHandles];
            for (int j = 0; j < numHandles; j++)
            {
                handles[j] = m.Get<TpmHandle>();
            }
            uint parmsEnd = m.GetValidLength();
            if (tag == TpmSt.Sessions)
            {
                var sessionOffset = m.Get<uint>();
                uint startOfParmsX = m.GetGetPos();
                parmsEnd = startOfParmsX + sessionOffset;
                m.SetGetPos(parmsEnd);
                var sessX = new List<SessionOut>();
                while (m.GetGetPos() < m.GetValidLength())
                {
                    var s = m.Get<SessionOut>();
                    sessX.Add(s);
                }
                sessions = sessX.ToArray();
                m.SetGetPos(startOfParmsX);
            }
            else
            {
                sessions = new SessionOut[0];
            }

            uint startOfParms = m.GetGetPos();
            uint parmsLength = parmsEnd - m.GetGetPos();

            // Get the response buf with no handles
            responseParmsNoHandles = new byte[parmsLength];
            Array.Copy(response, (int)startOfParms, responseParmsNoHandles, 0, (int)parmsLength);

            // Get the response buf with handles
            responseParmsWithHandles = new byte[parmsLength + numHandles * 4];
            Array.Copy(response, 10, responseParmsWithHandles, 0, (int)numHandles * 4);
            Array.Copy(response, (int)startOfParms, responseParmsWithHandles, (int)numHandles * 4, (int)parmsLength);
        }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:63,代码来源:Tpm2.cs

示例8: DispatchMethod


//.........这里部分代码省略.........
            {
                parmsCopy = Globs.CopyData(parms);
            }

            // Response atoms
            TpmSt responseTag;
            TpmRc resultCode;
            uint responseParamSize;
            byte[] outParmsNoHandles, outParmsWithHandles;
            TpmHandle[] outHandles;
            SessionOut[] outSessions;

            // In normal processing there is just one pass through this do-while loop
            // If command observation/modification callbacks are installed, then the
            // caller repeats the command as long as necessary.
            bool invokeCallbacks = OuterCommand == TpmCc.None && !CpHashMode && !DoNotDispatchCommand;
            do try
            {
                if (TheCmdParamsCallback != null && invokeCallbacks)
                {
                    parms = Globs.CopyData(parmsCopy);
                    TheCmdParamsCallback(commandInfo, ref parms, inHandles);
                }

                // If there are any encrypting sessions then next we encrypt the data in place
                parms = DoParmEncryption(parms, commandInfo, 0, Direction.Command);

                // Now do the HMAC (note that the handles are needed for name-replacement)
                SessionIn[] inSessions = CreateRequestSessions(parms, inHandles);

                // CpHashMode is enabled for a single command through tpm.GetCpHash().TpmCommand(...)
                if (OuterCommand == TpmCc.None && CpHashMode)
                {
                    CommandParmHash.HashData = GetCommandHash(CommandParmHash.HashAlg, parms, inHandles);
                    outParms = (TpmStructureBase)Activator.CreateInstance(expectedResponseType);
                    CpHashMode = false;
                    _ClearCommandContext();
                    return true;
                }

                // Create the command buffer
                byte[] command = CommandProcessor.CreateCommand(ordinal, inHandles, inSessions, parms);

                // And dispatch the command
                Log(ordinal, inParms, 0);

                if (DoNotDispatchCommand)
                {
                    CommandBytes = command;
                    outParms = (TpmStructureBase)Activator.CreateInstance(expectedResponseType);
                    DoNotDispatchCommand = false;
                    _ClearCommandContext();
                    return true;
                }

                if (TheCmdBufCallback != null && invokeCallbacks)
                {
                    TheCmdBufCallback(ref command);
                }

                // And actually dispatch the command into the underlying device
                DateTime commandSentTime, responseReceivedTime;
                int nvRateRecoveryCount = 0;

                // No more than 4 retries on NV_RATE error
                for (;;)
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:67,代码来源:Tpm2.cs

示例9: ToHost

 internal override void ToHost(Marshaller m)
 {
     var id = (TpmAlgId)m.Get(typeof (TpmAlgId), "HashAlg");
     if (id == TpmAlgId.Null)
     {
         _HashAlg = id;
         HashData = new byte[0];
         return;
     }
     _HashAlg = id;
     int hashLength = CryptoLib.DigestSize(id);
     HashData = m.GetArray<byte>(hashLength, "HashData");
 }
开发者ID:vishalishere,项目名称:TSS.MSR,代码行数:13,代码来源:TpmCustomDefs.cs

示例10: ToHost

 internal override void ToHost(Marshaller m)
 {
     Algorithm = m.Get<TpmAlgId>();
     switch (Algorithm)
     {
         case TpmAlgId.None:
         case TpmAlgId.Null:
             return;
         case TpmAlgId.Xor:
             KeyBits = 0;
             Mode = m.Get<TpmAlgId>();
             break;
         case TpmAlgId.Aes:
             KeyBits = m.Get<ushort>();
             Mode = m.Get<TpmAlgId>();
             break;
         default:
             Globs.Throw<NotImplementedException>("SymDef.ToHost: Unknown algorithm");
             break;
     }
 }
开发者ID:Microsoft,项目名称:TSS.MSR,代码行数:21,代码来源:TpmCustomDefs.cs


注:本文中的Marshaller.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。