回答问题
https://www.zhihu.com/question/494101361/answer/2212116525
2022年8月26日
09:51
很多app会检测是否真机运行环境,如何发现模拟器运行,很多是禁止使用
模拟器运行,所以经常会出现app在模拟器里面闪退.
要想解决这一问题,需要解决真机环境问题.
那么一般app如何判断是否模拟器运行呢,从技术角度非常容易解决.
参考一下的代码:
/**
* 验证当前设备是否为模拟器
*/
public class VerifyDevice {
public static booleanisSuccess = false;
/**
* 模拟器验证结果
*/
public static void verify() {
Context context =Application.getInstance();
if(notHasBlueTooth()){
isSuccess = true;
}else if(notHasLightSensorManager(context)){
isSuccess = true;
}else if(ifFeatures()){
isSuccess = true;
}else if(checkIsNotRealPhone()){
isSuccess = true;
/**
* 判断蓝牙是否有效
*/
private static booleannotHasBlueTooth(){
BluetoothAdapterbluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter== null){
return true;
}else{
//如果蓝牙不一定有效的。获取蓝牙名称,若为null则默认为模拟器
String name =bluetoothAdapter.getName();
if(TextUtils.isEmpty(name)){
return true;
}else{
return false;
/**
* 依据是否存在光传感器 来判断是否为模拟器
* @param context
* @return
*/
private static booleannotHasLightSensorManager(Context context){
SensorManagersensorManager = (SensorManager)context.getSystemService(context.SENSOR_SERVICE);
Sensor sensor =sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (sensor == null){
return true;
}else{
return false;
/**
* 根据部分特征参数设备信息来判断是否为模拟器
* @return
*/
private static booleanifFeatures(){
returnBuild.FINGERPRINT.startsWith("generic")
||Build.FINGERPRINT.toLowerCase().contains("vbox")
||Build.FINGERPRINT.toLowerCase().contains("test-keys")
||Build.MODEL.contains("google_sdk")
||Build.MODEL.contains("Emulator")
||Build.MODEL.contains("Android SDK built for x86")
||Build.MANUFACTURER.contains("Genymotion")
||(Build.BRAND.startsWith("generic")&& Build.DEVICE.startsWith("generic"))
||"google_sdk".equals(Build.PRODUCT);
/*
*根据CPU是否为电脑来判断是否为模拟器
*返回:true为模拟器
*/
private static booleancheckIsNotRealPhone() {
String cpuInfo =readCpuInfo();
if((cpuInfo.contains("intel") || cpuInfo.contains("amd"))){
return true;
return false;
/**
* 根据CPU是否为电脑来判断是否为模拟器
* @return
*/
private static StringreadCpuInfo(){
String result = "";
try{
String args ={"/system/bin/cat","/proc/cpuinfo"};
ProcessBuilderprocessBuilder = new ProcessBuilder(args);
Process process =processBuilder.start();
StringBufferstringBuffer = new StringBuffer();
String readLine ="";
BufferedReaderresponseReader = new BufferedReader(newInputStreamReader(process.getInputStream(), "utf-8"));
while ((readLine =responseReader.readLine())!=null){
stringBuffer.append(readLine);
responseReader.close();
result =stringBuffer.toString().toLowerCase();
} catch (IOExceptione) {
e.printStackTrace();
return result;
对于技术来说,判断是否模拟器运行很简单,那么如何去避免被app识别模拟器运行呢?
其实如果你会点逆向知识,就很容易破解真机环境问题,可以看到,app也是通过代码
读取底层的一些东西,一些变量,一些文件配置等等.
那么我们是否可以这样理解,修改了这些东西就可以很轻松的过了模拟器检测呢?
答案是肯定的.
通过工具修改后的模拟器,真实虚拟真机环境,遇到这样的模拟器,绝大部分的app检测方法都失效了.
有兴趣可以参考下这个视频:
https://www.zhihu.com/zvideo/1500070373152051200
比较详细的介绍 操作方法.
但是对于大型的app,比如微信,抖音之类的,判断就不是这么简单的了。
这些app还会获取以下的信息:
1:相关的一些手机硬件信息
比如CPU型号,GPU型号等等串码结合硬件信息判断是否一台真实手机。
2:手机通讯录
通过抓取通讯录,因为不同的手机,正常的手机,都会有通讯录,极少没有的。
3:通话记录,短信信息。
通过抓取短信,通话记录。判断是否一台真实手机,一般个人手机是有通话记录和短信