The following is only a partial implementation from a shared detection and is for technical studies only. At present, mature simulator detection generally consists of a combination of multiple schemes, including simulator specific files, hardware information, simulator attributes, etc.)

1. Check whether the IMSI ID of the emulator is 310260000000000

Specific implementation: Check whether you have the android.permission.READ_PHONE_STATE permission. Check whether the IMSI ID of the current operating environment is 310260000000000. Check whether VoiceMailNumbe equals to 15552175049 and GetDeviceId equals to “000000000000000” and “012345678912345”.


    private static boolean a(Context context, String str, String[] strArr, String str2) {
        boolean z;
        boolean z2;
        boolean z3;
        String[] strArr2;
        if (context.getPackageManager().checkPermission("android.permission.READ_PHONE_STATE", context.getPackageName()) == 0) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            z2 = false;
            for (String str3 : d) {
                if (z2 || StringUtils.equal(str3, str)) {
                    z2 = true;
                } else {
                    z2 = false; }}}else {
            z2 = false;
        }
        if(strArr ! =null) {
            for (String equal : strArr) {
                if (StringUtils.equal(equal, "310260000000000") || z2) {
                    z3 = true;
                } else {
                    z3 = false; }}}if (z2 || StringUtils.equal(str2, "15552175049")) {
            return true;
        }
        return false;
    }
Copy the code

2. Check the driver file content of the simulator

Check whether the /proc/tty/drivers file exists and can be read. In readable case, read and take out the specific content data to compare whether it contains a goldfish string



   private static String[] b = {"goldfish"};
private static Boolean a(a) {
        String str;
        File file = new File("/proc/tty/drivers");
        if(! file.exists() || ! file.canRead()) { String str2 ="EmulatorChecker";
            StringBuilder sb = new StringBuilder("can not read file /proc/tty/drivers ,because");
            if (file.exists()) {
                str = "not exist";
            } else {
                str = "not readable";
            }
            sb.append(str);
            Logger.e(str2, sb.toString());
        } else {
            byte[] bArr = new byte[1024];
            try {
                FileInputStream fileInputStream = new FileInputStream(file);
                fileInputStream.read(bArr);
                fileInputStream.close();
            } catch (Exception unused) {
            }
            String str3 = new String(bArr);
            for (String contains : b) {
                if (str3.contains(contains)) {
                    returnBoolean.TRUE; }}}return Boolean.FALSE;
    }
Copy the code

3. Detect specific files and file properties of the simulator

The specific steps are as follows: determine to read the specified file and file properties, and determine the unique Genymotion emulator that reads the mobile phone manufacturer using ro.product.manufacturer


 private static int a(h hVar) {
        int i;
        int i2;
        String[] strArr = {"/system/bin/qemu_props"."/system/bin/androVM-prop"."/system/bin/microvirt-prop"."/system/lib/libdroid4x.so"."/system/bin/windroyed"."/system/bin/microvirtd"."/system/bin/nox-prop"."/system/bin/ttVM-prop"."/system/bin/droid4x-prop"."/data/.bluestacks.prop"};
        String[] strArr2 = {"init.svc.vbox86-setup"."init.svc.droid4x"."init.svc.qemud"."init.svc.su_kpbs_daemon"."init.svc.noxd"."init.svc.ttVM_x86-setup"."init.svc.xxkmsg"."init.svc.microvirtd"."ro.kernel.android.qemud"."androVM.vbox_dpi"."androVM.vbox_graph_mode"};
        int i3 = 0;
        for (int i4 = 0; i4 < 10; i4++) {
            if (a(strArr[i4])) {
                i2 = 1 << i4;
            } else {
                i2 = 0;
            }
            i3 |= i2;
            a(strArr[i4]);
        }
        int i5 = 10;
        for (int i6 = 0; i6 < 11; i6++) {
            String str = strArr2[i6];
            if (StringUtils.isEmpty(hVar.a(str))) {
                i = 0;
            } else {
                i = 1 << i5;
            }
            i3 |= i;
            StringUtils.isEmpty(hVar.a(str));
            i5++;
        }
        Pair pair = new Pair("ro.product.manufacturer"."Genymotion");
        String a2 = hVar.a((String) pair.first);
        if(StringUtils.isEmpty(a2) || ! a2.contains((CharSequence) pair.second)) {return i3;
        }
        return i3 | (1 << i5);
    }

Copy the code

4. Check whether the specified device file exists

Determine whether the following three unique files exist



private static String[] c = {"/dev/socket/qemud"."/dev/qemu_pipe"."/dev/qemu_trace"};

 private static boolean a(String str) {
        if (StringUtils.isEmpty(str)) {
            return false;
        }
        File file = new File(str);
        if (file.exists()) {
            return true;
        }
        try {
            new FileInputStream(file);
            return true;
        } catch (FileNotFoundException e) {
            if(! e.getMessage().contains("No such file or directory")) {
                return true;
            }
            return false; }}Copy the code