本文整理汇总了C#中Marshaller.GetValidLength方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.GetValidLength方法的具体用法?C# Marshaller.GetValidLength怎么用?C# Marshaller.GetValidLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Marshaller
的用法示例。
在下文中一共展示了Marshaller.GetValidLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: DispatchMethod
//.........这里部分代码省略.........
{
TheTraceCallback(command, response);
}
// Collect basic statistics on command execution
if (TheCmdStatsCallback != null && invokeCallbacks)
{
repeat = TheCmdStatsCallback(ordinal, GetBaseErrorCode(resultCode),
(responseReceivedTime - commandSentTime).TotalSeconds);
}
if (repeat && resultCode == TpmRc.Success)
{
// Update session state
ProcessResponseSessions(outSessions);
int offset = (int)commandInfo.HandleCountOut * 4;
outParmsWithHandles = DoParmEncryption(outParmsWithHandles, commandInfo, offset, Direction.Response);
var m = new Marshaller(outParmsWithHandles);
outParms = (TpmStructureBase)m.Get(expectedResponseType, "");
#if false
m = new Marshaller(command);
TpmSt tag = m.Get<TpmSt>();
uint cmdSize = m.Get<uint>();
TpmCc actualCmd = m.Get<TpmCc>();
var actualHandles = new TpmHandle[inHandles.Length];
for (int i = 0; i < inHandles.Length; ++i)
{
actualHandles[i] = m.Get<TpmHandle>();
}
for (int i = 0; i < inSessions.Length; ++i)
{
m.Get<SessionIn>();
}
var actualParms = m.GetArray<byte>(m.GetValidLength() - m.GetGetPos());
if (m.GetValidLength() != cmdSize)
{
throw new Exception("Command length in header does not match input byte-stream");
}
#endif
CommandHeader actualHeader;
TpmHandle[] actualHandles;
SessionIn[] actualSessions;
byte[] actualParmsBuf;
CommandProcessor.CrackCommand(command, out actualHeader, out actualHandles, out actualSessions, out actualParmsBuf);
m = new Marshaller();
foreach (TpmHandle h in actualHandles)
{
m.Put(h, "handle");
}
m.Put(actualParmsBuf, "parms");
var actualParms = (TpmStructureBase)Activator.CreateInstance(inParms.GetType());
actualParms.ToHost(m);
UpdateHandleData(actualHeader.CommandCode, actualParms, actualHandles, outParms);
//ValidateResponseSessions(outHandles, outSessions, ordinal, resultCode, outParmsNoHandles);
foreach (var h in outHandles)
{
CancelSafeFlushContext(h);
}
} // if (repeat && resultCode == TpmRc.Success)
}
catch (Exception)
{
_ClearCommandPrelaunchContext();
_ClearCommandContext();
throw;