飞道的博客

安装两个虚拟机只为验证一个猜测,结果不出所料(Unity | deviceUniqueIdentifier | 设备ID相同)

523人阅读  评论(0)

一、前言

嗨,大家好,我是新发。
项目发布了Windows平台的版本,运行过程中发现有部分玩家的设备ID是相同的。
莫非这些玩家破解了代码,篡改了获取设备ID的逻辑,使之相同。

没理由,如果是为了刷号,正常是修改成不同的设备ID才对。
直觉告诉我,问题可能是虚拟机,如果我安装两个虚拟机,那么这两个虚拟机的设备ID是一样的吗?好奇心驱使我做了下面的实验。

二、Unity获取设备ID

Unity官方提供了SystemInfo类,方便开发者获取系统信息,其中就包括我们说的设备标识符,也就设备IDSystemInfo.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

可以看到我的电脑的设备IDf54dd0ef5a143be2fb44a65178603d0b37e126aa

关于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
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场