[FEATURE] HWID возвращается

This commit is contained in:
Gravit 2020-04-07 18:10:34 +07:00
parent 43a43ec30d
commit 5c5240a2f3
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
6 changed files with 136 additions and 0 deletions

View file

@ -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) {

View file

@ -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 {
}
}

View file

@ -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;
}
}

View file

@ -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";
}
}

View file

@ -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<HardwareReportRequestEvent> {
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;
}
}

View file

@ -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() {