mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
HttpDownloader update
AvanguardStarter update ProGuard update
This commit is contained in:
parent
a7dcfc4183
commit
303402310b
9 changed files with 76 additions and 37 deletions
|
@ -29,6 +29,7 @@
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
|
|
|
@ -42,6 +42,8 @@ public ProguardConf(LaunchServer srv) {
|
||||||
confStrs.add("@".concat(config.toString()));
|
confStrs.add("@".concat(config.toString()));
|
||||||
if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
if (this.srv.config.genMappings) confStrs.add("-printmapping \'" + mappings.toFile().getName() + "\'");
|
||||||
confStrs.add("-obfuscationdictionary \'" + words.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() + "\'");
|
confStrs.add("-classobfuscationdictionary \'" + words.toFile().getName() + "\'");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public String getUsageDescription() {
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,1);
|
verifyArgs(args,1);
|
||||||
LogHelper.debug("start downloading");
|
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");
|
LogHelper.debug("end downloading");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
-libraryjars '<java.home>/lib/rt.jar'
|
-libraryjars '<java.home>/lib/rt.jar'
|
||||||
-libraryjars '<java.home>/lib/jce.jar'
|
-libraryjars '<java.home>/lib/jce.jar'
|
||||||
-libraryjars '<java.home>/lib/ext/nashorn.jar'
|
-libraryjars '<java.home>/lib/ext/nashorn.jar'
|
||||||
-injars ../Launcher.jar
|
|
||||||
-outjars ../Launcher-obf.jar
|
|
||||||
-keepattributes SourceFile,LineNumberTable
|
-keepattributes SourceFile,LineNumberTable
|
||||||
-renamesourcefileattribute Source
|
-renamesourcefileattribute Source
|
||||||
|
|
||||||
|
|
|
@ -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 String avn32 = null, avn64 = null;
|
||||||
public static Path wrap32 = null, wrap64 = 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) {
|
public static void start(Path path1) {
|
||||||
Path path = path1.resolve("guard");
|
Path path = path1.resolve("guard");
|
||||||
processArched(handle(path.resolve(NAME + "32.dll"), "Avanguard32.dll"),
|
processArched(handle(path.resolve("Avanguard32.dll"), "Avanguard32.dll"),
|
||||||
handle(path.resolve(NAME + "64.dll"), "Avanguard64.dll"),
|
handle(path.resolve("Avanguard64.dll"), "Avanguard64.dll"),
|
||||||
handle(path.resolve(NAME + "32.exe"), "wrapper32.exe"),
|
handle(path.resolve(NAME + "32.exe"), "wrapper32.exe"),
|
||||||
handle(path.resolve(NAME + "64.exe"), "wrapper64.exe"));
|
handle(path.resolve(NAME + "64.exe"), "wrapper64.exe"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,12 +29,7 @@
|
||||||
import com.eclipsesource.json.JsonObject;
|
import com.eclipsesource.json.JsonObject;
|
||||||
import com.eclipsesource.json.WriterConfig;
|
import com.eclipsesource.json.WriterConfig;
|
||||||
|
|
||||||
import ru.gravit.launcher.AvanguardStarter;
|
import ru.gravit.launcher.*;
|
||||||
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.hasher.DirWatcher;
|
import ru.gravit.launcher.hasher.DirWatcher;
|
||||||
import ru.gravit.launcher.hasher.FileNameMatcher;
|
import ru.gravit.launcher.hasher.FileNameMatcher;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
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, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
|
||||||
Collections.addAll(args,"-javaagent:".concat(pathLauncher));
|
Collections.addAll(args,"-javaagent:".concat(pathLauncher));
|
||||||
//Collections.addAll(args, "-classpath", classPathString.toString());
|
//Collections.addAll(args, "-classpath", classPathString.toString());
|
||||||
if(wrapper)
|
//if(wrapper)
|
||||||
Collections.addAll(args, "-Djava.class.path=".concat(classPathString.toString())); // Add Class Path
|
//Collections.addAll(args, "-Djava.class.path=".concat(classPathString.toString())); // Add Class Path
|
||||||
Collections.addAll(args, ClientLauncher.class.getName());
|
Collections.addAll(args, ClientLauncher.class.getName());
|
||||||
Collections.addAll(args, paramsFile.toString());
|
Collections.addAll(args, paramsFile.toString());
|
||||||
|
|
||||||
|
@ -365,8 +360,8 @@ public static Process launch(
|
||||||
ProcessBuilder builder = new ProcessBuilder(args);
|
ProcessBuilder builder = new ProcessBuilder(args);
|
||||||
if(wrapper)
|
if(wrapper)
|
||||||
builder.environment().put("JAVA_HOME", System.getProperty("java.home"));
|
builder.environment().put("JAVA_HOME", System.getProperty("java.home"));
|
||||||
else
|
//else
|
||||||
builder.environment().put("CLASSPATH", classPathString.toString());
|
//builder.environment().put("CLASSPATH", classPathString.toString());
|
||||||
EnvHelper.addEnv(builder);
|
EnvHelper.addEnv(builder);
|
||||||
builder.directory(params.clientDir.toFile());
|
builder.directory(params.clientDir.toFile());
|
||||||
builder.inheritIO();
|
builder.inheritIO();
|
||||||
|
@ -414,20 +409,10 @@ public static void main(String... args) throws Throwable {
|
||||||
// Verify ClientLauncher sign and classpath
|
// Verify ClientLauncher sign and classpath
|
||||||
LogHelper.debug("Verifying ClientLauncher sign and classpath");
|
LogHelper.debug("Verifying ClientLauncher sign and classpath");
|
||||||
SecurityHelper.verifySign(LauncherRequest.BINARY_PATH, params.launcherSign, publicKey);
|
SecurityHelper.verifySign(LauncherRequest.BINARY_PATH, params.launcherSign, publicKey);
|
||||||
String[] classpath = JVMHelper.getClassPath();
|
|
||||||
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath());
|
LinkedList<Path> classPath = resolveClassPathList(params.clientDir, profile.object.getClassPath());
|
||||||
int counter = classPath.size();
|
for (Path classpathURL : classPath) {
|
||||||
for (String classpathURL : classpath) {
|
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
|
||||||
Path file = Paths.get(classpathURL);
|
|
||||||
if (!file.startsWith(IOHelper.JVM_DIR))
|
|
||||||
for (Path classPathURL : classPath)
|
|
||||||
if (classpathURL.equals(classPathURL.toString())) {
|
|
||||||
counter--;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (counter != 0)
|
|
||||||
throw new SecurityException(String.format("Forbidden classpath entry, %d != 0", counter));
|
|
||||||
URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath());
|
URL[] classpathurls = resolveClassPath(params.clientDir, profile.object.getClassPath());
|
||||||
classLoader = new LauncherClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
|
classLoader = new LauncherClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
|
||||||
Thread.currentThread().setContextClassLoader(classLoader);
|
Thread.currentThread().setContextClassLoader(classLoader);
|
||||||
|
|
|
@ -13,13 +13,17 @@
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public class LauncherAgent {
|
public class LauncherAgent {
|
||||||
private static final boolean enabled = false;
|
private static final boolean enabled = false;
|
||||||
|
private static boolean isAgentStarted=false;
|
||||||
public static Instrumentation inst;
|
public static Instrumentation inst;
|
||||||
|
|
||||||
public static void addJVMClassPath(String path) throws IOException {
|
public static void addJVMClassPath(String path) throws IOException {
|
||||||
LogHelper.debug("Launcher Agent addJVMClassPath");
|
LogHelper.debug("Launcher Agent addJVMClassPath");
|
||||||
inst.appendToSystemClassLoaderSearch(new JarFile(path));
|
inst.appendToSystemClassLoaderSearch(new JarFile(path));
|
||||||
}
|
}
|
||||||
|
public boolean isAgentStarted()
|
||||||
|
{
|
||||||
|
return isAgentStarted;
|
||||||
|
}
|
||||||
public static long getObjSize(Object obj) {
|
public static long getObjSize(Object obj) {
|
||||||
return inst.getObjectSize(obj);
|
return inst.getObjectSize(obj);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +31,7 @@ public static long getObjSize(Object obj) {
|
||||||
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
public static void premain(String agentArgument, Instrumentation instrumentation) {
|
||||||
System.out.println("Launcher Agent");
|
System.out.println("Launcher Agent");
|
||||||
inst = instrumentation;
|
inst = instrumentation;
|
||||||
|
isAgentStarted = true;
|
||||||
|
|
||||||
if(ClassFile.MAJOR_VERSION > ClassFile.JAVA_8 || enabled) {
|
if(ClassFile.MAJOR_VERSION > ClassFile.JAVA_8 || enabled) {
|
||||||
inst.addTransformer(new SystemClassLoaderTransformer());
|
inst.addTransformer(new SystemClassLoaderTransformer());
|
||||||
|
|
|
@ -32,6 +32,8 @@ public static AutogenConfig getAutogenConfig()
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public final InetSocketAddress address;
|
public final InetSocketAddress address;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
public final String projectname;
|
||||||
|
@LauncherAPI
|
||||||
public final RSAPublicKey publicKey;
|
public final RSAPublicKey publicKey;
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -42,7 +44,7 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
||||||
address = InetSocketAddress.createUnresolved(
|
address = InetSocketAddress.createUnresolved(
|
||||||
ADDRESS_OVERRIDE == null ? localAddress : ADDRESS_OVERRIDE, config.port);
|
ADDRESS_OVERRIDE == null ? localAddress : ADDRESS_OVERRIDE, config.port);
|
||||||
publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
publicKey = SecurityHelper.toPublicRSAKey(input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH));
|
||||||
|
projectname = config.projectname;
|
||||||
// Read signed runtime
|
// Read signed runtime
|
||||||
int count = input.readLength(0);
|
int count = input.readLength(0);
|
||||||
Map<String, byte[]> localResources = new HashMap<>(count);
|
Map<String, byte[]> localResources = new HashMap<>(count);
|
||||||
|
@ -60,10 +62,19 @@ public LauncherConfig(HInput input) throws IOException, InvalidKeySpecException
|
||||||
}
|
}
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
|
@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
|
||||||
|
public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> 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<String, byte[]> runtime) {
|
public LauncherConfig(String address, int port, RSAPublicKey publicKey, Map<String, byte[]> runtime) {
|
||||||
this.address = InetSocketAddress.createUnresolved(address, port);
|
this.address = InetSocketAddress.createUnresolved(address, port);
|
||||||
this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
|
this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
|
||||||
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
|
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
|
||||||
|
this.projectname = "Minecraft";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,20 +3,57 @@
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Observable;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
public class HttpDownloader {
|
public class HttpDownloader extends Observable {
|
||||||
public static void downloadFile(URL url, String file) throws IOException {
|
public static final int BUFER_SIZE = 8192;
|
||||||
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
|
public static final int INTERVAL = 300;
|
||||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
public AtomicInteger writed = new AtomicInteger(0);
|
||||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue