本文整理汇总了C#中Marshaller.GetArray方法的典型用法代码示例。如果您正苦于以下问题:C# Marshaller.GetArray方法的具体用法?C# Marshaller.GetArray怎么用?C# Marshaller.GetArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Marshaller
的用法示例。
在下文中一共展示了Marshaller.GetArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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;
示例3: 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;
}
示例4: 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");
}