[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; this.classMetadataReader = classMetadataReader;
} }
public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) { public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) {
super(classReader, flags); super(classReader, flags);
this.classMetadataReader = classMetadataReader; this.classMetadataReader = classMetadataReader;

View file

@ -11,6 +11,7 @@
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.function.Predicate; 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)); output.putNextEntry(IOHelper.newZipEntry(e));
if (filename.endsWith(".class")) { if (filename.endsWith(".class")) {
byte[] bytes; byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) { if(needFixes) {
IOHelper.transfer(input, outputStream); bytes = classFix(input, reader, srv.config.launcher.stripLineNumbers);
bytes = outputStream.toByteArray(); output.write(bytes);
} }
try { else
if(needFixes) bytes = classFix(bytes, reader, srv.config.launcher.stripLineNumbers); IOHelper.transfer(input, output);
} catch (Throwable t) {
LogHelper.error(t);
}
output.write(bytes);
} else } else
IOHelper.transfer(input, output); IOHelper.transfer(input, output);
e = input.getNextEntry(); 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) { private static byte[] classFix(InputStream input, ClassMetadataReader reader, boolean stripNumbers) throws IOException {
ClassReader cr = new ClassReader(bytes); ClassReader cr = new ClassReader(input);
ClassNode cn = new ClassNode(); ClassNode cn = new ClassNode();
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES); cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); 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, MAGIC_ARG);
Collections.addAll(args, "-XX:+DisableAttachMechanism"); Collections.addAll(args, "-XX:+DisableAttachMechanism");
Collections.addAll(args, "-Xmx256M");
Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-javaagent:".concat(pathLauncher));
Collections.addAll(args, "-cp"); Collections.addAll(args, "-cp");
Collections.addAll(args, pathLauncher); Collections.addAll(args, pathLauncher);