From cd4e89dc15dd3dfe66f0c79b7b49f4d45fe97fb4 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 16 Oct 2019 22:40:36 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=91=D0=B0=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20HWID=20=D0=BD=D0=B0=20=D0=BB=D0=B6=D0=B8=D0=B2=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/dao/UserHWID.java | 10 +-- .../java/pro/gravit/launcher/hwid/HWID.java | 5 +- .../gravit/launcher/hwid/HWIDCheckHelper.java | 71 +++++++++++++++++++ .../java/pro/gravit/launcher/hwid/NoHWID.java | 14 ++-- .../pro/gravit/launcher/hwid/OshiHWID.java | 38 +++++++--- 5 files changed, 118 insertions(+), 20 deletions(-) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java index d81dddf3..db0b8846 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserHWID.java @@ -41,11 +41,6 @@ public OshiHWID toHWID() return oshi; } - @Override - public String getSerializeString() { - return toHWID().getSerializeString(); - } - @Override public int getLevel() { return toHWID().getLevel(); @@ -60,4 +55,9 @@ public int compare(HWID hwid) { public boolean isNull() { return toHWID().isNull(); } + + @Override + public void normalize() { + + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java index 32616752..b107e716 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWID.java @@ -1,11 +1,14 @@ package pro.gravit.launcher.hwid; public interface HWID { - String getSerializeString(); int getLevel(); //Уровень доверия, насколько уникальные значения + int getAntiLevel(); //Уровень лживости, насколько фальшивые значения + int compare(HWID hwid); boolean isNull(); + + void normalize(); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java new file mode 100644 index 00000000..79052ed7 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/HWIDCheckHelper.java @@ -0,0 +1,71 @@ +package pro.gravit.launcher.hwid; + +public class HWIDCheckHelper { + public static int checkString(String str) + { + int result = 0; + //Считаем символы + char lastChar = '\0'; + int combo = 0; + int maxCombo = 0; + //Считаем род символов + int lastCharType = -1; + int lastCharTypeCombo = 0; + int wtfCharTypeCombo = 0; + boolean skipLastCharType = true; + for(char c : str.toCharArray()) + { + if(c == lastChar || Math.abs(c - lastChar) == 1 || + ( ( lastChar == '0' || lastChar == '9' ) && ( c == 'A' || c == 'a' ))) //Переход с 0 или 9 на A или a + { + lastChar = c; + combo++; + } + else + { + if(maxCombo < combo) + maxCombo = combo; + lastChar = c; + combo = 1; + } + int charType = getCharType(c); + if(lastCharType == charType) { + lastCharTypeCombo++; + //Нам подсунули серию из идущих подряд спец символов. Что за? + if((charType == -1 || charType == 3) && lastCharTypeCombo > 2) + { + wtfCharTypeCombo+=3; + } + //Нам подсунули серию из слишком большого числа идущих подряд чисел. Что за? + if((charType == 0) && lastCharTypeCombo > 4) + { + wtfCharTypeCombo++; + } + } + else + { + if(skipLastCharType && ( charType == -1 || charType == 3 )) + { + skipLastCharType = false; + } + else + { + skipLastCharType = true; + lastCharType = charType; + } + } + } + //Считаем результат + if(maxCombo > 3) result+= maxCombo * 3; + if(wtfCharTypeCombo > 1) result+= wtfCharTypeCombo * 2; + return result; + } + public static int getCharType(char c) + { + if(c >= '0' && c <= '9') return 0; + if(c >= 'A' && c <= 'Z') return 1; + if(c >= 'a' && c <= 'z') return 2; + if(c == ' ' || c == '-' || c == '_') return 3; + return -1; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java index d03c1d82..853ec6e2 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/NoHWID.java @@ -1,16 +1,17 @@ package pro.gravit.launcher.hwid; public class NoHWID implements HWID { - @Override - public String getSerializeString() { - return ""; - } @Override public int getLevel() { return 0; } + @Override + public int getAntiLevel() { + return 0; + } + @Override public int compare(HWID hwid) { return 0; @@ -20,4 +21,9 @@ public int compare(HWID hwid) { public boolean isNull() { return true; } + + @Override + public void normalize() { + //Skip + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java index a3f36dac..3d0656a7 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/hwid/OshiHWID.java @@ -20,23 +20,23 @@ public class OshiHWID implements HWID { @LauncherAPI public String macAddr; - @Override - public String getSerializeString() { - return gson.toJson(this); - } - @Override public int getLevel() //Уровень доверия, насколько уникальные значения { int result = 0; - if (totalMemory != 0) result += 8; - if (serialNumber != null && !serialNumber.equals("unknown")) result += 12; - if (HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result += 30; - if (processorID != null && !processorID.equals("unknown")) result += 10; - if (macAddr != null && !macAddr.equals("00:00:00:00:00:00")) result += 15; + if (totalMemory != 0) result += 32; + if (serialNumber != null) result += isRealSerialNumber() ? 20 : 3; + if (HWDiskSerial != null && !HWDiskSerial.isEmpty()) result += 38; + if (processorID != null && !processorID.isEmpty()) result += 20; + if (macAddr != null && !macAddr.isEmpty()) result += 25; return result; } + @Override + public int getAntiLevel() { + return HWIDCheckHelper.checkString(serialNumber) + HWIDCheckHelper.checkString(HWDiskSerial); + } + @Override public int compare(HWID hwid) { if (hwid instanceof OshiHWID) { @@ -58,6 +58,24 @@ public boolean isNull() { return getLevel() < 15; } + @Override + public void normalize() { + HWDiskSerial = HWDiskSerial.trim(); + serialNumber = serialNumber.trim(); + processorID = processorID.trim(); + macAddr = macAddr.trim(); + } + public boolean isRealSerialNumber() + { + if(serialNumber.isEmpty()) return false; + if(serialNumber.equals("System Serial Number")) return false; + if(serialNumber.equals("To be filled by O.E.M.")) return false; + if(serialNumber.equals("unknown")) return false; + if(serialNumber.equals("None")) return false; + if(serialNumber.equals("Default string")) return false; + return true; + } + @Override public boolean equals(Object o) { if (this == o) return true;