internal static int ReadArrayLength(MemorySection[] heap, UInt64 address, TypeDescription arrayType, VirtualMachineInformation virtualMachineInformation) { BytesAndOffset bo = heap.Find(address, virtualMachineInformation); UInt64 bounds = bo.Add(virtualMachineInformation.arrayBoundsOffsetInHeader).ReadPointer(); if (bounds == 0) #if UNITY_2017_2_OR_NEWER { return((int)bo.Add(virtualMachineInformation.arraySizeOffsetInHeader).ReadPointer()); } #else { return(bo.Add(virtualMachineInformation.arraySizeOffsetInHeader).ReadInt32()); } #endif BytesAndOffset cursor = heap.Find(bounds, virtualMachineInformation); int length = 1; for (int i = 0; i != arrayType.arrayRank; i++) { #if UNITY_2017_2_OR_NEWER length *= (int)cursor.ReadPointer(); cursor = cursor.Add(virtualMachineInformation.pointerSize == 4 ? 8 : 16); #else length *= cursor.ReadInt32(); cursor = cursor.Add(8); #endif } return(length); }
internal static int ReadStringObjectSizeInBytes(BytesAndOffset bo, VirtualMachineInformation virtualMachineInformation) { BytesAndOffset lengthPointer = bo.Add(virtualMachineInformation.objectHeaderSize); int length = lengthPointer.ReadInt32(); return(virtualMachineInformation.objectHeaderSize + /*lengthfield*/ 1 + (length * /*utf16=2bytes per char*/ 2) + /*2 zero terminators*/ 2); }
internal static string ReadString(BytesAndOffset bo, VirtualMachineInformation virtualMachineInformation) { BytesAndOffset lengthPointer = bo.Add(virtualMachineInformation.objectHeaderSize); int length = lengthPointer.ReadInt32(); BytesAndOffset firstChar = lengthPointer.Add(4); return(System.Text.Encoding.Unicode.GetString(firstChar.bytes, firstChar.offset, length * 2)); }