Inheritance: TpmStructureBase
Exemple #1
0
 public CommandHeader(CommandHeader the_CommandHeader)
 {
     if((Object) the_CommandHeader == null ) throw new ArgumentException(Globs.GetResourceString("parmError"));
     Tag = the_CommandHeader.Tag;
     CommandSize = the_CommandHeader.CommandSize;
     CommandCode = the_CommandHeader.CommandCode;
 }
Exemple #2
0
 /// <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;
 }