From 5c5240a2f3866d788a46a328d366da07b8a0e68a Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 7 Apr 2020 18:10:34 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20HWID=20=D0=B2=D0=BE=D0=B7=D0=B2?= =?UTF-8?q?=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=D1=81=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launchserver/socket/WebSocketService.java | 2 + .../secure/HardwareReportResponse.java | 20 +++++ .../gravit/launcher/utils/HWIDProvider.java | 81 +++++++++++++++++++ .../request/HardwareReportRequestEvent.java | 10 +++ .../request/secure/HardwareReportRequest.java | 22 +++++ .../websockets/ClientWebSocketService.java | 1 + 6 files changed, 136 insertions(+) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java create mode 100644 Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 00b1b1b7..6f0908f1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -22,6 +22,7 @@ import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; import pro.gravit.launchserver.socket.response.profile.ProfileByUsername; import pro.gravit.launchserver.socket.response.secure.GetSecureLevelInfoResponse; +import pro.gravit.launchserver.socket.response.secure.HardwareReportResponse; import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; import pro.gravit.launchserver.socket.response.secure.VerifySecureLevelKeyResponse; import pro.gravit.launchserver.socket.response.update.LauncherResponse; @@ -131,6 +132,7 @@ public static void registerResponses() { providers.register("getSecureLevelInfo", GetSecureLevelInfoResponse.class); providers.register("verifySecureLevelKey", VerifySecureLevelKeyResponse.class); providers.register("securityReport", SecurityReportResponse.class); + providers.register("hardwareReport", HardwareReportResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java new file mode 100644 index 00000000..83b87337 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java @@ -0,0 +1,20 @@ +package pro.gravit.launchserver.socket.response.secure; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class HardwareReportResponse extends SimpleResponse { + public String pathToJava; + public String javaVersion; + + @Override + public String getType() { + return "hardwareReport"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java new file mode 100644 index 00000000..3f8aa00d --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java @@ -0,0 +1,81 @@ +package pro.gravit.launcher.utils; + +import oshi.SystemInfo; +import oshi.hardware.HWDiskStore; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.hardware.PowerSource; +import oshi.software.os.OperatingSystem; +import pro.gravit.launcher.request.secure.HardwareReportRequest; + +public class HWIDProvider { + public SystemInfo systemInfo; + public OperatingSystem system; + public HardwareAbstractionLayer hardware; + public HWIDProvider() + { + systemInfo = new SystemInfo(); + system = systemInfo.getOperatingSystem(); + hardware = systemInfo.getHardware(); + } + //Statistic information + public int getBitness() + { + return system.getBitness(); + } + public long getTotalMemory() + { + return hardware.getMemory().getTotal(); + } + public long getProcessorMaxFreq() + { + return hardware.getProcessor().getMaxFreq(); + } + public int getProcessorPhysicalCount() + { + return hardware.getProcessor().getPhysicalProcessorCount(); + } + public int getProcessorLogicalCount() + { + return hardware.getProcessor().getLogicalProcessorCount(); + } + public boolean isBattery() + { + PowerSource[] powerSources = hardware.getPowerSources(); + return powerSources != null && powerSources.length != 0; + } + //Hardware Information + public String getHWDiskID() + { + HWDiskStore[] hwDiskStore = hardware.getDiskStores(); + long size = 0; + HWDiskStore maxStore = null; + for(HWDiskStore store : hwDiskStore) + { + if(store.getSize() > size) + { + maxStore = store; + size = store.getSize(); + } + } + if(maxStore != null) + { + return maxStore.getSerial(); + } + return null; + } + public HardwareReportRequest.HardwareInfo getHardwareInfo(boolean needSerial) + { + HardwareReportRequest.HardwareInfo info = new HardwareReportRequest.HardwareInfo(); + info.bitness = getBitness(); + info.logicalProcessors = getProcessorLogicalCount(); + info.physicalProcessors = getProcessorPhysicalCount(); + info.processorMaxFreq = getProcessorMaxFreq(); + info.totalMemory = getTotalMemory(); + info.battery = isBattery(); + if(needSerial) + { + info.hwDiskId = getHWDiskID(); + } + return info; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java new file mode 100644 index 00000000..7305eca8 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java @@ -0,0 +1,10 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class HardwareReportRequestEvent extends RequestEvent { + @Override + public String getType() { + return "hardwareReport"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java new file mode 100644 index 00000000..857d6c97 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java @@ -0,0 +1,22 @@ +package pro.gravit.launcher.request.secure; + +import pro.gravit.launcher.events.request.HardwareReportRequestEvent; +import pro.gravit.launcher.request.Request; + +public class HardwareReportRequest extends Request { + public HardwareInfo hardware; + @Override + public String getType() { + return "hardwareReport"; + } + + public static class HardwareInfo { + public int bitness; + public long totalMemory; + public int logicalProcessors; + public int physicalProcessors; + public long processorMaxFreq; + public boolean battery; + public String hwDiskId; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 4e74f253..0e50045c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -110,6 +110,7 @@ public void registerResults() { results.register("getSecureLevelInfo", GetSecureLevelInfoRequestEvent.class); results.register("verifySecureLevelKey", VerifySecureLevelKeyRequestEvent.class); results.register("securityReport", SecurityReportRequestEvent.class); + results.register("hardwareReport", HardwareReportRequestEvent.class); } public void waitIfNotConnected() {