模拟器检验

  1. 属性检测
    1.  //判断当前设备是否是模拟器。如果返回TRUE,则当前是模拟器,不是返回FALSE
          public static boolean isEmulator(Context context){
              try{
                  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                  String imei = tm.getDeviceId();
                  if (imei != null && imei.equals("000000000000000")){
                      return true;
                  }
                  return  (Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"));//系统全局属性判断
              }catch (Exception ioe) {

              }
              return false;
          } 
                   其次,android各个os版本都有code name,模拟器中,属性BRANDDEVICE都是“generic”,Landroid/os/Build:->BRAND的值可以判断是否为模拟器;
          绕过方法:修改系统源码相应属性,重新编译;将判断模拟器的逻辑代码重新设计;
       2. 检测IMEI和IMSI,默认值分别为000000000000000(15个)和310260000000000
          需要申请android.permission.READ_PHONE_STATE权限
          TelephoneManager Tm=(TelephoneyManager)getSystemService(TELEPHONY_SERVICE);
          String imsi=Tm.getSubscriberId();
          String imei=Tm.getDeviceId();
          绕过方法:修改Android SDK下/tools/emulator-arm.exe文件,修改后保存

     


2.     虚拟文件检测
     模拟器中存在特殊文件或目录,如/system/bin/qemu-props(在模拟器中设置系统属性),/system/lib/libc_malloc_debug_qemu.so文件,/sys/qemu_trace目录等。

     private static String[] knwon_files={"/system/bin/qemu-props","/system/lib/libc_malloc_debug_qemu.so","/sys/qemu_trace"};
     
     public static boolean hasQEmuFiles(){
          for(String pipe: known_files){
               File qemu_file=new File(pipe);
               if(qemu_file.exists()){
                    return true;
         }
          return false;
     }
     参考资料:https://github.com/strazzere



3.     基于Cache行为的模拟器检测

posted @ 2014-08-30 10:53  徐小鱼  阅读(630)  评论(0编辑  收藏  举报