[FIX] Не позволяем лаунчеру разжираться слишком сильно

This commit is contained in:
Gravit 2019-10-23 03:09:47 +07:00
parent e002d1a7e9
commit 89c412cda1
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 10 additions and 11 deletions

View file

@ -18,6 +18,7 @@ public SafeClassWriter(ClassMetadataReader classMetadataReader, int flags) {
this.classMetadataReader = classMetadataReader;
}
public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) {
super(classReader, flags);
this.classMetadataReader = classMetadataReader;

View file

@ -11,6 +11,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Predicate;
@ -69,16 +70,12 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L
output.putNextEntry(IOHelper.newZipEntry(e));
if (filename.endsWith(".class")) {
byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
IOHelper.transfer(input, outputStream);
bytes = outputStream.toByteArray();
}
try {
if(needFixes) bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers);
} catch (Throwable t) {
LogHelper.error(t);
}
if(needFixes) {
bytes = classFix(input, reader, srv.config.launcher.stripLineNumbers);
output.write(bytes);
}
else
IOHelper.transfer(input, output);
} else
IOHelper.transfer(input, output);
e = input.getNextEntry();
@ -87,8 +84,8 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L
}
}
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) {
ClassReader cr = new ClassReader(bytes);
private static byte[] classFix(InputStream input, ClassMetadataReader reader, boolean stripNumbers) throws IOException {
ClassReader cr = new ClassReader(input);
ClassNode cn = new ClassNode();
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

View file

@ -81,6 +81,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
}
Collections.addAll(args, MAGIC_ARG);
Collections.addAll(args, "-XX:+DisableAttachMechanism");
Collections.addAll(args, "-Xmx256M");
Collections.addAll(args, "-javaagent:".concat(pathLauncher));
Collections.addAll(args, "-cp");
Collections.addAll(args, pathLauncher);