[FEATURE] Проверка HWID

This commit is contained in:
Gravit 2020-04-07 19:05:58 +07:00
parent 925c1170a3
commit c438f08d7a
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 71 additions and 2 deletions

View file

@ -1,12 +1,12 @@
package pro.gravit.launchserver.socket.response.secure;
import io.netty.channel.ChannelHandlerContext;
import pro.gravit.launcher.request.secure.HardwareReportRequest;
import pro.gravit.launchserver.socket.Client;
import pro.gravit.launchserver.socket.response.SimpleResponse;
public class HardwareReportResponse extends SimpleResponse {
public String pathToJava;
public String javaVersion;
public HardwareReportRequest.HardwareInfo hardware;
@Override
public String getType() {

View file

@ -0,0 +1,48 @@
package pro.gravit.launcher.console.test;
import pro.gravit.launcher.utils.HWIDProvider;
import pro.gravit.utils.command.Command;
import pro.gravit.utils.helper.LogHelper;
public class PrintHardwareInfoCommand extends Command {
@Override
public String getArgsDescription() {
return "[]";
}
@Override
public String getUsageDescription() {
return "print your hardware info and timings";
}
@Override
public void invoke(String... args) throws Exception {
LogHelper.info("Your Hardware ID:");
long startTime = System.currentTimeMillis();
long currentTime;
HWIDProvider provider = new HWIDProvider();
currentTime = System.currentTimeMillis();
LogHelper.info("Create HWIDProvider instance: %d ms", currentTime - startTime);
startTime = System.currentTimeMillis();
int bitness = provider.getBitness();
long totalMemory = provider.getTotalMemory();
boolean isBattery = provider.isBattery();
currentTime = System.currentTimeMillis();
LogHelper.info("Bitness: %d, totalMemory: %d(%.3f GB), battery %s, TIME: %d ms", bitness, totalMemory, (double)totalMemory / (1024.0*1024.0*1024.0), Boolean.toString(isBattery), currentTime - startTime);
startTime = System.currentTimeMillis();
int logicalProcessors = provider.getProcessorLogicalCount();
int physicalProcessors = provider.getProcessorPhysicalCount();
long processorMaxFreq = provider.getProcessorMaxFreq();
currentTime = System.currentTimeMillis();
LogHelper.info("Processors || logical: %d physical %d freq %d, TIME: %d ms", logicalProcessors, physicalProcessors, processorMaxFreq, currentTime - startTime);
startTime = System.currentTimeMillis();
String hwDiskID = provider.getHWDiskID();
currentTime = System.currentTimeMillis();
LogHelper.info("HWDiskID %s, TIME: %d ms", hwDiskID, currentTime - startTime);
startTime = System.currentTimeMillis();
String baseboardSerial = provider.getBaseboardSerialNumber();
currentTime = System.currentTimeMillis();
LogHelper.info("BaseboardSerial %s, TIME: %d ms", baseboardSerial, currentTime - startTime);
LogHelper.info("Hardware ID end");
}
}

View file

@ -4,6 +4,7 @@
import pro.gravit.launcher.LauncherEngine;
import pro.gravit.launcher.client.events.ClientUnlockConsoleEvent;
import pro.gravit.launcher.console.UnlockCommand;
import pro.gravit.launcher.console.test.PrintHardwareInfoCommand;
import pro.gravit.utils.command.CommandHandler;
import pro.gravit.utils.command.JLineCommandHandler;
import pro.gravit.utils.command.StdCommandHandler;
@ -44,6 +45,7 @@ public static void registerCommands() {
handler.registerCommand("gc", new GCCommand());
handler.registerCommand("clear", new ClearCommand(handler));
handler.registerCommand("unlock", new UnlockCommand());
handler.registerCommand("printhardware", new PrintHardwareInfoCommand());
}
public static boolean checkUnlockKey(String key) {

View file

@ -1,6 +1,7 @@
package pro.gravit.launcher.utils;
import oshi.SystemInfo;
import oshi.hardware.Display;
import oshi.hardware.HWDiskStore;
import oshi.hardware.HardwareAbstractionLayer;
import oshi.hardware.PowerSource;
@ -63,6 +64,20 @@ public String getHWDiskID()
}
return null;
}
public byte[] getDisplayID()
{
Display[] displays = hardware.getDisplays();
if(displays == null || displays.length == 0) return null;
for(Display display : displays)
{
return display.getEdid();
}
return null;
}
public String getBaseboardSerialNumber()
{
return hardware.getComputerSystem().getBaseboard().getSerialNumber();
}
public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
{
HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo();
@ -75,6 +90,8 @@ public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial)
if(needSerial)
{
info.hwDiskId = getHWDiskID();
info.displayId = getDisplayID();
info.baseboardSerialNumber = getBaseboardSerialNumber();
}
return info;
}

View file

@ -18,5 +18,7 @@ public static class HardwareInfo {
public long processorMaxFreq;
public boolean battery;
public String hwDiskId;
public byte[] displayId;
public String baseboardSerialNumber;
}
}