Android如何区别真机和模拟器

来源:互联网 发布:软件规模度量单位 编辑:程序博客网 时间:2024/04/25 08:10


发布时间: 2015/06/03 11:50 阅读: 3805 收藏: 27

                       

现在的模拟器的功能太强大,从蓝牙,传感器等配件到IMEI,Mac,以及手机硬件信息什么都可以模拟

为了防止用户利用模拟器模仿真机进行刷单,刷流量等恶意操作

需要获取设备返回的一些信息来鉴别设备的真伪。

下面是整理的模拟器和真机的区别

虽然大部分都可以模仿,伪造,但是如果综合所有维度来监控,应该不存在太大问题。


一,native方式。

通过c代码读取设备中的配置和硬件相关信息。


1,diskstats

获取闪存的分区状态信息。

int fd = open(“/proc/diskstats”, O_RDONLY);

bytes = read(fd, buf, bytes);

区别:真机下都有mmcblk0分区,但是模拟器没有分区信息。


2,mac地址。

通过socket和ioctl读取mac地址。

sockfd = socket(AF_INET, SOCK_DGRAM, 0);

ioctl(sockfd, SIOCGIFCONF, (char*)&ifc);

ioctl(sockfd, SIOCGIFADDR, &ifr[i])

ioctl(sockfd, SIOCGIFHWADDR, (char*)&ifr[i])


区别:真机可以获取wlan0的ip和mac地址,模拟器只能获取eth0的ip和mac地址;


3,有用的prop信息。

__system_property_get(key, buf);

区别: 模拟器没有ro.boot.serialno和ro.serialno属性,真机中为机器序列号。

模拟器 ro.hardware属性为goldfish,真机为各自的型号。


4,cpu信息。

int fd = open(“/proc/cpuinfo”, O_RDONLY);

bytes = read(fd, buf, bytes);

区别:模拟器中cpuinfo的硬件为Goldfish。


5,drivers

int fd = open(“/proc/tty/drivers”, O_RDONLY);

区别:模拟器中包含goldfish的驱动

 

6,模拟器特有文件。

int fd = open(“/dev/socket/qemud”, O_RDONLY);

int fd = open(“/dev/qemu_pipe”, O_RDONLY);

区别:模拟器专有的文件,真机中没有。


二,传统的方式:

通过Java层的代码获取,可以有以下方式:


1,IMEI和IMSI

IMEI  移动设备国际身份码。

IMSI  IMSI国际移动用户识别码,储存在SIM卡中

final TelephonyManager tm = (TelephonyManager) getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

String imei = tm.getDeviceId();

String imsi = tm.getSubscriberId();


设备1:354273055927169 / null(无卡)

设备2:862966024243759 / 460011040618938

模拟器:000000000000000 / 310260000000000


2,Serial序列号

String serial = android.os.Build.SERIAL;


设备1:4df78680771b117b

设备2:OBAI5HDQZPDIRCQG

模拟器:unknown


3,android_id

String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

设备和模拟器都有,16位。


4,Mac地址

WifiManager wifimanage=(WifiManager)getSystemService(Context.WIFI_SERVICE);  WifiInfo wifiinfo= wifimanage.getConnectionInfo();

设备1:88:32:9b:1e:49:20

设备2:f8:a4:5f:fd:56:17

模拟器:null

1 1
原创粉丝点击