diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 2d0d3d86..71d630df 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -18,6 +18,7 @@ import java.security.spec.InvalidKeySpecException; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -245,12 +246,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static class PostBuildTransformConf extends ConfigObject { public final boolean enabled; - public String script; + public List script; private PostBuildTransformConf(BlockConfigEntry block, Path coredir) { super(block); enabled = block.getEntryValue("enabled", BooleanConfigEntry.class); - script = enabled && block.hasEntry("script") ? block.getEntryValue("script", StringConfigEntry.class) : null; + script = new ArrayList<>(1); + if (block.hasEntry("script")) + block.getEntry("script", ListConfigEntry.class).stream(StringConfigEntry.class).forEach(script::add); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index 49a9fa70..676b3aca 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -24,7 +24,7 @@ public class MysqlHWIDHandler extends HWIDHandler { private final String banMessage; private final String isBannedName; private final String loginName; - private final String hwidName, cpuName, biosName; + private final String hwidName; private final String[] queryParams; private final String queryUpd; private final String[] queryParamsUpd; @@ -49,10 +49,6 @@ public MysqlHWIDHandler(BlockConfigEntry block) { banMessage = block.hasEntry("banMessage") ? block.getEntryValue("banMessage", StringConfigEntry.class) : "You HWID Banned"; hwidName = VerifyHelper.verify(block.getEntryValue("hwidName", StringConfigEntry.class), VerifyHelper.NOT_EMPTY, "hwidName can't be empty"); - cpuName = VerifyHelper.verify(block.getEntryValue("cpuName", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "cpuName can't be empty"); - biosName = VerifyHelper.verify(block.getEntryValue("biosName", StringConfigEntry.class), - VerifyHelper.NOT_EMPTY, "biosName can't be empty"); queryUpd = VerifyHelper.verify(block.getEntryValue("queryUpd", StringConfigEntry.class), VerifyHelper.NOT_EMPTY, "MySQL queryUpd can't be empty"); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index 213f20da..88d60a66 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -7,11 +7,12 @@ import java.io.IOException; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -import java.util.StringTokenizer; -import java.util.jar.JarFile; import java.util.Map.Entry; +import java.util.jar.JarFile; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipInputStream; @@ -69,6 +70,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO } } + // TODO: new native security wrapper and library... @SuppressWarnings("unused") private final class GuardDirVisitor extends SimpleFileVisitor { private final ZipOutputStream output; @@ -187,15 +189,12 @@ public void build() throws IOException { } private void transformedBuild() throws IOException { - String cmd = CommonHelper.replace(server.config.buildPostTransform.script, "launcher-output", IOHelper.toAbsPathString(syncBinaryFile), "launcher-obf", IOHelper.toAbsPathString(obfOutJar), "launcher-nonObf", IOHelper.toAbsPathString(binaryFile)); + List cmd = new ArrayList<>(1); + server.config.buildPostTransform.script.forEach(v -> CommonHelper.replace(v, "launcher-output", IOHelper.toAbsPathString(syncBinaryFile), "launcher-obf", IOHelper.toAbsPathString(obfJar), "launcher-nonObf", IOHelper.toAbsPathString(binaryFile))); ProcessBuilder builder = new ProcessBuilder(); builder.directory(IOHelper.toAbsPath(server.dir).toFile()); builder.inheritIO(); - StringTokenizer st = new StringTokenizer(cmd); - String[] cmdarray = new String[st.countTokens()]; - for (int i = 0; st.hasMoreTokens(); i++) - cmdarray[i] = st.nextToken(); - builder.command(cmdarray); + builder.command(cmd); Process proc = builder.start(); try { LogHelper.debug("Transformer process return code: " + proc.waitFor()); @@ -297,6 +296,7 @@ public void tryUnpackRuntime() throws IOException { // Unpack launcher guard files Files.createDirectory(runtimeDir); LogHelper.info("Unpacking launcher runtime files"); + if (Launcher.class.getResource("/runtime.zip") == null) return; try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("runtime.zip"))) { for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { if (entry.isDirectory()) @@ -316,6 +316,7 @@ public void tryUnpackGuard() throws IOException { // Unpack launcher guard files Files.createDirectory(guardDir); LogHelper.info("Unpacking launcher native guard files"); + if (Launcher.class.getResource("/guard.zip") == null) return; try (ZipInputStream input = IOHelper.newZipInput(IOHelper.getResourceURL("guard.zip"))) { for (ZipEntry entry = input.getNextEntry(); entry != null; entry = input.getNextEntry()) { if (entry.isDirectory()) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index aa3f2612..093f9b26 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -20,7 +20,6 @@ import ru.gravit.launcher.serialize.signed.SignedObjectHolder; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; -import ru.gravit.launcher.HWID; import ru.gravit.launchserver.auth.hwid.HWIDException; import ru.gravit.launchserver.auth.provider.AuthProvider; import ru.gravit.launchserver.auth.provider.AuthProviderResult; diff --git a/LaunchServer/src/main/resources/guard.zip b/LaunchServer/src/main/resources/guard.zip deleted file mode 100644 index c2d3f43e..00000000 Binary files a/LaunchServer/src/main/resources/guard.zip and /dev/null differ diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg index 4eb24654..fa9dba4d 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg @@ -42,10 +42,10 @@ textureProviderConfig: { cloaksURL: "http://skins.minecraft.net/MinecraftCloaks/%username%.png"; }; -# Jar signing +# Build operation buildExtendedOperation: { enabled: false; - script: "java -jar myTransformer.jar %launcher-obf% %launcher-output% %launcher-nonObf%"; + script: []; }; # Binaries name diff --git a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg index 56240dcb..c08bbda3 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg @@ -14,17 +14,14 @@ -overloadaggressively -repackageclasses 'ru.gravit.launcher' --keep class ru.zaxar163.* --keep class cpw.mods.fml.* --keep class net.minecraftforge.fml.* -keepattributes SourceFile,LineNumberTable,*Annotation* -renamesourcefileattribute SourceFile -keepattributes Signature -adaptresourcefilecontents META-INF/MANIFEST.MF --keeppackagenames com.eclipsesource.json.**,com.mojang.**,org.apache.**,com.google.gson.** +-keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,oshi.**,com.sun.jna.**,com.google.gson.** --keep class com.mojang.**,org.apache.**,com.google.gson.**,com.eclipsesource.json.** { +-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,oshi.**,com.sun.jna.**,com.google.gson.**,org.slf4j.**,oshi.jna.**,com.sun.jna.** { *; } diff --git a/Launcher/runtime/dialog/overlay/update/update.js b/Launcher/runtime/dialog/overlay/update/update.js index 98182596..4fa29a64 100644 --- a/Launcher/runtime/dialog/overlay/update/update.js +++ b/Launcher/runtime/dialog/overlay/update/update.js @@ -77,9 +77,8 @@ function offlineUpdateRequest(dirName, dir, matcher, digest) { return; } - // Verify dir with matcher using ClientLauncher's API - ClientLauncher.verifyHDir(dir, hdir.object, matcher, digest); - return hdir; + // Verify dir with matcher using FunctionalBridge`s API + return FunctionalBridge.offlineUpdateRequest(dir, hdir, matcher, digest).run(); }; } diff --git a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java index 2c78dcfc..af7d307f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/ru/gravit/launcher/LauncherEngine.java @@ -215,7 +215,7 @@ public void start(String... args) throws Throwable { Launcher.modulesManager.initModules(); // Load init.js script FunctionalBridge.worker = new RequestWorker(); - CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker); + CommonHelper.newThread("FX Task Worker", true, FunctionalBridge.worker).start(); loadScript(Launcher.API_SCRIPT_FILE); loadScript(Launcher.CONFIG_SCRIPT_FILE); LogHelper.debug("Dir: %s", DirBridge.dir); diff --git a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java index 992b78e7..b66d316a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java +++ b/Launcher/src/main/java/ru/gravit/launcher/RequestWorker.java @@ -13,6 +13,7 @@ public RequestWorker() public BlockingQueue queue; @Override public void run() { + LogHelper.debug("FX Task Thread start"); while (!Thread.interrupted()) { try { @@ -24,5 +25,6 @@ public void run() { return; } } + LogHelper.debug("FX Task Thread done"); } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 08a5dd74..6a1ff33f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -546,7 +546,7 @@ public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, matcher = matcher.verifyOnly(); // Hash directory and compare (ignore update-only matcher entries, it will break offline-mode) - HashedDir currentHDir = new HashedDir(dir, matcher, false, digest); + HashedDir currentHDir = new HashedDir(dir, matcher, true, digest); if (!hdir.diff(currentHDir, matcher).isSame()) throw new SecurityException(String.format("Forbidden modification: '%s'", IOHelper.getFileName(dir))); } @@ -554,81 +554,3 @@ public static void verifyHDir(Path dir, HashedDir hdir, FileNameMatcher matcher, private ClientLauncher() { } } - -// It's here since first commit, there's no any reasons to remove :D -// ++oyyysssssssssssooooooo++++++++/////:::::-------------................----:::----::+osssso+///+++++ooys/:/+ssssyyssyooooooo+++////:::::::::-::///++ossyhdddddddhhys/----::::::::::::::/://////////// -// ++oyyssssssssssoooooooo++++++++//////:::::--------------------------------:::::-:::/+oo+//://+oo+//syysssssyyyyyhyyyssssssoo+++///::--:----:--:://++osyyhdddmddmdhys/------::::::::::::::://///////// -// ++syyssssssssssoooooooo++++++++///////:::::::::::::::-----------------------::--::/++++/:--::/+++//osysshhhhyhhdyyyyyssyssoo++//::-------------::/+++oyhyhdddmddmdhy+--------:::::::::::::::///////// -// ++ssssssssssssooooooooo++++++///////::::::::-------------------------------------::/+//:----://+//+oyhhhddhhdhhhyhyyyyhysoo+//::----------------://++oshhhhmddmddmhhs:---------::::::::::::::://///// -// ++sssssssssssooooooooo++++////::::::::::------------------------------------:---:::///:-----://++osyhddddhdddhhhhhyyhdysso+/::-------------------://+ooyhhddmddmdmdhy/----------:::::::::::::::////// -// ++sssssssssoooooooo+++////::::::::::-------------------------------------::///::::///::--::/++osyhhddmmdhddddhhhhhyhdhyso+/:----------------------::/++oyhdhdmmmmmddho-------------:::::::::::::///// -// /+ssssssssosooo+++/////::::::::::----------------------------------:::::://+++ooossso////++oosyhddddmmdhddddhhhhhhhdhyddhs+:-----------------------::/++syhddmmmmdddho--------------::::::::::::::/// -// /+sssssssooo+++//////::::::::::-------------------------------:::://++++ooooooooooooo+/+oosyyhhddddmmddddddhhhhhhhdhyyssyyhs+::-------------::://++/+/o++shddddmmmddh+----------------:::::::::::::// -// /+sssooso++++/////::::::::::::------------------------::::::///++o++//:--...............-/osyyhddmmmmddddhhhhhyyhdhhdmddhysoso::--------::/osyyyssyyssssoosdmddddddy+:-------------------:::::::::::/ -// /+sssooso+++////::::::::::::--------------------:::::////++o+//:-......................--+ossydddmmdmmdddhhhhyyhddyyydmhhooo++/:-------::/+oshhhyso+/://++ohmmmdhhy+:---------------------::::::::::: -// /+sooooso++/////:::::::::::--------------:::::///+++oo+//:-............................-/+oyydddmmddddddhhhyyyhhhyysosss+:/+///:--.---://+o/ohhdhoyyo+/://+ymmdhsyo:------------------------::::::::: -// /+ooooooso+////:::::::::------------:::::///++oooo/:-..................................:/oyyyhdmdddddddhhhhyyhyss++///:::/::::/:-...--::://-/shy+-:+s+/::/+hdhysos/--------------------------:::::::: -// /+oooooooo++///::::::::::-:----:::::::///+oosyy/-.....................................-/+syhhddddddddhhhhhhhysso+/::::-----:::::-..------:::::////:::::::/sdysso+o:..----.--------------------::::::: -// /+ooooooooo++///:::::::::::::::::::///++osyhmmdo:-...................................-/+syyhdddddddddhdddmmhys+/::----------:::--..---------::::::-----::+dhsoso++:....--.--..----------------::::::: -// /ooooooooooo++///::::::://///++oooosssyydddhdhs+so/+++:-............................./+syyhdddddddddddddmmmhs+//:------------:--..---------------------:/hdsooso+/-....--.....------------------::::: -// /oooooooo++++o++//:::::::///++ossso+ooosysos++o/so//////--..........................:yhddhdddmmdddmmmdddmddhs+/::----------:::---.--------------------:/hdhsooso+/-.....-........----------------:::: -// /ooooooo+++++++++//:::::::::/+o+ooooyyso+oo/++o/oo///://////::--...................-sdhddhddmmdhdmmmddhhdmNds+/:::--------:/:------------------------::sdhyooyso+:-...............---------------:::: -// /ooooooo+++++++++++//:::://+++++ssyys+/+y+///++/so///:://://::::/---://............-smdddddmmhyhhdddhhsydmNmyo//:::------://:--------:::------------::odhysshyo++-................---------------:::: -// /oooooo+++++++++++/+o+/++++++++ohhoo+//yo//:/+//so:/:////::+////+///+so/++/:--------:hdddmdhyssyhhddhsosdmNmho+/:::------////:------::::-----------::+hdhhhyyo+o/-................----------------::: -// /ooo++o++++++++++//+oooooo++++oyyoo+//os+////+//so/://::////+///+//+ssooo+++++++/++//odhhhyoooosyhhhysoodmmNds+//:::-----:++o+/:::/+//:----------::/+ydhyyyyo+oo:...................--------------::: -// /oooo+++++++++++/////+ossoooooss++////+so/::++//os://:/::://////++/os+++++++/++++++++osyso++++osyyyyssoodmmmmyo+/::::-----::/++++////:--------::::/+shhysoso+ss/.....................------------:::/ -// +ooo++++++++++/////////+oooosso////:::+oso/:/+//oy+//:///://////+//o+/++////////++++ooooo++++ossyhhsoosodmmmmds+//////::::::::::::---------::::://+shhyso+++ss:........................----------::// -// +ooo++++++++++///////////////++++//:::/++o////+/+yo//////////////:/o:/+//////////+oooo+oooo++ooyyyyysssshmmmmmds+//////+++++///:::::::::::::::://+syhhso+++oo/..........................---------::/+ -// +o+o+++++++++///////////////::///++//:::/+///////oy+///://///////-++:+/://://::/++so++ooooooossysyyhhssyhmmmmNmds+//:::/++++oooooooo+++//:::::/+oosyys++oso+/-..........................--------:://+ -// +oo+++++++++/////////////////:::://++//////:/+/:/+ss+//////++///:://///::://:://++o++ossssyyssosyyhhyssydmmmmNNmmyo//////++///////////::::::/+oooosossssyyo/-...........................--------://++ -// +++++++++++//////////////::/::::::::///++/:///:://oss//:////++//::+/////:::/:://+so++ssyyhhhoosyyyysoosydmmmNNmmmmho+//::////+++++///:::::/+osssssshmdssyyo-............................-------::/+++ -// +oo++++++++++/////////////:/::::::::::://+/////:/:+oso+:////++/://+++++++/::///+oooosyyyhhhsossssso+osshmmmmNmmmmmdys+/::::---:::::::::/+osyyyssyddmmhsyhy+-.............................-----:://+++ -// +o++++++++++///////////:/::::::::::::---::/+++/::::+oso/::/://:://++++o+:::+//++ssooyyyhhyyssssoo++sssymmmmNmmmmmmhysso/:::::-----:::/+yhhhyyyhddmmdhhyhys+:-............................-----://+++/ -// ++++++++++++/////////////::::::::----------://////:/+oso+/:::::://+++o+//+ooooo+++oshyhhhysssso++ososhmNNNNNmmmmhhyoooooo+/////://+oyhmmdhhyhdddddhyyysssoo+:--.........................-----://++//: -// o++++++++++/////////////:::::::::-------------:////::/ooo/:::::///+os++ssyyyyssssssyhhhysssssoooooosdmNNNNNmmmdhsss+++ooooooossyyhdmmmmdhyysyhhyssooooossooys+//:--.....................----::/+++/:: -// o+++++++++//////////////::::::::----------.....-://////+oo+:://://ooooyhhhhdddhhhyhhhhyssssssssooshmNNNNNNNmmmdooo++//++oooossshddmmmddys++ooo+/+++ossyhhyyyyysoo+//:--.................----://++/::: -// ++++++++++//////////////:::::::--------..........-::///:/+++::::/+o+/ohhhhhhyyyyyyhhhysyyysyyyyhdmNNNNNNNNmmmhso++//:///+ooossydddmmmddhyysso+/++ossshddddddhyyso++++////::::::--.......---://++/:-:: -// o+++++++++///////////////:::::::------..............-:////++/:///+osoyhhhhyssssyhhdddhhhyyhhdmmmmmmmmmmmmmmmho+oo+/::::///+++oyhhdmmmddhhysoo+oosyhhdmmmddddhhyssoo+++++++++++///:-....---://++//-::: -// +++++++++//+///////////:/::::::------.................-://////////+ossyyyyyhhhhddddhhhhddmmmmddddmmmmmmmmmdyo+++os/::::::://+ydhhmmmddddddddddmmmmmmmmmmmmddhyyysoo+o+++//++////::::-----::/++//--::+ -// +++++++++///////////////:::::::------....................-:///++/::+syyyhhhhhhhhhhhhddmmmddddddddmmmmmmmmdso++++++++/:::://ohdhydmmddddhdmmmmmmhhdmmmmmmmmmhhyyyysooso+/+////////////:::::/+++/:-::++ -// ++++++++++//////////////:/:::::------......................-:/+/:::+shhdhhhhhhhhhdddmmmddddhhhhhddmmmmmmdyo+++++/+/++++++oydmdhyhdddhhsssydmdmmddddddmmmmmdhhsyysoso++++///+//////://+//////+/:-::/o: -// ++++++++++/////////////://:::::------.........................::::/osdmmmmmddddddddddhhysssooosyhdmmmmmdsooo+o++/+++++++shmmddhyyhmhso/+shhdmddhhhdmmmmddhhyyysoooo//+++/://///:/+//+///////::-::/o/: -// +++++++++++////////////:/::::::-----..........................-:://+oymmmmmddddhhhhhhhhyysoo+osyhhdmdhyoo/++so++++oooooohmmmmdhhyhdh+//+ydhyssshddmmdhhhyyssso+/+o+//+////:////+//+////+////+++////:- -// +++++++++//////////////://:::::-----.........................-::::///oyddddhhhhhdmdddhddhhysssyhhdmdyo++o/+/+oooo+++o+osdmmmmdhhyhdd+/+syo++oshddhyyhhyssooo+///+/++/+++/://:/+/++++o++oooooso++oo++/ -// o+++++++++///////////////::::::-----.........................::::::++o+shmdyhhsyhdddmmddddhsosyhhmmh++/+o+/+/++++ooososhmddddhyyso++oosso++osyyhhddmdysooo+//+/o+++/+/o//o+/++++/+ooosssooooo+++++/++ -// o+++++++++///////////////:::::------........................-::::::+ossyyhyo+++shddmmdyyhyo//osysdds//++++o+/++o+o++oosdhdddhhyyysoooysoosyyyhdddhmmss+o+o++//+/+++//+++++oo++/oossssssssoooooooo++++ -// o++++++++++/////////////:/::::-----.........................:::::/oyysyysooo+oyhdddmdhhddh+++osyhdh//////++o+///++ooooyshdmmmmdddhdhssshhysydmmysshyoo++++++/+++////+o+ooso+++ssyyyyyyyyysssooooo+o++ -// ooo+++++++++//////////////::::-----.........................:-:::ohdhhhhysssssyhhhyhhhdmmd+++oyddho////:/++++++/+/+++oshmmmmmdhyyyssyhdysshmmmdhyysoo+/+o+//++/+//++ososso++syhyyyhyyyyyyyysssysssyss -// ooo+++++++++////////////::::::------.......................---::+hddhhyysoosoooosssooosyyyssyhdhho+///////////+/+++++symmmdys+//+oyhhyssyhdmmmmmhyo+++++++/+++++oo++ohssoooyhhhhhhhyyyhyhhyyhyyhyyyyy -// ooo++++++/++/////////////::::::-----.......................:::/:/+sssyyysssyo++oosyhhhhyyssoo+oooo+///////////+++++oyhddhysssyyhdddhysoshmNNNNmmyoo+++++++/+/++++o+osdyssoyhhhhhhhhhhhhhhyhhhhhhhhhhh -// oooo++++++++/////////////::::::-----.......................:::::///++ooooo++/:/+syhhddys++/:/+++o+++////++////+++osysydhydmddddyshysoshmmmmmNNmyooo+oo+++++/++oooooshdyoyyhhhhhhhhhhdhhhhhdhhhhdhhhhd -// ooo+++++++++/////////////::::::----.......................-://::::://////:///://ooooo+////////++oo++++////++//oosyhyyyyshddmmhyhyysyhmNmdddmNdysooooosooooooooooso+shdysyhdhhhhhhhdddhdhdddddddhhhddd -// oooo+++++++++////////////::::::----.......................::/:::::///////://::::::::::://:/::/++oo+++////++++oohyhhhhhhsydmdhhhyyhhyymmmdddmmyssoooosysossosoo+ssossddysydhhddhhddhhddddddddddddhdddd -// oooo+++++++++/++//////////::::-----......................-:::::::///////::/:::::::::::::::::/:/++oo++++++/++ssyhhddddhyyohmddhhddhyhhmmmddmmdsssoosssosssossooossoyhmhyyhdhddddhhhdhhddddddddhddddmdd -// oooo+++++++++//+//////////::::----.......................-:::::///:/::::::/::::-::::/:-:::::///++ooooo+++++shhdddddhhyyhysdddhdmdhhddmdhhydmhssosssysssssssoosssssyhmysyddddddhdhdddddddddddddddmdddd -// ooooo+++++++++++//////////::::----.......................::::::://://:::://::-:::-::::::::::////++oosoo+o+oyhhdddddhhhhddyyhyhddhhhdmmmhyyddhssssssyyysssssssssysyyddyyhddddddddhhhhhddddddddmddddddm -// ooooo+o++++++++++/////////::::----.......................::::::/:///::::::::::::::::::::/:::::///++osssososssyhddddhhhhdddssoossyhdmmmmhyyhhhyssyyyyysyyyssyssssshhmhyhdddddddddddhdhhddmddmdddddhdmm -// ooooooo++++++++++/////////:::-----......................-:::::/::::/:/::://::::/::::::::::::::/:://+ooosssyysyyyyyyyhddmmysssssyyhhddmdhysyhhyyyyyyyysyyyyysssyysyydhydddddddhddddhddddddddddddhddmmm -// ooooooo+++++++++++////////:::-----......................:::::/:::://:-::/:://::/::::-:::::::::/:/::/++oosssyyysssssyhdddhsyysssyyhhddhhyssyyyyyyyyysyyssyyyyyyyyyhhdyhdddhddddhddddddmmddddddhdddmmmm -// ooooooo+o+++++++++++//////:::-----.....................-::::::/:///:::::::::/::/::::::::::/::/:///::////+oosyysssyssyyyysssyhyyhddmmdyysoossyssyyysssyyssysyyyyshyddhddhhhddhdddddddddmddhdddhhdhhdmm -// ooooooooo++++++++++///////:::-----.....................-::::////:::::::::::::::::::://::::/-:::::/:://::///+osyyssosossssssysyhdddddhysoosssyyssssyssyyyyyysssyshddddddhddddddddddmddddhdhhhddddmmmmm -// oooooooooo+o++++++++++////::::----.....................::://::::/::::::::::::::/:://::::::::::/::::::///////++ooooosoo+ososssshddhhysssooossssssssyssysyyyyyysysyhddddddddddddddddddddhddhhhddddmmmmd -// soooooooooo+++++++++++////::::----....................-:::::////:::/:::::::/::://///:/::::::::/:///://:/://+//+++++++oo+ooooooshdyyyssossoosssyssyysssssyyyyysssshdddddddddddddddddddhhhdhhhddmmmmdmd -// sssooooooooo++++++++++////::::----....................-:::/:://///:::::::::::::/://:/::://::::::://:::/://///++/+++/+++o+oosssyyysssyysosoososysssyysyyyyhysyssyyhdddddddddddddddddhddhddhddmmmmmdmmm -// ssssoooooooo++++++++++////:::::----...................:::::://::::::::::::-::://///:////::/:/:::://///:://://+o++++++oooosoosoossoososssooososssssyyyyyssyyyssyyyhmmdddhhhhhhhddhdddddddddmmmmmmddmmm -// sssoooooooooooo+++++++/////::::----...................:://///:/:::::::::::::::://///////////+/:/://://::////+++++++ooossoossososososssoososossssssyssyyyyyyyyyysyhdhhhhhhhhhhhdhhhhhdddddmmmmmmddmmNN -// ssssoooooooooooo+++++++////::::----..................-::::/:/:::::::::::::://:::://///:/:///////////:://+/++++++oooooooosssssoosssssssosooosooossssyyysyyysyyyysoyyooossssyyhhhddhddhhhhhddmmmmmmmmmm -// ssssssoooooooooooo++++++///:::------.................::::::://:::::::-:::::/::://////:///////////////////++o++oo+ooooosoossossosssossssoosoosoosssyysyyyysyyssysoyo+oooo//+osossosyhhhhhhddmmddmmmmdm -// sssssssosooooooooooo++++///::::-----................./::::/:/:::::::::-::/:::/://///////////+//++/++//+oo+oo++ooo+ooooosssosoossssysosssssooooossysyyyyysyyyyyssoo++ooo+//+s/:---::/+oosyyyhhhhdmmmmm -// yssssssssssoooooooo+++++///::::-----................://::::::/:/::::::-::/::::://///////////////+/++++++oo+++oooooo+oooosssossosysosssosssoooosssyyyyyyyyyyyysso++++++//:/o/:--::::::::::/++oossymmmm -// yysssssssssssooooooo++++////:::------..............-///:::/:::/:::/::::://:::::::///////////////++++++o++++o++oo+ooooooooosysosssssoosssssosoossyyyyyssyyyyysss++oooo+///oo/::::-::::::::::::////sdmm -// yyysssssssssssooooooo++++///:::-------.............:/:::/:/:::::::::://://::/::::/:////////+/////++++++oo+ooo++oooo+oooossssssssssoossoooooossssyyyyyyyyyyyysso++ooo/--:/:.::::..::::-..-::://////ohm -// yyyssssssssssssoooooo++++///::::------............-/:::/://///:::::::::://::/::::::////:///+/+++/++++++/++++++o+o++oooooooosssssoossssssssosssssyyyyyyyyyyyyso++ooo:./.-+-.---...--:::.--::::://////o -// yyyysyssssssssssoooooo+++///::::--------.........-/:::::////::/::::::::::/:://:/:::///////////+/+++++//++++++++oo+++ooosoooossssssossoosssssssssyyyyyyyyyyysoo+oooo`:+.+.--.--.-::.-.----::-:./////// -// yyyyyyyyyssssssssooooo+++///:::::----------......:///:::://///:::::::::::://:/:::://///////+////++++////+++++++++o++oooosssososossossososssssysyyysyyyyyyysso+oooo+--:-+-.-.-------::----:--:-:////// -// yyyyyyyyyyssssssssoooo++++//:::::-------------.--////://::/:::::/::::/:::://:/::::/:/:///////+//+++///+//++/++++o++++ooooooosssossssosoossssssssssyyyyyyyyso++ooso++/o+/:::::::::::::::////////////// -// yyyyyyyyyyyssssssssoooo+++///::::---------------:////////////:/:///::::://////::::::://///////+/++////+//+/++++++++ooosooooooososoosososssosyyyssyysyyyyysso+oso+//+oo/:::::::::::::/:::///////////++ -// yyyyyyyyyyyyysssssssooo+++///:::::---------------+////:///:///:::::///::://///:::/:::///////////++/++++///++++/++o+oooooooooosoososoossssssssysssyyyyyyysoo+ooso+++ss/::::::::::::::://///////////+++ -// hhyyyyyyyyyyyyyssssssooo++///:::::---------------/////////:////://:///::://///://::://////////++////+///+///++o++++ooooooooooooooooooooososososssyssssysooo+oso+++os+:::::///////////////////////++++ -// hhhyyyyyyyyyyyyyyssssooo+++///::::---------------:////////////:////////:://///::://////////++/+++//////+++++++++++++++oo+++o+ooososooosssoossssssssssssooo+osso+oos+:::////////////////////////++++++ -// hhhhhhyyyyyyyyyyyyssssoo+++////:::::--------------:///////////:///://///:///////:///://///++/++++//++/++++/++++++++++++++o+oooooooosoosssssoosssssssssso++ossooooyo/:///////////////////////++++++++o diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index 96b0172d..365a4414 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -26,7 +26,7 @@ public class FunctionalBridge { public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider(); @LauncherAPI - public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception { + public static HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedObjectHolder hdir, FileNameMatcher matcher, boolean digest) throws Exception { return () -> { if (hdir == null) { Request.requestError(java.lang.String.format("Директории '%s' нет в кэше", dirName)); @@ -37,7 +37,7 @@ public HashedDirRunnable offlineUpdateRequest(String dirName, Path dir, SignedOb } @LauncherAPI - public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException { + public static LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, SignatureException { if (settings.lastDigest == null || settings.lastProfiles.isEmpty()) { Request.requestError("Запуск в оффлайн-режиме невозможен"); } @@ -51,12 +51,12 @@ public LegacyLauncherRequest.Result offlineLauncherRequest() throws IOException, return new LegacyLauncherRequest.Result(null, settings.lastDigest, settings.lastProfiles); } @LauncherAPI - public void makeJsonRequest(RequestInterface request, Runnable callback) + public static void makeJsonRequest(RequestInterface request, Runnable callback) { } @LauncherAPI - public void startTask(@SuppressWarnings("rawtypes") Task task) + public static void startTask(Task task) { try { worker.queue.put(task); @@ -65,7 +65,7 @@ public void startTask(@SuppressWarnings("rawtypes") Task task) } } @LauncherAPI - public HWID getHWID() + public static HWID getHWID() { return hwidProvider.getHWID(); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java index 626648ee..99864ab8 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java +++ b/Launcher/src/main/java/ru/gravit/launcher/hwid/OshiHWIDProvider.java @@ -1,7 +1,7 @@ package ru.gravit.launcher.hwid; import oshi.SystemInfo; -import oshi.hardware.HWDiskStore; +import oshi.hardware.*; import ru.gravit.launcher.HWID; import ru.gravit.launcher.LauncherHWIDInterface; import ru.gravit.launcher.OshiHWID; @@ -19,30 +19,64 @@ public String getSerial() return ""; } + } + public String getProcessorID() + { + try { + return systemInfo.getHardware().getProcessor().getProcessorID(); + } catch (Exception e) + { + LogHelper.error(e); + return ""; + } + } public String getHWDisk() { - for(HWDiskStore s : systemInfo.getHardware().getDiskStores()) + try { + for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) { + if (!s.getModel().contains("USB")) + return s.getSerial(); + } + return ""; + } catch (Exception e) { - if(!s.getModel().contains("USB")) - return s.getSerial(); + LogHelper.error(e); + return ""; } - return ""; } public long getTotalMemory() { return systemInfo.getHardware().getMemory().getTotal(); } - + public long getAvailableMemory() + { + return systemInfo.getHardware().getMemory().getAvailable(); + } + public void printHardwareInformation() + { + HardwareAbstractionLayer hardware = systemInfo.getHardware(); + ComputerSystem computerSystem = hardware.getComputerSystem(); + LogHelper.debug("ComputerSystem Model: %s Serial: %s",computerSystem.getModel(),computerSystem.getSerialNumber()); + for (HWDiskStore s : systemInfo.getHardware().getDiskStores()) + { + LogHelper.debug("HWDiskStore Serial: %s Model: %s Size: %d",s.getSerial(),s.getModel(),s.getSize()); + } + for (UsbDevice s : systemInfo.getHardware().getUsbDevices(true)) + { + LogHelper.debug("USBDevice Serial: %s Name: %s",s.getSerialNumber(),s.getName()); + } + CentralProcessor processor = hardware.getProcessor(); + LogHelper.debug("Processor Model: %s ID: %s",processor.getModel(),processor.getProcessorID()); + } @Override public HWID getHWID() { OshiHWID hwid = new OshiHWID(); hwid.serialNumber = getSerial(); hwid.totalMemory = getTotalMemory(); hwid.HWDiskSerial = getHWDisk(); - LogHelper.debug("serialNumber %s",hwid.serialNumber); - LogHelper.debug("totalMemory %d",hwid.totalMemory); - LogHelper.debug("HWDiskSerial %s",hwid.HWDiskSerial); + hwid.processorID = getProcessorID(); + printHardwareInformation(); return hwid; } } diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java index d998c9ec..b62e837e 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/auth/AuthRequest.java @@ -2,10 +2,7 @@ import java.io.IOException; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.LauncherHWIDInterface; +import ru.gravit.launcher.*; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.launcher.profiles.PlayerProfile; @@ -33,10 +30,10 @@ private Result(PlayerProfile pp, String accessToken) { private final byte[] encryptedPassword; private final int auth_id; - private final LauncherHWIDInterface hwid; + private final HWID hwid; @LauncherAPI - public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) { + public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid) { super(config); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.encryptedPassword = encryptedPassword.clone(); @@ -45,7 +42,7 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword } @LauncherAPI - public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, LauncherHWIDInterface hwid, int auth_id) { + public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword, HWID hwid, int auth_id) { super(config); this.login = VerifyHelper.verify(login, VerifyHelper.NOT_EMPTY, "Login can't be empty"); this.encryptedPassword = encryptedPassword.clone(); @@ -54,12 +51,12 @@ public AuthRequest(LauncherConfig config, String login, byte[] encryptedPassword } @LauncherAPI - public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid) { + public AuthRequest(String login, byte[] encryptedPassword, HWID hwid) { this(null, login, encryptedPassword,hwid); } @LauncherAPI - public AuthRequest(String login, byte[] encryptedPassword, LauncherHWIDInterface hwid, int auth_id) { + public AuthRequest(String login, byte[] encryptedPassword, HWID hwid, int auth_id) { this(null, login, encryptedPassword, hwid, auth_id); } @@ -75,7 +72,7 @@ protected Result requestDo(HInput input, HOutput output) throws IOException { if (Launcher.profile != null) output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT); output.writeInt(auth_id); - output.writeString(hwid.getHWID().getSerializeString(),0); + output.writeString(hwid.getSerializeString(),0); //output.writeLong(0); //output.writeLong(0); //output.writeLong(0); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/HWID.java b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java index cc510103..d1cf0f9c 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/HWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/HWID.java @@ -2,5 +2,6 @@ public interface HWID { String getSerializeString(); + int getLevel(); //Уровень доверия, насколько уникальные значения boolean isNull(); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java index 5b1a7a0c..24be03ea 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/OshiHWID.java @@ -4,20 +4,27 @@ public class OshiHWID implements HWID { public static Gson gson = new Gson(); + @LauncherAPI public long totalMemory = 0; + @LauncherAPI public String serialNumber; + @LauncherAPI public String HWDiskSerial; + @LauncherAPI + public String processorID; @Override public String getSerializeString() { return gson.toJson(this); } + @Override public int getLevel() //Уровень доверия, насколько уникальные значения { int result = 0; if(totalMemory != 0) result++; - if(serialNumber != null) result+=5; - if(HWDiskSerial != null) result+=8; + if(serialNumber != null && !serialNumber.equals("unknown")) result+=4; + if(HWDiskSerial != null && !HWDiskSerial.equals("unknown")) result+=15; + if(processorID != null && !processorID.equals("unknown")) result+=6; return result; } @Override diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index 9d7a3904..09c805bb 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -15,8 +15,7 @@ import ru.gravit.launcher.serialize.config.entry.*; @SuppressWarnings("ComparableImplementedButEqualsNotOverridden") -public final class -ClientProfile extends ConfigObject implements Comparable { +public final class ClientProfile extends ConfigObject implements Comparable { @LauncherAPI public enum Version { MC147("1.4.7", 51), @@ -63,6 +62,8 @@ public String toString() { @LauncherAPI public static final StreamObject.Adapter RO_ADAPTER = input -> new ClientProfile(input, true); + public static final boolean profileCaseSensitive = Boolean.getBoolean("launcher.clientProfile.caseSensitive"); + private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); // Version @@ -278,8 +279,8 @@ public boolean isUpdateFastCheck() { @LauncherAPI public boolean isWhitelistContains(String username) { - if (!useWhitelist.getValue()) return true; - return whitelist.stream().anyMatch(e -> e.equalsIgnoreCase(username)); // TODO case sensitive on/off + if (!useWhitelist) return true; + return whitelist.stream().anyMatch(profileCaseSensitive ? e -> e.equals(username) : e -> e.equalsIgnoreCase(username)); } @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java index c90d7e1c..175cae96 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/EnvHelper.java @@ -4,11 +4,7 @@ import java.util.Map; public class EnvHelper { - public static final String[] toTest; - - static { - toTest = new String[]{"_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS"}; - } + public static final String[] toTest = {"_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS"}; public static void addEnv(ProcessBuilder builder) { Map map = builder.environment(); diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java index 678b0feb..6ec5ab62 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/JVMHelper.java @@ -64,7 +64,6 @@ public static OS byName(String name) { try { MethodHandles.publicLookup(); // Just to initialize class } catch (Throwable exc) { - LogHelper.error("Unsafe field is not initialized"); throw new InternalError(exc); } } diff --git a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java index a14343ef..62f0c45c 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java +++ b/libLauncher/src/main/java/ru/gravit/utils/helper/UnpackHelper.java @@ -1,24 +1,25 @@ package ru.gravit.utils.helper; import java.io.IOException; +import java.io.InputStream; import java.net.URL; import java.nio.file.Path; import java.util.Arrays; public class UnpackHelper { - @SuppressWarnings("ResultOfMethodCallIgnored") public static boolean unpack(URL resource, Path target) throws IOException { - byte[] orig = IOHelper.read(resource); if (IOHelper.exists(target)) { - if (matches(target, orig)) return false; + if (matches(target, resource)) return false; } if (!IOHelper.exists(target)) target.toFile().createNewFile(); - IOHelper.transfer(orig, target, false); + try (InputStream in = IOHelper.newInput(resource)) { + IOHelper.transfer(in, target, false); + } return true; } - private static boolean matches(Path target, byte[] in) { + private static boolean matches(Path target, URL in) { try { return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in), SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, target));