mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Last fix before gradle scripts update and SignerJar restore.
This commit is contained in:
parent
81ef824b85
commit
de22bd3d33
6 changed files with 78 additions and 59 deletions
|
@ -1,9 +1,13 @@
|
||||||
package ru.gravit.launchserver.binary;
|
package ru.gravit.launchserver.binary;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import ru.gravit.launcher.Launcher;
|
import ru.gravit.launcher.Launcher;
|
||||||
|
@ -12,18 +16,34 @@
|
||||||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.StripLineNumbersTask;
|
import ru.gravit.launchserver.binary.tasks.AdditionalFixesApplyTask;
|
||||||
import ru.gravit.launchserver.binary.tasks.UnpackBuildTask;
|
import ru.gravit.launchserver.binary.tasks.UnpackBuildTask;
|
||||||
import ru.gravit.utils.helper.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public final class JARLauncherBinary extends LauncherBinary {
|
public final class JARLauncherBinary extends LauncherBinary {
|
||||||
|
private static final class ListFileVisitor extends SimpleFileVisitor<Path> {
|
||||||
|
private final List<Path> lst;
|
||||||
|
|
||||||
|
private ListFileVisitor(List<Path> lst) {
|
||||||
|
this.lst = lst;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
|
if (file.toFile().getName().endsWith(".jar"))
|
||||||
|
lst.add(file);
|
||||||
|
return super.visitFile(file, attrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public final AtomicLong count;
|
public final AtomicLong count;
|
||||||
public final Path runtimeDir;
|
public final Path runtimeDir;
|
||||||
public final Path guardDir;
|
public final Path guardDir;
|
||||||
public final Path buildDir;
|
public final Path buildDir;
|
||||||
public ArrayList<LauncherBuildTask> tasks;
|
public List<LauncherBuildTask> tasks;
|
||||||
|
public List<Path> coreLibs;
|
||||||
|
|
||||||
public JARLauncherBinary(LaunchServer server) throws IOException {
|
public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
super(server);
|
super(server);
|
||||||
|
@ -33,6 +53,7 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
|
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
|
||||||
buildDir = server.dir.resolve("build");
|
buildDir = server.dir.resolve("build");
|
||||||
tasks = new ArrayList<>();
|
tasks = new ArrayList<>();
|
||||||
|
coreLibs = new ArrayList<>();
|
||||||
Files.createDirectory(buildDir);
|
Files.createDirectory(buildDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,15 +61,17 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
|
||||||
public void init() {
|
public void init() {
|
||||||
tasks.add(new UnpackBuildTask(server));
|
tasks.add(new UnpackBuildTask(server));
|
||||||
tasks.add(new MainBuildTask(server));
|
tasks.add(new MainBuildTask(server));
|
||||||
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask(server));
|
tasks.add(new ProGuardBuildTask(server));
|
||||||
tasks.add(new AttachJarsTask(server));
|
tasks.add(new AttachJarsTask(server));
|
||||||
if(server.config.stripLineNumbers) tasks.add(new StripLineNumbersTask(server));
|
tasks.add(new AdditionalFixesApplyTask(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void build() throws IOException {
|
public void build() throws IOException {
|
||||||
LogHelper.info("Building launcher binary file");
|
LogHelper.info("Building launcher binary file");
|
||||||
count.set(0);
|
count.set(0);
|
||||||
|
coreLibs.clear();
|
||||||
|
IOHelper.walk(server.launcherLibraries, new ListFileVisitor(coreLibs), true);
|
||||||
Path thisPath = null;
|
Path thisPath = null;
|
||||||
boolean isNeedDelete = false;
|
boolean isNeedDelete = false;
|
||||||
long time_start = System.currentTimeMillis();
|
long time_start = System.currentTimeMillis();
|
||||||
|
@ -61,7 +84,7 @@ public void build() throws IOException {
|
||||||
long time_task_end = System.currentTimeMillis();
|
long time_task_end = System.currentTimeMillis();
|
||||||
long time_task = time_task_end - time_this;
|
long time_task = time_task_end - time_this;
|
||||||
time_this = time_task_end;
|
time_this = time_task_end;
|
||||||
if (isNeedDelete && server.config.deleteTempFiles) Files.delete(oldPath);
|
if (isNeedDelete && server.config.deleteTempFiles) Files.deleteIfExists(oldPath);
|
||||||
isNeedDelete = task.allowDelete();
|
isNeedDelete = task.allowDelete();
|
||||||
LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task);
|
LogHelper.subInfo("Task %s processed from %d millis",task.getName(), time_task);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +95,7 @@ public void build() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String nextName(String taskName) {
|
public String nextName(String taskName) {
|
||||||
return String.format("%s-%s-%d.jar", server.config.projectName, taskName, count.getAndIncrement());
|
return String.format("Launcher-%s-%d.jar", server.config.projectName, taskName, count.getAndIncrement());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Path nextPath(String taskName) {
|
public Path nextPath(String taskName) {
|
||||||
|
|
|
@ -10,33 +10,38 @@
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.asm.ClassMetadataReader;
|
import ru.gravit.launchserver.asm.ClassMetadataReader;
|
||||||
import ru.gravit.launchserver.asm.SafeClassWriter;
|
import ru.gravit.launchserver.asm.SafeClassWriter;
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
public class StripLineNumbersTask implements LauncherBuildTask {
|
public class AdditionalFixesApplyTask implements LauncherBuildTask {
|
||||||
private final LaunchServer server;
|
private final LaunchServer server;
|
||||||
|
|
||||||
public StripLineNumbersTask(LaunchServer server) {
|
public AdditionalFixesApplyTask(LaunchServer server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "StripDebug";
|
return "AdditionalFixesApply";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
Path out = server.launcherBinary.nextPath("stripped");
|
Path out = server.launcherBinary.nextPath("post-fixed");
|
||||||
try (ClassMetadataReader reader = new ClassMetadataReader()) {
|
try (ClassMetadataReader reader = new ClassMetadataReader()) {
|
||||||
reader.getCp().add(new JarFile(inputFile.toFile()));
|
reader.getCp().add(new JarFile(inputFile.toFile()));
|
||||||
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
try (ZipInputStream input = IOHelper.newZipInput(inputFile);
|
||||||
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
|
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(out))) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
|
if (e.isDirectory()) {
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String filename = e.getName();
|
String filename = e.getName();
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
if (filename.endsWith(".class")) {
|
if (filename.endsWith(".class")) {
|
||||||
|
@ -45,7 +50,7 @@ public Path process(Path inputFile) throws IOException {
|
||||||
IOHelper.transfer(input, outputStream);
|
IOHelper.transfer(input, outputStream);
|
||||||
bytes = outputStream.toByteArray();
|
bytes = outputStream.toByteArray();
|
||||||
}
|
}
|
||||||
output.write(classFix(bytes, reader));
|
output.write(classFix(bytes, reader, server.config.stripLineNumbers));
|
||||||
} else
|
} else
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
|
@ -55,10 +60,13 @@ public Path process(Path inputFile) throws IOException {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader) {
|
private static byte[] classFix(byte[] bytes, ClassMetadataReader reader, boolean stripNumbers) {
|
||||||
ClassReader cr = new ClassReader(bytes);
|
ClassReader cr = new ClassReader(bytes);
|
||||||
|
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);
|
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
cr.accept(cw, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
|
cn.accept(cw);
|
||||||
return cw.toByteArray();
|
return cw.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,9 @@
|
||||||
package ru.gravit.launchserver.binary.tasks;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.instrument.Instrumentation;
|
|
||||||
import java.nio.file.FileVisitResult;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarFile;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
@ -17,21 +12,6 @@
|
||||||
import ru.gravit.utils.helper.IOHelper;
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
public class AttachJarsTask implements LauncherBuildTask {
|
public class AttachJarsTask implements LauncherBuildTask {
|
||||||
private static final class ListFileVisitor extends SimpleFileVisitor<Path> {
|
|
||||||
private final List<Path> lst;
|
|
||||||
|
|
||||||
private ListFileVisitor(List<Path> lst) {
|
|
||||||
this.lst = lst;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
||||||
if (file.toFile().getName().endsWith(".jar"))
|
|
||||||
lst.add(file);
|
|
||||||
return super.visitFile(file, attrs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final LaunchServer srv;
|
private final LaunchServer srv;
|
||||||
private final List<Path> jars;
|
private final List<Path> jars;
|
||||||
private final List<String> exclusions;
|
private final List<String> exclusions;
|
||||||
|
@ -40,6 +20,7 @@ public AttachJarsTask(LaunchServer srv) {
|
||||||
this.srv = srv;
|
this.srv = srv;
|
||||||
jars = new ArrayList<>();
|
jars = new ArrayList<>();
|
||||||
exclusions = new ArrayList<>();
|
exclusions = new ArrayList<>();
|
||||||
|
exclusions.add("META-INF");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,13 +35,15 @@ public Path process(Path inputFile) throws IOException {
|
||||||
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) {
|
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputFile))) {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
|
if (e.isDirectory() || srv.buildHookManager.isContainsBlacklist(e.getName())) {
|
||||||
|
e = input.getNextEntry();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
}
|
}
|
||||||
List<Path> coreAttach = new ArrayList<>();
|
attach(output, srv.launcherBinary.coreLibs);
|
||||||
IOHelper.walk(srv.launcherLibraries, new ListFileVisitor(coreAttach), true);
|
|
||||||
attach(output, coreAttach);
|
|
||||||
attach(output, jars);
|
attach(output, jars);
|
||||||
}
|
}
|
||||||
return outputFile;
|
return outputFile;
|
||||||
|
@ -72,7 +55,7 @@ private void attach(ZipOutputStream output, List<Path> lst) throws IOException {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
String filename = e.getName();
|
String filename = e.getName();
|
||||||
if (exclusions.stream().noneMatch(filename::startsWith)) {
|
if (exclusions.stream().noneMatch(filename::startsWith) && !srv.buildHookManager.isContainsBlacklist(filename)) {
|
||||||
output.putNextEntry(IOHelper.newZipEntry(e));
|
output.putNextEntry(IOHelper.newZipEntry(e));
|
||||||
IOHelper.transfer(input, output);
|
IOHelper.transfer(input, output);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ public Path process(Path inputJar) throws IOException {
|
||||||
ZipEntry e = input.getNextEntry();
|
ZipEntry e = input.getNextEntry();
|
||||||
while (e != null) {
|
while (e != null) {
|
||||||
String filename = e.getName();
|
String filename = e.getName();
|
||||||
if (server.buildHookManager.isContainsBlacklist(filename)) {
|
if (server.buildHookManager.isContainsBlacklist(filename) || e.isDirectory()) {
|
||||||
e = input.getNextEntry();
|
e = input.getNextEntry();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import proguard.ParseException;
|
import proguard.ParseException;
|
||||||
import proguard.ProGuard;
|
import proguard.ProGuard;
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
|
import ru.gravit.utils.helper.IOHelper;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
public class ProGuardBuildTask implements LauncherBuildTask {
|
public class ProGuardBuildTask implements LauncherBuildTask {
|
||||||
|
@ -24,18 +25,24 @@ public String getName() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Path process(Path inputFile) throws IOException {
|
public Path process(Path inputFile) throws IOException {
|
||||||
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
if (server.config.enabledProGuard) {
|
||||||
Configuration proguard_cfg = new Configuration();
|
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
||||||
ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar),
|
Configuration proguard_cfg = new Configuration();
|
||||||
server.proguardConf.proguard.toFile(), System.getProperties());
|
ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar),
|
||||||
try {
|
server.proguardConf.proguard.toFile(), System.getProperties());
|
||||||
parser.parse(proguard_cfg);
|
try {
|
||||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
parser.parse(proguard_cfg);
|
||||||
proGuard.execute();
|
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||||
} catch (ParseException e) {
|
proGuard.execute();
|
||||||
LogHelper.error(e);
|
} catch (ParseException e) {
|
||||||
}
|
LogHelper.error(e);
|
||||||
return outputJar;
|
}
|
||||||
|
return outputJar;
|
||||||
|
} else {
|
||||||
|
Path outputJar = server.launcherBinary.nextPath("non-obf");
|
||||||
|
IOHelper.copy(inputFile, outputJar);
|
||||||
|
return outputJar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,30 +1,28 @@
|
||||||
package ru.gravit.launchserver.binary.tasks.api;
|
package ru.gravit.launchserver.binary.tasks;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
|
||||||
|
|
||||||
public final class TaskUtil {
|
public final class TaskUtil {
|
||||||
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
public static void addCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskAdd) {
|
||||||
List<Integer> indexes = new ArrayList<>();
|
List<LauncherBuildTask> indexes = new ArrayList<>();
|
||||||
tasks.stream().filter(pred).forEach(e -> {
|
tasks.stream().filter(pred).forEach(e -> {
|
||||||
indexes.add(tasks.indexOf(e)+count);
|
indexes.add(e);
|
||||||
});
|
});
|
||||||
indexes.forEach(e -> {
|
indexes.forEach(e -> {
|
||||||
tasks.add(e, taskAdd);
|
tasks.add(tasks.indexOf(e)+count, taskAdd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
public static void replaceCounted(List<LauncherBuildTask> tasks, int count, Predicate<LauncherBuildTask> pred, LauncherBuildTask taskRep) {
|
||||||
List<Integer> indexes = new ArrayList<>();
|
List<LauncherBuildTask> indexes = new ArrayList<>();
|
||||||
tasks.stream().filter(pred).forEach(e -> {
|
tasks.stream().filter(pred).forEach(e -> {
|
||||||
indexes.add(tasks.indexOf(e)+count);
|
indexes.add(e);
|
||||||
});
|
});
|
||||||
indexes.forEach(e -> {
|
indexes.forEach(e -> {
|
||||||
tasks.set(e, taskRep);
|
tasks.set(tasks.indexOf(e)+count, taskRep);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue