mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] Базовые проверки HWID на лживость
This commit is contained in:
parent
f0a235f12c
commit
cd4e89dc15
5 changed files with 118 additions and 20 deletions
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue