How Android distinguishes between Real-computer and simulator
Source: Internet
Author: User
<span id="Label3"></p><p><p>Now the simulator is too powerful, from bluetooth, sensors and other accessories to imei,mac, as well as mobile phone hardware information can be simulated</p></p><p><p>In order to prevent users from using simulator simulation machine to brush a single, brush traffic and other malicious operations</p></p><p><p>Need to obtain some information returned by the device to identify the authenticity of the Device.</p></p><p><p>Here is the difference between a sorted simulator and a real machine</p></p><p><p>Although most can be imitated, forged, but if all dimensions are integrated to monitor, there should be no big problem.</p></p><p><p><br></p></p><p><p>one, native Way.</p></p><p><p>Read the configuration and hardware-related information in the device through the C Code.</p></p><p><p><br></p></p><p><p>1,diskstats</p></p><p><p>Gets the partition state information for the Flash.</p></p><p><p>int fd = Open ("/proc/diskstats", o_rdonly);</p></p><p><p>bytes = Read (fd, buf, bytes);</p></p><p><p>Difference: there are mmcblk0 partitions on the real machine, but the simulator has no partition Information.</p></p><p><p><br></p></p><p><p>2,mac Address.</p></p><p><p>Read the MAC address through the socket and the Ioctl.</p></p><p><p>SOCKFD = socket (af_inet, sock_dgram, 0);</p></p><p><p>IOCTL (sockfd, siocgifconf, (char*) &ifc);</p></p><p><p>IOCTL (sockfd, siocgifaddr, &ifr[i])</p></p><p><p>IOCTL (sockfd, siocgifhwaddr, (char*) &ifr[i])</p></p><p><p><br></p></p><p><p>Difference: the real machine can get wlan0 IP and Mac address, the simulator can only get eth0 IP and Mac address;</p></p><p><p><br></p></p><p><p>3, Useful prop Information.</p></p><p><p>__system_property_get (key, buf);</p></p><p><p>Difference: the simulator does not have the Ro.boot.serialno and Ro.serialno properties, the machine serial number in the real machine.</p></p><p><p>The simulator Ro.hardware property is goldfish and the real machine is the respective model.</p></p><p><p><br></p></p><p><p>4,cpu Information.</p></p><p><p>int fd = Open ("/proc/cpuinfo", o_rdonly);</p></p><p><p>bytes = Read (fd, buf, bytes);</p></p><p><p>Difference: the Cpuinfo hardware in the simulator is Goldfish.</p></p><p><p><br></p></p><p><p>5,drivers</p></p><p><p>int fd = Open ("/proc/tty/drivers", o_rdonly);</p></p><p><p>Difference: the simulator contains goldfish drivers</p></p><p><p></p></p><p><p>6, simulator-specific Files.</p></p><p><p>int fd = Open ("/dev/socket/qemud", o_rdonly);</p></p><p><p>int fd = Open ("/dev/qemu_pipe", o_rdonly);</p></p><p><p>The Difference: emulator proprietary files, not in the real machine.</p></p><p><p><br></p></p><p><p>two, the traditional way:</p></p><p><p>It can be obtained from Java layer code in the following ways:</p></p><p><p><br></p></p><p><p>1,imei and IMSI</p></p><p><p>IMEI Mobile Device International identification Code.</p></p><p><p>IMSI IMSI International Mobile subscriber id, stored in SIM card</p></p><p><p>Final Telephonymanager TM = (telephonymanager) getbasecontext (). getsystemservice (context.telephony_service);</p></p><p><p>String IMEI = Tm.getdeviceid ();</p></p><p><p>String IMSI = Tm.getsubscriberid ();</p></p><p><p><br></p></p><p><p>Device 1:354273055927169/null (no Card)</p></p><p><p>Equipment 2:862966024243759/460011040618938</p></p><p><p>Simulator: 000000000000000/310260000000000</p></p><p><p><br></p></p><p><p>2,serial Serial Number</p></p><p><p>String serial = android.os.Build.SERIAL;</p></p><p><p><br></p></p><p><p>Equipment 1:4df78680771b117b</p></p><p><p>Equipment 2:OBAI5HDQZPDIRCQG</p></p><p><p>Simulator: Unknown</p></p><p><p><br></p></p><p><p>3,android_id</p></p><p><p>String android_id = secure.getstring (getcontentresolver (), secure.android_id);</p></p><p><p>Devices and simulators are available, 16-bit.</p></p><p><p><br></p></p><p><p>4,mac Address</p></p><p><p>Wifimanager wifimanage= (wifimanager) Getsystemservice (context.wifi_service); Wifiinfo wifiinfo= Wifimanage.getconnectioninfo ();</p></p><p><p>Equipment 1:88:32:9B:1E:49:20</p></p><p><p>Equipment 2:f8:a4:5f:fd:56:17</p></p><p><p>Emulator: NULL</p></p><p><p><br></p></p><p><p>How Android distinguishes between Real-computer and simulator</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service