diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index be52d0b1..f530696c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.zip.CRC32; +import org.apache.commons.io.FileUtils; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.utils.helper.CommonHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java index 1d2f37c2..d8482c1f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java @@ -42,6 +42,8 @@ public ProguardConf(LaunchServer srv) { confStrs.add("@".concat(config.toString())); if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'"); confStrs.add("-obfuscationdictionary \'" + words.toFile().getName() + "\'"); + confStrs.add("-injar \'../" + srv.config.binaryName + ".jar\'"); + confStrs.add("-injar \'../" + srv.config.binaryName + "-obf.jar\'"); confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'"); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java index 85e1da00..a9bcc06d 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/TestCommand.java @@ -26,7 +26,7 @@ public String getUsageDescription() { public void invoke(String... args) throws Exception { verifyArgs(args,1); LogHelper.debug("start downloading"); - HttpDownloader.downloadFile(new URL(args[0]),"test.html"); + HttpDownloader downloader =new HttpDownloader(new URL(args[0]),"test.html"); LogHelper.debug("end downloading"); } } 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 6dfb5ab8..005ef29c 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/proguard.cfg @@ -1,8 +1,6 @@ -libraryjars '/lib/rt.jar' -libraryjars '/lib/jce.jar' -libraryjars '/lib/ext/nashorn.jar' --injars ../Launcher.jar --outjars ../Launcher-obf.jar -keepattributes SourceFile,LineNumberTable -renamesourcefileattribute Source diff --git a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java index d83e8723..6b4efb60 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java +++ b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java @@ -38,7 +38,7 @@ public void run() { } } } - public static final String NAME = "wrapper"; // TODO customizable filename. + public static final String NAME = Launcher.getConfig().projectname; public static String avn32 = null, avn64 = null; public static Path wrap32 = null, wrap64 = null; @@ -102,8 +102,8 @@ private static void processArched(Path arch32, Path arch64, Path wrapper32, Path public static void start(Path path1) { Path path = path1.resolve("guard"); - processArched(handle(path.resolve(NAME + "32.dll"), "Avanguard32.dll"), - handle(path.resolve(NAME + "64.dll"), "Avanguard64.dll"), + processArched(handle(path.resolve("Avanguard32.dll"), "Avanguard32.dll"), + handle(path.resolve("Avanguard64.dll"), "Avanguard64.dll"), handle(path.resolve(NAME + "32.exe"), "wrapper32.exe"), handle(path.resolve(NAME + "64.exe"), "wrapper64.exe")); } 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 0513dc36..ec198b10 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -29,12 +29,7 @@ import com.eclipsesource.json.JsonObject; import com.eclipsesource.json.WriterConfig; -import ru.gravit.launcher.AvanguardStarter; -import ru.gravit.launcher.Launcher; -import ru.gravit.launcher.LauncherAPI; -import ru.gravit.launcher.LauncherClassLoader; -import ru.gravit.launcher.LauncherConfig; -import ru.gravit.launcher.LauncherVersion; +import ru.gravit.launcher.*; import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; @@ -352,8 +347,8 @@ public static Process launch( Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args,"-javaagent:".concat(pathLauncher)); //Collections.addAll(args, "-classpath", classPathString.toString()); - if(wrapper) - Collections.addAll(args, "-Djava.class.path=".concat(classPathString.toString())); // Add Class Path + //if(wrapper) + //Collections.addAll(args, "-Djava.class.path=".concat(classPathString.toString())); // Add Class Path Collections.addAll(args, ClientLauncher.class.getName()); Collections.addAll(args, paramsFile.toString()); @@ -365,8 +360,8 @@ public static Process launch( ProcessBuilder builder = new ProcessBuilder(args); if(wrapper) builder.environment().put("JAVA_HOME", System.getProperty("java.home")); - else - builder.environment().put("CLASSPATH", classPathString.toString()); + //else + //builder.environment().put("CLASSPATH", classPathString.toString()); EnvHelper.addEnv(builder); builder.directory(params.clientDir.toFile()); builder.inheritIO(); @@ -414,20 +409,10 @@ public static void main(String... args) throws Throwable { // Verify ClientLauncher sign and classpath LogHelper.debug("Verifying ClientLauncher sign and classpath"); SecurityHelper.verifySign(LauncherRequest.BINARY_PATH, params.launcherSign, publicKey); - String[] classpath = JVMHelper.getClassPath(); LinkedList classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath()); - int counter = classPath.size(); - for (String classpathURL : classpath) { - Path file = Paths.get(classpathURL); - if (!file.startsWith(IOHelper.JVM_DIR)) - for (Path classPathURL : classPath) - if (classpathURL.equals(classPathURL.toString())) { - counter--; - break; - } + for (Path classpathURL : classPath) { + LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - if (counter != 0) - throw new SecurityException(String.format("Forbidden classpath entry, %d != 0", counter)); URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath()); classLoader = new LauncherClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java index 7ca429b5..e144d10d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherAgent.java @@ -13,13 +13,17 @@ @LauncherAPI public class LauncherAgent { private static final boolean enabled = false; + private static boolean isAgentStarted=false; public static Instrumentation inst; public static void addJVMClassPath(String path) throws IOException { LogHelper.debug("Launcher Agent addJVMClassPath"); inst.appendToSystemClassLoaderSearch(new JarFile(path)); } - + public boolean isAgentStarted() + { + return isAgentStarted; + } public static long getObjSize(Object obj) { return inst.getObjectSize(obj); } @@ -27,6 +31,7 @@ public static long getObjSize(Object obj) { public static void premain(String agentArgument, Instrumentation instrumentation) { System.out.println("Launcher Agent"); inst = instrumentation; + isAgentStarted = true; if(ClassFile.MAJOR_VERSION > ClassFile.JAVA_8 || enabled) { inst.addTransformer(new SystemClassLoaderTransformer()); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java index c54a3738..d0007f98 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/LauncherConfig.java @@ -32,6 +32,8 @@ public static AutogenConfig getAutogenConfig() @LauncherAPI public final InetSocketAddress address; @LauncherAPI + public final String projectname; + @LauncherAPI public final RSAPublicKey publicKey; @LauncherAPI @@ -42,7 +44,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException address = InetSocketAddress.createUnresolved( ADDRESS_OVERRIDE == null ? localAddress : ADDRESS_OVERRIDE, config.port); publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH)); - + projectname = config.projectname; // Read signed runtime int count = input.readLength(0); Map localResources = new HashMap<>(count); @@ -60,10 +62,19 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException } @LauncherAPI @SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter") + public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map runtime,String projectname) { + this.address = InetSocketAddress.createUnresolved(address, port); + this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); + this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.projectname = projectname; + } + @LauncherAPI + @SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter") public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map runtime) { this.address = InetSocketAddress.createUnresolved(address, port); this.publicKey = Objects.requireNonNull(publicKey, "publicKey"); this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.projectname = "Minecraft"; } @Override diff --git a/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java b/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java index 23fe61ef..559c5e6a 100644 --- a/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java +++ b/libLauncher/src/main/java/ru/gravit/utils/HttpDownloader.java @@ -3,20 +3,57 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.LogHelper; +import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; import java.nio.file.Path; +import java.util.Observable; +import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -public class HttpDownloader { - public static void downloadFile(URL url, String file) throws IOException { - ReadableByteChannel rbc = Channels.newChannel(url.openStream()); - try (FileOutputStream fos = new FileOutputStream(file)) { - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); +public class HttpDownloader extends Observable { + public static final int BUFER_SIZE = 8192; + public static final int INTERVAL = 300; + public AtomicInteger writed = new AtomicInteger(0); + private String filename; + public Thread thread; + + public HttpDownloader(URL url, String file) { + Runnable run = () -> { + try { + filename = file; + downloadFile(url, file); + } catch (IOException e) { + e.printStackTrace(); + } + }; + Thread downloader = new Thread(run); + thread = downloader; + downloader.start(); + } + public synchronized String getFilename() + { + return filename; + } + + public void downloadFile(URL url, String file) throws IOException { + try (BufferedInputStream in = new BufferedInputStream(url.openStream()); FileOutputStream fout = new FileOutputStream(file)) { + + final byte data[] = new byte[BUFER_SIZE]; + int count; + long timestamp = System.currentTimeMillis(); + int writed_local = 0; + while ((count = in.read(data, 0, BUFER_SIZE)) != -1) { + fout.write(data, 0, count); + writed_local+=count; + if(System.currentTimeMillis() - timestamp > INTERVAL) { + writed.set(writed_local); + LogHelper.debug("Downloaded %d",writed_local); + } + } + writed.set(writed_local); } }