HttpDownloader update

AvanguardStarter update
ProGuard update
This commit is contained in:
Gravit 2018-09-20 18:47:40 +07:00
parent a7dcfc4183
commit 303402310b
9 changed files with 76 additions and 37 deletions

View file

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

View file

@ -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() + "\'");
}

View file

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

View file

@ -1,8 +1,6 @@
-libraryjars '<java.home>/lib/rt.jar'
-libraryjars '<java.home>/lib/jce.jar'
-libraryjars '<java.home>/lib/ext/nashorn.jar'
-injars ../Launcher.jar
-outjars ../Launcher-obf.jar
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute Source

View file

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

View file

@ -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<Path> 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);

View file

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

View file

@ -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<String, byte[]> 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<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) {
this.address = InetSocketAddress.createUnresolved(address, port);
this.publicKey = Objects.requireNonNull(publicKey, "publicKey");
this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime));
this.projectname = "Minecraft";
}
@Override

View file

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