2021-07-11 22:59:29 -05:00
|
|
|
// Decompiled with JetBrains decompiler
|
|
|
|
|
// Type: Microsoft.Iris.Render.Protocol.MarshalHelper
|
|
|
|
|
// Assembly: UIX.RenderApi, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
|
|
|
|
|
// MVID: D47658B8-A8EA-43D6-8837-ECE823BFFFC1
|
|
|
|
|
// Assembly location: C:\Program Files\Zune\UIX.RenderApi.dll
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Iris.Render.Protocol
|
|
|
|
|
{
|
2021-07-11 23:04:40 -05:00
|
|
|
internal class MarshalHelper
|
2021-07-11 22:59:29 -05:00
|
|
|
{
|
2021-07-11 23:04:40 -05:00
|
|
|
private static RENDERHANDLE[] s_EmptyRenderHandleArray = new RENDERHANDLE[0];
|
2021-07-11 22:59:29 -05:00
|
|
|
|
2021-07-11 23:04:40 -05:00
|
|
|
public static unsafe void Decode(
|
|
|
|
|
RenderPort port,
|
|
|
|
|
Message* pmsg,
|
|
|
|
|
BLOBREF refParam,
|
|
|
|
|
out string param)
|
2021-07-11 22:59:29 -05:00
|
|
|
{
|
2021-07-11 23:04:40 -05:00
|
|
|
uint uint32 = BLOBREF.ToUInt32(refParam);
|
2021-07-11 23:07:04 -05:00
|
|
|
uint num1 = uint32 & ushort.MaxValue;
|
2021-07-11 23:04:40 -05:00
|
|
|
uint num2 = (uint32 & 4294901760U) >> 16;
|
|
|
|
|
byte* numPtr = (byte*)((IntPtr)pmsg + (int)num1);
|
|
|
|
|
int length = (int)num2 - 2;
|
|
|
|
|
byte[] numArray = new byte[length];
|
2021-07-11 23:07:04 -05:00
|
|
|
Marshal.Copy(new IntPtr(numPtr), numArray, 0, length);
|
2021-07-11 23:04:40 -05:00
|
|
|
Encoding encoding = Encoding.Unicode;
|
|
|
|
|
if (port.AlwaysBigEndian)
|
|
|
|
|
encoding = Encoding.BigEndianUnicode;
|
|
|
|
|
param = encoding.GetString(numArray);
|
2021-07-11 22:59:29 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-11 23:04:40 -05:00
|
|
|
public static unsafe void Decode(
|
|
|
|
|
RenderPort port,
|
|
|
|
|
Message* pmsgOuter,
|
|
|
|
|
BLOBREF refMsgInner,
|
|
|
|
|
out Message* pmsgInner)
|
2021-07-11 22:59:29 -05:00
|
|
|
{
|
2021-07-11 23:04:40 -05:00
|
|
|
byte* numPtr = (byte*)pmsgOuter;
|
2021-07-11 23:07:04 -05:00
|
|
|
uint num = ushort.MaxValue & BLOBREF.ToUInt32(refMsgInner);
|
2021-07-11 23:04:40 -05:00
|
|
|
pmsgInner = (Message*)(numPtr + (int)num);
|
2021-07-11 22:59:29 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-11 23:04:40 -05:00
|
|
|
private static ushort[] ComputeByteOrderMap(Type targetType, bool fCompact)
|
2021-07-11 22:59:29 -05:00
|
|
|
{
|
2021-07-11 23:04:40 -05:00
|
|
|
ushort[] fieldMap = new ushort[10];
|
2021-07-11 23:07:04 -05:00
|
|
|
ComputeByteOrderMapWorker(ref fieldMap, targetType, 0);
|
2021-07-11 23:04:40 -05:00
|
|
|
if (fCompact)
|
|
|
|
|
{
|
2021-07-11 23:07:04 -05:00
|
|
|
int length = fieldMap[0] + 1;
|
2021-07-11 23:04:40 -05:00
|
|
|
if (fieldMap.Length > length)
|
|
|
|
|
{
|
|
|
|
|
ushort[] numArray = new ushort[length];
|
2021-07-11 23:07:04 -05:00
|
|
|
Array.Copy(fieldMap, numArray, length);
|
2021-07-11 23:04:40 -05:00
|
|
|
fieldMap = numArray;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return fieldMap;
|
2021-07-11 22:59:29 -05:00
|
|
|
}
|
2021-07-11 23:04:40 -05:00
|
|
|
|
|
|
|
|
public static unsafe void SwapByteOrder(
|
|
|
|
|
byte* pMem,
|
|
|
|
|
ref ushort[] fieldMapByRef,
|
|
|
|
|
Type type,
|
|
|
|
|
int startOffset,
|
|
|
|
|
int stopOffset)
|
|
|
|
|
{
|
|
|
|
|
if (fieldMapByRef == null)
|
2021-07-11 23:07:04 -05:00
|
|
|
fieldMapByRef = ComputeByteOrderMap(type, true);
|
2021-07-11 23:04:40 -05:00
|
|
|
ushort[] numArray = fieldMapByRef;
|
|
|
|
|
if (stopOffset <= 0)
|
|
|
|
|
stopOffset = int.MaxValue;
|
2021-07-11 23:07:04 -05:00
|
|
|
int num1 = numArray[0] + 1;
|
2021-07-11 23:04:40 -05:00
|
|
|
for (int index1 = 1; index1 < num1; ++index1)
|
|
|
|
|
{
|
|
|
|
|
ushort num2 = numArray[index1];
|
2021-07-11 23:07:04 -05:00
|
|
|
int num3 = num2 >> 2;
|
2021-07-11 23:04:40 -05:00
|
|
|
if (num3 >= startOffset)
|
|
|
|
|
{
|
|
|
|
|
if (num3 >= stopOffset)
|
|
|
|
|
break;
|
2021-07-11 23:07:04 -05:00
|
|
|
int num4 = 1 << (num2 & 3);
|
2021-07-11 23:04:40 -05:00
|
|
|
byte* numPtr = pMem + num3;
|
|
|
|
|
int num5 = num4 / 2;
|
|
|
|
|
for (int index2 = 0; index2 < num5; ++index2)
|
|
|
|
|
{
|
|
|
|
|
int index3 = num4 - (index2 + 1);
|
|
|
|
|
byte num6 = numPtr[index2];
|
|
|
|
|
numPtr[index2] = numPtr[index3];
|
|
|
|
|
numPtr[index3] = num6;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 23:07:04 -05:00
|
|
|
public static object MakeDumpable(string value) => value;
|
2021-07-11 23:04:40 -05:00
|
|
|
|
|
|
|
|
public static object MakeDumpable(object value) => value;
|
|
|
|
|
|
2021-07-11 23:07:04 -05:00
|
|
|
public static unsafe object MakeDumpable(void* value) => new IntPtr(value);
|
2021-07-11 23:04:40 -05:00
|
|
|
|
|
|
|
|
private static void ComputeByteOrderMapWorker(
|
|
|
|
|
ref ushort[] fieldMap,
|
|
|
|
|
Type targetType,
|
|
|
|
|
int parentOffset)
|
|
|
|
|
{
|
|
|
|
|
if (targetType.IsPrimitive)
|
|
|
|
|
return;
|
2021-07-11 23:07:04 -05:00
|
|
|
int packingForType = GetPackingForType(targetType);
|
2021-07-11 23:04:40 -05:00
|
|
|
int num1 = 0;
|
|
|
|
|
foreach (FieldInfo field in targetType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
|
|
|
|
|
{
|
|
|
|
|
Type type = field.FieldType;
|
|
|
|
|
if (type.IsEnum)
|
|
|
|
|
type = Enum.GetUnderlyingType(type);
|
|
|
|
|
int size = Marshal.SizeOf(type);
|
|
|
|
|
int num2 = size;
|
|
|
|
|
if (type.IsPrimitive)
|
|
|
|
|
{
|
|
|
|
|
if (num2 > packingForType)
|
|
|
|
|
num2 = packingForType;
|
|
|
|
|
}
|
|
|
|
|
else if (num2 > 4)
|
|
|
|
|
num2 = 4;
|
|
|
|
|
int num3 = num2 - 1;
|
|
|
|
|
int num4 = num1 + num3 & ~num3;
|
|
|
|
|
int num5 = num4 + parentOffset;
|
|
|
|
|
if (type.IsPrimitive)
|
2021-07-11 23:07:04 -05:00
|
|
|
AddByteOrderEntry(ref fieldMap, num5, size);
|
2021-07-11 23:04:40 -05:00
|
|
|
else
|
2021-07-11 23:07:04 -05:00
|
|
|
ComputeByteOrderMapWorker(ref fieldMap, type, num5);
|
2021-07-11 23:04:40 -05:00
|
|
|
num1 = num4 + size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static int GetPackingForType(Type t) => 8;
|
|
|
|
|
|
|
|
|
|
private static void AddByteOrderEntry(ref ushort[] fieldMap, int offset, int size)
|
|
|
|
|
{
|
|
|
|
|
ushort num;
|
|
|
|
|
switch (size)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
return;
|
|
|
|
|
case 2:
|
2021-07-11 23:07:04 -05:00
|
|
|
num = 1;
|
2021-07-11 23:04:40 -05:00
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
return;
|
|
|
|
|
case 4:
|
2021-07-11 23:07:04 -05:00
|
|
|
num = 2;
|
2021-07-11 23:04:40 -05:00
|
|
|
break;
|
|
|
|
|
case 8:
|
2021-07-11 23:07:04 -05:00
|
|
|
num = 3;
|
2021-07-11 23:04:40 -05:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-11 23:07:04 -05:00
|
|
|
int index = fieldMap[0] + 1;
|
2021-07-11 23:04:40 -05:00
|
|
|
if (index >= fieldMap.Length)
|
|
|
|
|
{
|
|
|
|
|
ushort[] numArray = new ushort[2 * fieldMap.Length];
|
2021-07-11 23:07:04 -05:00
|
|
|
Array.Copy(fieldMap, numArray, fieldMap.Length);
|
2021-07-11 23:04:40 -05:00
|
|
|
fieldMap = numArray;
|
|
|
|
|
}
|
|
|
|
|
fieldMap[0] = (ushort)index;
|
2021-07-11 23:07:04 -05:00
|
|
|
fieldMap[index] = (ushort)((uint)(offset << 2) | num);
|
2021-07-11 23:04:40 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-11 23:07:04 -05:00
|
|
|
public static RENDERHANDLE[] CreateRenderHandleArray(int length) => length == 0 ? s_EmptyRenderHandleArray : new RENDERHANDLE[length];
|
2021-07-11 22:59:29 -05:00
|
|
|
}
|
|
|
|
|
}
|