一、前言
嗨,大家好,我是新发。
项目发布了Windows
平台的版本,运行过程中发现有部分玩家的设备ID
是相同的。
莫非这些玩家破解了代码,篡改了获取设备ID
的逻辑,使之相同。
没理由,如果是为了刷号,正常是修改成不同的设备ID
才对。
直觉告诉我,问题可能是虚拟机,如果我安装两个虚拟机,那么这两个虚拟机的设备ID
是一样的吗?好奇心驱使我做了下面的实验。
二、Unity获取设备ID
Unity
官方提供了SystemInfo
类,方便开发者获取系统信息,其中就包括我们说的设备标识符,也就设备ID
:SystemInfo.deviceUniqueIdentifier
。
我们可以通过反射的方式把SystemInfo
类的所有成员答应出来。
例:
using System;
using System.Reflection;
using System.Text;
using UnityEngine;
public class PrintSystemInfo : MonoBehaviour
{
void Start()
{
Type type = typeof(SystemInfo);
PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Static |
BindingFlags.Public | BindingFlags.GetProperty);
StringBuilder sbr = new StringBuilder();
sbr.AppendLine("总共" + propertyInfos.Length + "个成员");
for (int i = 0; i < propertyInfos.Length; i++)
{
sbr.AppendFormat("{0:D2}. {1,-50} = ", i + 1, propertyInfos[i].Name);
sbr.Append(type.InvokeMember(propertyInfos[i].Name, BindingFlags.Static |
BindingFlags.Public | BindingFlags.GetProperty, null, null, null));
sbr.AppendLine();
}
Debug.Log(sbr.ToString());
}
}
输出如下:
总共89个成员
01. batteryLevel = -1
02. batteryStatus = Charging
03. operatingSystem = Windows 10 (10.0.18363) 64bit
04. operatingSystemFamily = Windows
05. processorType = Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
06. processorFrequency = 3292
07. processorCount = 4
08. systemMemorySize = 16284
09. deviceUniqueIdentifier = f54dd0ef5a143be2fb44a65178603d0b37e126aa
10. deviceName = LINXINFAPC
11. deviceModel = B85M-D2V (Gigabyte Technology Co., Ltd.)
12. supportsAccelerometer = False
13. supportsGyroscope = False
14. supportsLocationService = False
15. supportsVibration = False
16. supportsAudio = True
17. deviceType = Desktop
18. graphicsMemorySize = 2007
19. graphicsDeviceName = NVIDIA GeForce GT 740
20. graphicsDeviceVendor = NVIDIA
21. graphicsDeviceID = 4040
22. graphicsDeviceVendorID = 4318
23. graphicsDeviceType = Direct3D11
24. graphicsUVStartsAtTop = True
25. graphicsDeviceVersion = Direct3D 11.0 [level 11.0]
26. graphicsShaderLevel = 50
27. graphicsMultiThreaded = True
28. renderingThreadingMode = MultiThreaded
29. hasHiddenSurfaceRemovalOnGPU = False
30. hasDynamicUniformArrayIndexingInFragmentShaders = True
31. supportsShadows = True
32. supportsRawShadowDepthSampling = True
33. supportsMotionVectors = True
34. supports3DTextures = True
35. supportsCompressed3DTextures = True
36. supports2DArrayTextures = True
37. supports3DRenderTextures = True
38. supportsCubemapArrayTextures = True
39. copyTextureSupport = Basic, Copy3D, DifferentTypes, TextureToRT, RTToTexture
40. supportsComputeShaders = True
41. supportsConservativeRaster = False
42. supportsMultiview = False
43. supportsGeometryShaders = True
44. supportsTessellationShaders = True
45. supportsRenderTargetArrayIndexFromVertexShader = False
46. supportsInstancing = True
47. supportsHardwareQuadTopology = False
48. supports32bitsIndexBuffer = True
49. supportsSparseTextures = True
50. supportedRenderTargetCount = 8
51. supportsSeparatedRenderTargetsBlend = True
52. supportedRandomWriteTargetCount = 8
53. supportsMultisampledTextures = 1
54. supportsMultisampled2DArrayTextures = True
55. supportsMultisampleAutoResolve = False
56. supportsTextureWrapMirrorOnce = 1
57. usesReversedZBuffer = True
58. npotSupport = Full
59. maxTextureSize = 16384
60. maxCubemapSize = 16384
61. maxComputeBufferInputsVertex = 128
62. maxComputeBufferInputsFragment = 128
63. maxComputeBufferInputsGeometry = 128
64. maxComputeBufferInputsDomain = 128
65. maxComputeBufferInputsHull = 128
66. maxComputeBufferInputsCompute = 32
67. maxComputeWorkGroupSize = 1024
68. maxComputeWorkGroupSizeX = 1024
69. maxComputeWorkGroupSizeY = 1024
70. maxComputeWorkGroupSizeZ = 64
71. supportsAsyncCompute = False
72. supportsGpuRecorder = True
73. supportsGraphicsFence = True
74. supportsAsyncGPUReadback = True
75. supportsRayTracing = False
76. supportsSetConstantBuffer = True
77. constantBufferOffsetAlignment = 0
78. minConstantBufferOffsetAlignment = False
79. hasMipMaxLevel = True
80. supportsMipStreaming = True
81. usesLoadStoreActions = False
82. hdrDisplaySupportFlags = Supported, RuntimeSwitchable, AutomaticTonemapping
83. supportsRenderTextures = True
84. supportsRenderToCubemap = True
85. supportsImageEffects = True
86. supportsStencil = 1
87. graphicsPixelFillrate = -1
88. supportsVertexPrograms = True
89. supportsGPUFence = False
可以看到我的电脑的设备ID
是f54dd0ef5a143be2fb44a65178603d0b37e126aa
。
关于
SystemInfo
更多的说明,可以参见我之前写的这篇文章:《Unity获取系统信息SystemInfo(CPU、显卡、操作系统等信息)》
三、安装虚拟机
系统镜像下载:https://msdn.itellyou.cn/
我在上面那个网站中下载了win7
系统镜像。
通过Oracle VM VirtualBox
安装了两个win7
虚拟机。
关于
Oracle VM VirtualBox
安装虚拟机,可以参见我之前写的这篇文章:《手把手教,使用Oracle VM VirtualBox虚拟机安装Windows XP系统,爷青回》
四、虚拟机中测试deviceUniqueIdentifier
弄个测试脚本,获取设备ID
,如下:
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour
{
public Text text;
void Start()
{
text.text = SystemInfo.deviceUniqueIdentifier;
}
}
在我的本机(win10
系统)中运行结果如下:
我发布到windows
平台,然后弄到两台虚拟机中。运行效果如下:
虚拟机与本地机的设备ID
不同,但两台虚拟机的设备ID
是相同的。
下次再有出现相同设备ID
的,就可以怀疑对方是否使用了虚拟机啦。
五、结束语
喜欢Unity
的同学,不要忘记点击关注,如果有什么Unity
相关的技术难题,也欢迎留言或私信~
转载:https://blog.csdn.net/linxinfa/article/details/116998510