Удаление легаси говнокода

This commit is contained in:
Gravit 2019-01-06 19:20:25 +07:00
parent 9e0c94581c
commit d2858f7c37
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 1 additions and 152 deletions

View file

@ -1,52 +1,18 @@
package ru.gravit.launchserver.binary;
import static ru.gravit.utils.helper.IOHelper.newZipEntry;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javassist.CannotCompileException;
import javassist.NotFoundException;
import proguard.Configuration;
import proguard.ConfigurationParser;
import proguard.ParseException;
import proguard.ProGuard;
import ru.gravit.launcher.AutogenConfig;
import ru.gravit.launcher.Launcher;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.asm.ClassMetadataReader;
import ru.gravit.launchserver.binary.tasks.LauncherBuildTask;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.launchserver.binary.tasks.ProGuardBuildTask;
import ru.gravit.launchserver.binary.tasks.UnpackBuildTask;
import ru.gravit.launchserver.manangers.hook.BuildHookManager.ZipBuildHook;
import ru.gravit.utils.helper.CommonHelper;
import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.SecurityHelper;
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
import ru.gravit.utils.helper.UnpackHelper;
public final class JARLauncherBinary extends LauncherBinary {
//public ClassMetadataReader reader;
public ArrayList<LauncherBuildTask> tasks;
public JARLauncherBinary(LaunchServer server) throws IOException {
super(server);
@ -55,16 +21,6 @@ public JARLauncherBinary(LaunchServer server) throws IOException {
tasks.add(new MainBuildTask());
if(server.config.enabledProGuard) tasks.add(new ProGuardBuildTask());
syncBinaryFile = server.dir.resolve(server.config.binaryName + ".jar");
/*runtimeDir = server.dir.resolve(Launcher.RUNTIME_DIR);
guardDir = server.dir.resolve(Launcher.GUARD_DIR);
initScriptFile = runtimeDir.resolve(Launcher.INIT_SCRIPT_FILE);
obfJar = server.dir.resolve(server.config.binaryName + "-obfPre.jar");
obfOutJar = server.config.buildPostTransform.enabled ? server.dir.resolve(server.config.binaryName + "-obf.jar")
: syncBinaryFile;
cleanJar = server.dir.resolve(server.config.binaryName + "-clean.jar");
reader = new ClassMetadataReader();
UnpackHelper.unpack(IOHelper.getResourceURL("Launcher.jar"), cleanJar);
reader.getCp().add(new JarFile(cleanJar.toFile()));*/
}
@Override
@ -90,53 +46,5 @@ public void build() throws IOException {
long time_end = System.currentTimeMillis();
IOHelper.move(thisPath, syncBinaryFile);
LogHelper.info("Build successful from %d millis",time_end - time_start);
// ProGuard
/*for (Runnable r : server.buildHookManager.getPostProguardRunHooks())
r.run();
try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(obfJar));
ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(obfOutJar))) {
ZipEntry e = input.getNextEntry();
while (e != null) {
String filename = e.getName();
output.putNextEntry(IOHelper.newZipEntry(e));
if (filename.endsWith(".class")) {
String classname = filename.replace('/', '.').substring(0, filename.length() - ".class".length());
byte[] bytes;
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048)) {
IOHelper.transfer(input, outputStream);
bytes = outputStream.toByteArray();
}
//bytes = server.buildHookManager.proGuardClassTransform(bytes, classname, this);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes)) {
IOHelper.transfer(inputStream, output);
}
} else
IOHelper.transfer(input, output);
e = input.getNextEntry();
}
for (ZipBuildHook h : server.buildHookManager.getProguardBuildHooks())
h.build(output);
}
if (server.config.buildPostTransform.enabled)
transformedBuild();*/
}
private void transformedBuild() throws IOException {
/*List<String> cmd = new ArrayList<>(1);
for (String v : server.config.buildPostTransform.script)
cmd.add(CommonHelper.replace(v, "launcher-output", IOHelper.toAbsPathString(syncBinaryFile), "launcher-obf",
IOHelper.toAbsPathString(obfJar), "launcher-nonObf", IOHelper.toAbsPathString(binaryFile)));
ProcessBuilder builder = new ProcessBuilder();
builder.directory(IOHelper.toAbsPath(server.dir).toFile());
builder.inheritIO();
builder.command(cmd);
Process proc = builder.start();
try {
LogHelper.debug("Transformer process return code: " + proc.waitFor());
} catch (InterruptedException e) {
LogHelper.error(e);
}*/
}
}

View file

@ -1,43 +0,0 @@
package ru.gravit.launchserver.manangers;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import ru.gravit.launcher.LauncherConfig;
import ru.gravit.launchserver.asm.SafeClassWriter;
import ru.gravit.launchserver.binary.JARLauncherBinary;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.launchserver.manangers.hook.BuildHookManager.Transformer;
public class NodeTransformer implements Transformer {
@FunctionalInterface
public interface ClassNodeTransformer {
void transform(ClassNode node, String classname, JARLauncherBinary data);
}
private final List<ClassNodeTransformer> transLst;
public List<ClassNodeTransformer> getTransLst() {
return transLst;
}
public NodeTransformer() {
transLst = new ArrayList<>();
}
@Override
public byte[] transform(byte[] input, String classname, MainBuildTask data) {
//ClassReader cr = new ClassReader(input);
//ClassNode cn = new ClassNode();
//cr.accept(cn, data.server.config.env.equals(LauncherConfig.LauncherEnvironment.PROD) || data.server.config.env.equals(LauncherConfig.LauncherEnvironment.STD) ? ClassReader.SKIP_DEBUG : 0);
//for (ClassNodeTransformer tr : transLst) tr.transform(cn, classname, data);
//ClassWriter cw = new SafeClassWriter(data.reader, ClassWriter.COMPUTE_MAXS);
//cn.accept(cw);
//return cw.toByteArray();
return null;
}
}

View file

@ -10,9 +10,7 @@
import ru.gravit.launcher.modules.TestClientModule;
import ru.gravit.launchserver.binary.BuildContext;
import ru.gravit.launchserver.binary.JAConfigurator;
import ru.gravit.launchserver.binary.JARLauncherBinary;
import ru.gravit.launchserver.binary.tasks.MainBuildTask;
import ru.gravit.launchserver.manangers.NodeTransformer;
public class BuildHookManager {
@FunctionalInterface
@ -40,8 +38,6 @@ public interface Transformer {
private final Set<String> CLASS_BLACKLIST;
private final Set<String> MODULE_CLASS;
private final Map<String, byte[]> INCLUDE_CLASS;
private final NodeTransformer noder;
private final NodeTransformer proguardNoder;
public BuildHookManager() {
POST_HOOKS = new HashSet<>(4);
@ -59,18 +55,6 @@ public BuildHookManager() {
registerIgnoredClass("META-INF/LICENSE");
registerIgnoredClass("META-INF/NOTICE");
registerClientModuleClass(TestClientModule.class.getName());
noder = new NodeTransformer();
registerClassTransformer(noder);
proguardNoder = new NodeTransformer();
registerProGuardHook(proguardNoder);
}
public NodeTransformer getProguardNoder() {
return proguardNoder;
}
public NodeTransformer getNoder() {
return noder;
}
public Set<ZipBuildHook> getProguardBuildHooks() {
@ -157,7 +141,7 @@ public void registerProGuardHook(Transformer hook) {
}
public boolean isNeedPostProguardHook() {
return POST_PROGUARD_HOOKS.size() > 1 || !POST_PROGUARDRUN_HOOKS.isEmpty() || !POST_PROGUARD_BUILDHOOKS.isEmpty() || !proguardNoder.getTransLst().isEmpty();
return POST_PROGUARD_HOOKS.size() > 1 || !POST_PROGUARDRUN_HOOKS.isEmpty() || !POST_PROGUARD_BUILDHOOKS.isEmpty();
}
public void registerPreHook(BuildHook hook) {