本帖最后由 027rainguai 于 2023-6-21 18:01 编辑
String iMei = DeviceInfoUtils.getIMEI(getContext());
if (!TextUtils.isEmpty(iMei)) {
this.iMei = DeviceInfoUtils.getIMEI(getContext());
} else {
this.iMei = "000000000000000";
}
String uniqueID = DeviceInfoUtils.getDeviceId(getContext());
让后把 iMei 和 uniqueID 显示在界面上
某软件里面根据设备码来做授权验证,上面是 uniqueID 获取方法。 提取出来,打包到一个新apk 结果,和原来安装的那个需要破解的apk,获取到的不一致。这是个什么情况。
附上抽取出来的工具类
[Plain Text] 纯文本查看 复制代码
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.bumptech.glide.load.Key;
import java.security.MessageDigest;
import java.util.Locale;
import java.util.UUID;
public class DeviceInfoUtils {
public static String getDeviceManufacturer() {
return Build.MANUFACTURER;
}
public static String getDeviceProduct() {
return Build.PRODUCT;
}
public static String getDeviceBrand() {
return Build.BRAND;
}
public static String getDeviceModel() {
return Build.MODEL;
}
public static String getDeviceBoard() {
return Build.BOARD;
}
public static String getDeviceDevice() {
return Build.DEVICE;
}
public static String getDeviceFubgerprint() {
return Build.FINGERPRINT;
}
public static String getDeviceHardware() {
return Build.HARDWARE;
}
public static String getDeviceHost() {
return Build.HOST;
}
public static String getDeviceDisplay() {
return Build.DISPLAY;
}
public static String getDeviceId() {
return Build.ID;
}
public static String getDeviceUser() {
return Build.USER;
}
public static String getDeviceSerial() {
return Build.SERIAL;
}
public static int getDeviceSDK() {
return Build.VERSION.SDK_INT;
}
public static String getDeviceAndroidVersion() {
return Build.VERSION.RELEASE;
}
public static String getDeviceDefaultLanguage() {
return Locale.getDefault().getLanguage();
}
public static String getDeviceManufacturers() {
return Build.MANUFACTURER;
}
public static String getDeviceName() {
return Build.DEVICE;
}
public static String getModelName() {
return Build.MODEL;
}
public static double getPingMuSize(Context context) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
double sqrt = Math.sqrt(Math.pow(displayMetrics.widthPixels, 2.0d) + Math.pow(displayMetrics.heightPixels, 2.0d));
double d = displayMetrics.density * 160.0f;
Double.isNaN(d);
return sqrt / d;
}
public static String getDeviceAllInfo(Context context) {
return "\n\n1. IMEI:\n\t\t" + getIMEI(context) + "\n\n10. 系统默认语言:\n\t\t" + getDeviceDefaultLanguage() + "\n\n11. 硬件序列号(设备名):\n\t\t" + Build.SERIAL + "\n\n12. 手机型号:\n\t\t" + Build.MODEL + "\n\n13. 生产厂商:\n\t\t" + Build.MANUFACTURER + "\n\n14. 手机Fingerprint标识:\n\t\t" + Build.FINGERPRINT + "\n\n15. Android 版本:\n\t\t" + Build.VERSION.RELEASE + "\n\n16. Android SDK版本:\n\t\t" + Build.VERSION.SDK_INT + "\n\n17. 安全patch 时间:\n\t\t" + Build.VERSION.SECURITY_PATCH + "\n\n19. 版本类型:\n\t\t" + Build.TYPE + "\n\n20. 用户名:\n\t\t" + Build.USER + "\n\n21. 产品名:\n\t\t" + Build.PRODUCT + "\n\n22. ID:\n\t\t" + Build.ID + "\n\n23. 显示ID:\n\t\t" + Build.DISPLAY + "\n\n24. 硬件名:\n\t\t" + Build.HARDWARE + "\n\n25. 产品名:\n\t\t" + Build.DEVICE + "\n\n26. Bootloader:\n\t\t" + Build.BOOTLOADER + "\n\n27. 主板名:\n\t\t" + Build.BOARD + "\n\n28. CodeName:\n\t\t" + Build.VERSION.CODENAME;
}
public static String getDeviceId(Context context) {
StringBuilder sb = new StringBuilder();
String imei = getIMEI(context);
String androidId = getAndroidId(context);
String serial = getSERIAL();
String replace = getDeviceUUID().replace("-", "");
if (imei != null && imei.length() > 0) {
sb.append(imei);
sb.append("|");
}
if (androidId != null && androidId.length() > 0) {
sb.append(androidId);
sb.append("|");
}
if (serial != null && serial.length() > 0) {
sb.append(serial);
sb.append("|");
}
if (replace != null && replace.length() > 0) {
sb.append(replace);
}
if (sb.length() > 0) {
try {
String bytesToHex = bytesToHex(getHashByString(sb.toString()));
if (bytesToHex != null) {
if (bytesToHex.length() > 0) {
return bytesToHex;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
return UUID.randomUUID().toString().replace("-", "");
}
public static String getIMEI(Context context) {
try {
return ((TelephonyManager) context.getSystemService("phone")).getDeviceId();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private static String getAndroidId(Context context) {
try {
return Settings.Secure.getString(context.getContentResolver(), "android_id");
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private static String getSERIAL() {
try {
return Build.SERIAL;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private static String getDeviceUUID() {
try {
return new UUID(("3991986" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10) + (Build.DEVICE.length() % 10) + (Build.HARDWARE.length() % 10) + (Build.ID.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10) + (Build.SERIAL.length() % 10)).hashCode(), Build.SERIAL.hashCode()).toString();
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
private static byte[] getHashByString(String str) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
messageDigest.reset();
messageDigest.update(str.getBytes(Key.STRING_CHARSET_NAME));
return messageDigest.digest();
} catch (Exception unused) {
return "".getBytes();
}
}
private static String bytesToHex(byte[] bArr) {
StringBuilder sb = new StringBuilder();
for (byte b : bArr) {
String hexString = Integer.toHexString(b & 255);
if (hexString.length() == 1) {
sb.append("0");
}
sb.append(hexString);
}
return sb.toString().toUpperCase(Locale.CHINA);
}
}
|