源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.6 KiB

  1. using System;
  2. using UnityEditor.MemoryProfiler;
  3. using UnityEngine;
  4. namespace MemoryProfilerWindow
  5. {
  6. class PrimitiveValueReader
  7. {
  8. private readonly VirtualMachineInformation _virtualMachineInformation;
  9. private readonly MemorySection[] _heapSections;
  10. public PrimitiveValueReader(VirtualMachineInformation virtualMachineInformation, MemorySection[] heapSections)
  11. {
  12. _virtualMachineInformation = virtualMachineInformation;
  13. _heapSections = heapSections;
  14. }
  15. public System.Int32 ReadInt32(BytesAndOffset bo)
  16. {
  17. return BitConverter.ToInt32(bo.bytes, bo.offset);
  18. }
  19. public System.UInt32 ReadUInt32(BytesAndOffset bo)
  20. {
  21. return BitConverter.ToUInt32(bo.bytes, bo.offset);
  22. }
  23. public System.Int64 ReadInt64(BytesAndOffset bo)
  24. {
  25. return BitConverter.ToInt64(bo.bytes, bo.offset);
  26. }
  27. public System.UInt64 ReadUInt64(BytesAndOffset bo)
  28. {
  29. return BitConverter.ToUInt64(bo.bytes, bo.offset);
  30. }
  31. public System.Int16 ReadInt16(BytesAndOffset bo)
  32. {
  33. return BitConverter.ToInt16(bo.bytes, bo.offset);
  34. }
  35. public System.UInt16 ReadUInt16(BytesAndOffset bo)
  36. {
  37. return BitConverter.ToUInt16(bo.bytes, bo.offset);
  38. }
  39. public System.Byte ReadByte(BytesAndOffset bo)
  40. {
  41. return bo.bytes[bo.offset];
  42. }
  43. public System.SByte ReadSByte(BytesAndOffset bo)
  44. {
  45. return (System.SByte)bo.bytes[bo.offset];
  46. }
  47. public System.Boolean ReadBool(BytesAndOffset bo)
  48. {
  49. return ReadByte(bo) != 0;
  50. }
  51. public UInt64 ReadPointer(BytesAndOffset bo)
  52. {
  53. if (_virtualMachineInformation.pointerSize == 4)
  54. return ReadUInt32(bo);
  55. else
  56. return ReadUInt64(bo);
  57. }
  58. public UInt64 ReadPointer(UInt64 address)
  59. {
  60. return ReadPointer(_heapSections.Find(address, _virtualMachineInformation));
  61. }
  62. public Char ReadChar(BytesAndOffset bytesAndOffset)
  63. {
  64. return System.Text.Encoding.Unicode.GetChars(bytesAndOffset.bytes, bytesAndOffset.offset, 2)[0];
  65. }
  66. public System.Single ReadSingle(BytesAndOffset bytesAndOffset)
  67. {
  68. return BitConverter.ToSingle(bytesAndOffset.bytes, bytesAndOffset.offset);
  69. }
  70. public System.Double ReadDouble(BytesAndOffset bytesAndOffset)
  71. {
  72. return BitConverter.ToDouble(bytesAndOffset.bytes, bytesAndOffset.offset);
  73. }
  74. }
  75. }