mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] ProGuard Component
This commit is contained in:
parent
1452b59fa5
commit
63891cd743
18 changed files with 259 additions and 340 deletions
|
@ -79,7 +79,6 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
|
|||
public final FeaturesManager featuresManager;
|
||||
// HWID ban + anti-brutforce
|
||||
public final CertificateManager certificateManager;
|
||||
public final ProguardConf proguardConf;
|
||||
// Server
|
||||
public final CommandHandler commandHandler;
|
||||
public final NettyServerSocketHandler nettyServerSocketHandler;
|
||||
|
@ -126,17 +125,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
runtime.verify();
|
||||
config.verify();
|
||||
if (config.sessions == null) config.sessions = new MemorySessionStorage();
|
||||
if (config.components != null) {
|
||||
LogHelper.debug("PreInit components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("PreInit component %s", k);
|
||||
v.preInit(this);
|
||||
});
|
||||
LogHelper.debug("PreInit components successful");
|
||||
}
|
||||
|
||||
// build hooks, anti-brutforce and other
|
||||
proguardConf = new ProguardConf(this);
|
||||
sessionManager = new SessionManager(this);
|
||||
mirrorManager = new MirrorManager();
|
||||
reconfigurableManager = new ReconfigurableManager();
|
||||
|
@ -154,14 +144,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
|
||||
// init modules
|
||||
modulesManager.invokeEvent(new LaunchServerInitPhase(this));
|
||||
if (config.components != null) {
|
||||
LogHelper.debug("Init components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("Init component %s", k);
|
||||
v.init(this);
|
||||
});
|
||||
LogHelper.debug("Init components successful");
|
||||
}
|
||||
|
||||
// Set launcher EXE binary
|
||||
launcherBinary = new JARLauncherBinary(this);
|
||||
|
@ -171,6 +153,15 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
launcherEXEBinary.init();
|
||||
syncLauncherBinaries();
|
||||
launcherModuleLoader = new LauncherModuleLoader(this);
|
||||
if (config.components != null) {
|
||||
LogHelper.debug("Init components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("Init component %s", k);
|
||||
v.setComponentName(k);
|
||||
v.init(this);
|
||||
});
|
||||
LogHelper.debug("Init components successful");
|
||||
}
|
||||
// Sync updates dir
|
||||
if (!IOHelper.isDir(updatesDir))
|
||||
Files.createDirectory(updatesDir);
|
||||
|
@ -184,14 +175,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
nettyServerSocketHandler = new NettyServerSocketHandler(this);
|
||||
// post init modules
|
||||
modulesManager.invokeEvent(new LaunchServerPostInitPhase(this));
|
||||
if (config.components != null) {
|
||||
LogHelper.debug("PostInit components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("PostInit component %s", k);
|
||||
v.postInit(this);
|
||||
});
|
||||
LogHelper.debug("PostInit components successful");
|
||||
}
|
||||
}
|
||||
|
||||
public void reload(ReloadType type) throws Exception {
|
||||
|
@ -209,24 +192,13 @@ public void reload(ReloadType type) throws Exception {
|
|||
config.verify();
|
||||
config.init(type);
|
||||
if (type.equals(ReloadType.FULL) && config.components != null) {
|
||||
LogHelper.debug("PreInit components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("PreInit component %s", k);
|
||||
v.preInit(this);
|
||||
});
|
||||
LogHelper.debug("PreInit components successful");
|
||||
LogHelper.debug("Init components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("Init component %s", k);
|
||||
v.setComponentName(k);
|
||||
v.init(this);
|
||||
});
|
||||
LogHelper.debug("Init components successful");
|
||||
LogHelper.debug("PostInit components");
|
||||
config.components.forEach((k, v) -> {
|
||||
LogHelper.subDebug("PostInit component %s", k);
|
||||
v.postInit(this);
|
||||
});
|
||||
LogHelper.debug("PostInit components successful");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import pro.gravit.utils.command.Command;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -15,4 +16,8 @@ public interface Reconfigurable {
|
|||
* Value is a command object
|
||||
*/
|
||||
Map<String, Command> getCommands();
|
||||
|
||||
default Map<String, Command> defaultCommandsMap() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import pro.gravit.launcher.Launcher;
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.binary.tasks.*;
|
||||
import pro.gravit.launchserver.components.ProGuardComponent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -38,10 +39,8 @@ public void init() {
|
|||
tasks.add(new PrepareBuildTask(server));
|
||||
if (!server.config.sign.enabled) tasks.add(new CertificateAutogenTask(server));
|
||||
tasks.add(new MainBuildTask(server));
|
||||
if (server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
||||
tasks.add(new ProGuardBuildTask(server));
|
||||
tasks.add(new AttachJarsTask(server));
|
||||
tasks.add(new AdditionalFixesApplyTask(server));
|
||||
if (!server.config.launcher.attachLibraryBeforeProGuard) tasks.add(new AttachJarsTask(server));
|
||||
if (server.config.launcher.compress) tasks.add(new CompressBuildTask(server));
|
||||
tasks.add(new SignJarTask(server.config.sign, server));
|
||||
}
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
package pro.gravit.launchserver.binary;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.utils.helper.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ProguardConf {
|
||||
public static final String[] JAVA9_OPTS = new String[]{
|
||||
"-libraryjars '<java.home>/jmods/'"
|
||||
};
|
||||
public static final String[] JAVA8_OPTS = new String[]{
|
||||
"-libraryjars '<java.home>/lib/rt.jar'",
|
||||
"-libraryjars '<java.home>/lib/jce.jar'",
|
||||
"-libraryjars '<java.home>/lib/ext/nashorn.jar'",
|
||||
"-libraryjars '<java.home>/lib/ext/jfxrt.jar'"
|
||||
};
|
||||
private static final char[] chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ".toCharArray();
|
||||
public final Path proguard;
|
||||
public final Path config;
|
||||
public final Path mappings;
|
||||
public final Path words;
|
||||
public transient final LaunchServer srv;
|
||||
|
||||
public ProguardConf(LaunchServer srv) {
|
||||
proguard = srv.dir.resolve("proguard");
|
||||
config = proguard.resolve("proguard.config");
|
||||
mappings = proguard.resolve("mappings.pro");
|
||||
words = proguard.resolve("random.pro");
|
||||
this.srv = srv;
|
||||
}
|
||||
|
||||
private static String generateString(SecureRandom rand, String lowString, String upString, int il) {
|
||||
StringBuilder sb = new StringBuilder(Math.max(il, lowString.length()));
|
||||
for (int i = 0; i < lowString.length(); ++i) {
|
||||
sb.append(rand.nextBoolean() ? lowString.charAt(i) : upString.charAt(i));
|
||||
}
|
||||
int toI = il - lowString.length();
|
||||
for (int i = 0; i < toI; i++) sb.append(chars[rand.nextInt(chars.length)]);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String[] buildConfig(Path inputJar, Path outputJar) {
|
||||
List<String> confStrs = new ArrayList<>();
|
||||
prepare(false);
|
||||
if (srv.config.launcher.proguardGenMappings)
|
||||
confStrs.add("-printmapping '" + mappings.toFile().getName() + "'");
|
||||
confStrs.add("-obfuscationdictionary '" + words.toFile().getName() + "'");
|
||||
confStrs.add("-injar '" + inputJar.toAbsolutePath() + "'");
|
||||
confStrs.add("-outjar '" + outputJar.toAbsolutePath() + "'");
|
||||
Collections.addAll(confStrs, JVMHelper.JVM_VERSION >= 9 ? JAVA9_OPTS : JAVA8_OPTS);
|
||||
srv.launcherBinary.coreLibs.stream()
|
||||
.map(e -> "-libraryjars '" + e.toAbsolutePath().toString() + "'")
|
||||
.forEach(confStrs::add);
|
||||
|
||||
srv.launcherBinary.addonLibs.stream()
|
||||
.map(e -> "-libraryjars '" + e.toAbsolutePath().toString() + "'")
|
||||
.forEach(confStrs::add);
|
||||
confStrs.add("-classobfuscationdictionary '" + words.toFile().getName() + "'");
|
||||
confStrs.add("@".concat(config.toFile().getName()));
|
||||
return confStrs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void genConfig(boolean force) throws IOException {
|
||||
if (IOHelper.exists(config) && !force) return;
|
||||
Files.deleteIfExists(config);
|
||||
UnpackHelper.unpack(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/proguard.cfg"), config);
|
||||
}
|
||||
|
||||
public void genWords(boolean force) throws IOException {
|
||||
if (IOHelper.exists(words) && !force) return;
|
||||
Files.deleteIfExists(words);
|
||||
SecureRandom rand = SecurityHelper.newRandom();
|
||||
rand.setSeed(SecureRandom.getSeed(32));
|
||||
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(IOHelper.newOutput(words), IOHelper.UNICODE_CHARSET))) {
|
||||
String projectName = srv.config.projectName.replaceAll("\\W", "");
|
||||
String lowName = projectName.toLowerCase();
|
||||
String upName = projectName.toUpperCase();
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) out.println(generateString(rand, lowName, upName, 14));
|
||||
}
|
||||
}
|
||||
|
||||
public void prepare(boolean force) {
|
||||
try {
|
||||
IOHelper.createParentDirs(config);
|
||||
genWords(force);
|
||||
genConfig(force);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package pro.gravit.launchserver.binary.tasks;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
import pro.gravit.utils.helper.JVMHelper;
|
||||
import pro.gravit.utils.helper.LogHelper;
|
||||
import proguard.Configuration;
|
||||
import proguard.ConfigurationParser;
|
||||
import proguard.ParseException;
|
||||
import proguard.ProGuard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class ProGuardBuildTask implements LauncherBuildTask {
|
||||
private final LaunchServer server;
|
||||
|
||||
public ProGuardBuildTask(LaunchServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ProGuard";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path process(Path inputFile) throws IOException {
|
||||
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
||||
if (server.config.launcher.enabledProGuard) {
|
||||
Configuration proguard_cfg = new Configuration();
|
||||
ConfigurationParser parser = new ConfigurationParser(server.proguardConf.buildConfig(inputFile, outputJar),
|
||||
server.proguardConf.proguard.toFile(), System.getProperties());
|
||||
if (JVMHelper.JVM_VERSION >= 9) {
|
||||
Path javaJModsPath = Paths.get(System.getProperty("java.home")).resolve("jmods");
|
||||
if (!IOHelper.exists(javaJModsPath)) {
|
||||
LogHelper.warning("Directory %s not found. It is not good", javaJModsPath);
|
||||
} else {
|
||||
//Find javaFX libraries
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.base.jmod")))
|
||||
LogHelper.error("javafx.base.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.graphics.jmod")))
|
||||
LogHelper.error("javafx.graphics.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.controls.jmod")))
|
||||
LogHelper.error("javafx.controls.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
}
|
||||
}
|
||||
try {
|
||||
parser.parse(proguard_cfg);
|
||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||
proGuard.execute();
|
||||
} catch (ParseException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
} else
|
||||
IOHelper.copy(inputFile, outputJar);
|
||||
return outputJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowDelete() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package pro.gravit.launchserver.command.basic;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class ProguardCleanCommand extends Command {
|
||||
public ProguardCleanCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "Resets proguard config";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
server.proguardConf.prepare(true);
|
||||
Files.deleteIfExists(server.proguardConf.mappings);
|
||||
}
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package pro.gravit.launchserver.command.basic;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RegenProguardDictCommand extends Command {
|
||||
|
||||
public RegenProguardDictCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "Regenerates proguard dictonary";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
server.proguardConf.genWords(true);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package pro.gravit.launchserver.command.basic;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.command.Command;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class RemoveMappingsProguardCommand extends Command {
|
||||
|
||||
public RemoveMappingsProguardCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "Removes proguard mappings (if you want to gen new mappings).";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws IOException {
|
||||
Files.deleteIfExists(server.proguardConf.mappings);
|
||||
}
|
||||
|
||||
}
|
|
@ -27,9 +27,6 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand
|
|||
basic.registerCommand("debug", new DebugCommand());
|
||||
basic.registerCommand("clear", new ClearCommand(handler));
|
||||
basic.registerCommand("gc", new GCCommand());
|
||||
basic.registerCommand("proguardClean", new ProguardCleanCommand(server));
|
||||
basic.registerCommand("proguardDictRegen", new RegenProguardDictCommand(server));
|
||||
basic.registerCommand("proguardMappingsRemove", new RemoveMappingsProguardCommand(server));
|
||||
basic.registerCommand("loadModule", new LoadModuleCommand(server));
|
||||
basic.registerCommand("modules", new ModulesCommand(server));
|
||||
basic.registerCommand("test", new TestCommand(server));
|
||||
|
|
|
@ -75,9 +75,8 @@ public void invoke(String... args) throws Exception {
|
|||
String fileName = args[2];
|
||||
try (Reader reader = IOHelper.newReader(Paths.get(fileName))) {
|
||||
Component component = Launcher.gsonManager.configGson.fromJson(reader, Component.class);
|
||||
component.preInit(server);
|
||||
component.setComponentName(componentName);
|
||||
component.init(server);
|
||||
component.postInit(server);
|
||||
LogHelper.info("Component %s(%s) loaded", componentName, component.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,12 @@ public class AuthLimiterComponent extends IPLimiter implements NeedGarbageCollec
|
|||
public String message;
|
||||
private transient LaunchServer srv;
|
||||
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
srv = launchServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer launchServer) {
|
||||
srv = launchServer;
|
||||
launchServer.authHookManager.preHook.registerHook(this::preAuthHook);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(LaunchServer launchServer) {
|
||||
|
||||
}
|
||||
|
||||
public boolean preAuthHook(AuthResponse.AuthContext context, Client client) {
|
||||
if (!check(context.ip)) {
|
||||
throw new HookException(message);
|
||||
|
|
|
@ -11,18 +11,9 @@ public class CommandRemoverComponent extends Component implements AutoCloseable
|
|||
public final transient Map<String, Command> commandsList = new HashMap<>();
|
||||
private transient LaunchServer server = null;
|
||||
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
server = launchServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer launchServer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(LaunchServer launchServer) {
|
||||
server = launchServer;
|
||||
for (String cmd : removeList) {
|
||||
Command removedCmd = launchServer.commandHandler.unregisterCommand(cmd);
|
||||
if (removedCmd != null)
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
public abstract class Component {
|
||||
public static final ProviderMap<Component> providers = new ProviderMap<>();
|
||||
private static boolean registredComp = false;
|
||||
protected String componentName;
|
||||
|
||||
public static void registerComponents() {
|
||||
if (!registredComp) {
|
||||
|
@ -16,9 +17,19 @@ public static void registerComponents() {
|
|||
}
|
||||
}
|
||||
|
||||
public abstract void preInit(LaunchServer launchServer);
|
||||
@Deprecated
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
|
||||
}
|
||||
|
||||
public abstract void init(LaunchServer launchServer);
|
||||
|
||||
public abstract void postInit(LaunchServer launchServer);
|
||||
public final void setComponentName(String s) {
|
||||
this.componentName = s;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void postInit(LaunchServer launchServer) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,208 @@
|
|||
package pro.gravit.launchserver.components;
|
||||
|
||||
import pro.gravit.launchserver.LaunchServer;
|
||||
import pro.gravit.launchserver.Reconfigurable;
|
||||
import pro.gravit.launchserver.binary.tasks.LauncherBuildTask;
|
||||
import pro.gravit.utils.command.Command;
|
||||
import pro.gravit.utils.command.SubCommand;
|
||||
import pro.gravit.utils.helper.*;
|
||||
import proguard.Configuration;
|
||||
import proguard.ConfigurationParser;
|
||||
import proguard.ParseException;
|
||||
import proguard.ProGuard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
|
||||
public class ProGuardComponent extends Component implements AutoCloseable, Reconfigurable {
|
||||
public String modeAfter = "MainBuild";
|
||||
public String dir = "proguard";
|
||||
public boolean enabled = true;
|
||||
public boolean mappings = true;
|
||||
public transient ProguardConf proguardConf;
|
||||
@Override
|
||||
public void init(LaunchServer launchServer) {
|
||||
proguardConf = new ProguardConf(launchServer, this);
|
||||
launchServer.launcherBinary.add((v) -> v.getName().startsWith(modeAfter), new ProGuardBuildTask(launchServer, proguardConf, this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Command> getCommands() {
|
||||
Map<String, Command> commands = defaultCommandsMap();
|
||||
commands.put("reset", new SubCommand("[]", "reset proguard config") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
proguardConf.prepare(true);
|
||||
Files.deleteIfExists(proguardConf.mappings);
|
||||
}
|
||||
});
|
||||
commands.put("regen", new SubCommand("[]", "regenerate proguard dictionary") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
proguardConf.genWords(true);
|
||||
}
|
||||
});
|
||||
commands.put("clean", new SubCommand("[]", "clean proguard mappings") {
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
proguardConf.prepare(true);
|
||||
Files.deleteIfExists(proguardConf.mappings);
|
||||
}
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ProGuardBuildTask implements LauncherBuildTask {
|
||||
private final LaunchServer server;
|
||||
private final ProGuardComponent component;
|
||||
private final ProguardConf proguardConf;
|
||||
|
||||
public ProGuardBuildTask(LaunchServer server, ProguardConf conf, ProGuardComponent component) {
|
||||
this.server = server;
|
||||
this.component = component;
|
||||
this.proguardConf = conf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ProGuard.".concat(component.componentName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path process(Path inputFile) throws IOException {
|
||||
Path outputJar = server.launcherBinary.nextLowerPath(this);
|
||||
if (component.enabled) {
|
||||
Configuration proguard_cfg = new Configuration();
|
||||
ConfigurationParser parser = new ConfigurationParser(proguardConf.buildConfig(inputFile, outputJar),
|
||||
proguardConf.proguard.toFile(), System.getProperties());
|
||||
if (JVMHelper.JVM_VERSION >= 9) {
|
||||
Path javaJModsPath = Paths.get(System.getProperty("java.home")).resolve("jmods");
|
||||
if (!IOHelper.exists(javaJModsPath)) {
|
||||
LogHelper.warning("Directory %s not found. It is not good", javaJModsPath);
|
||||
} else {
|
||||
//Find javaFX libraries
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.base.jmod")))
|
||||
LogHelper.error("javafx.base.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.graphics.jmod")))
|
||||
LogHelper.error("javafx.graphics.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
if (!IOHelper.exists(javaJModsPath.resolve("javafx.controls.jmod")))
|
||||
LogHelper.error("javafx.controls.jmod not found. Launcher can be assembled incorrectly. Maybe you need to install OpenJFX?");
|
||||
}
|
||||
}
|
||||
try {
|
||||
parser.parse(proguard_cfg);
|
||||
ProGuard proGuard = new ProGuard(proguard_cfg);
|
||||
proGuard.execute();
|
||||
} catch (ParseException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
} else
|
||||
IOHelper.copy(inputFile, outputJar);
|
||||
return outputJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowDelete() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProguardConf {
|
||||
public static final String[] JAVA9_OPTS = new String[]{
|
||||
"-libraryjars '<java.home>/jmods/'"
|
||||
};
|
||||
public static final String[] JAVA8_OPTS = new String[]{
|
||||
"-libraryjars '<java.home>/lib/rt.jar'",
|
||||
"-libraryjars '<java.home>/lib/jce.jar'",
|
||||
"-libraryjars '<java.home>/lib/ext/nashorn.jar'",
|
||||
"-libraryjars '<java.home>/lib/ext/jfxrt.jar'"
|
||||
};
|
||||
private static final char[] chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ".toCharArray();
|
||||
public final Path proguard;
|
||||
public final Path config;
|
||||
public final Path mappings;
|
||||
public final Path words;
|
||||
public transient final LaunchServer srv;
|
||||
private transient final ProGuardComponent component;
|
||||
|
||||
public ProguardConf(LaunchServer srv, ProGuardComponent component) {
|
||||
this.component = component;
|
||||
this.proguard = srv.dir.resolve(component.dir);
|
||||
config = proguard.resolve("proguard.config");
|
||||
mappings = proguard.resolve("mappings.pro");
|
||||
words = proguard.resolve("random.pro");
|
||||
this.srv = srv;
|
||||
}
|
||||
|
||||
private static String generateString(SecureRandom rand, String lowString, String upString, int il) {
|
||||
StringBuilder sb = new StringBuilder(Math.max(il, lowString.length()));
|
||||
for (int i = 0; i < lowString.length(); ++i) {
|
||||
sb.append(rand.nextBoolean() ? lowString.charAt(i) : upString.charAt(i));
|
||||
}
|
||||
int toI = il - lowString.length();
|
||||
for (int i = 0; i < toI; i++) sb.append(chars[rand.nextInt(chars.length)]);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String[] buildConfig(Path inputJar, Path outputJar) {
|
||||
List<String> confStrs = new ArrayList<>();
|
||||
prepare(false);
|
||||
if (component.mappings)
|
||||
confStrs.add("-printmapping '" + mappings.toFile().getName() + "'");
|
||||
confStrs.add("-obfuscationdictionary '" + words.toFile().getName() + "'");
|
||||
confStrs.add("-injar '" + inputJar.toAbsolutePath() + "'");
|
||||
confStrs.add("-outjar '" + outputJar.toAbsolutePath() + "'");
|
||||
Collections.addAll(confStrs, JVMHelper.JVM_VERSION >= 9 ? JAVA9_OPTS : JAVA8_OPTS);
|
||||
srv.launcherBinary.coreLibs.stream()
|
||||
.map(e -> "-libraryjars '" + e.toAbsolutePath().toString() + "'")
|
||||
.forEach(confStrs::add);
|
||||
|
||||
srv.launcherBinary.addonLibs.stream()
|
||||
.map(e -> "-libraryjars '" + e.toAbsolutePath().toString() + "'")
|
||||
.forEach(confStrs::add);
|
||||
confStrs.add("-classobfuscationdictionary '" + words.toFile().getName() + "'");
|
||||
confStrs.add("@".concat(config.toFile().getName()));
|
||||
return confStrs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void genConfig(boolean force) throws IOException {
|
||||
if (IOHelper.exists(config) && !force) return;
|
||||
Files.deleteIfExists(config);
|
||||
UnpackHelper.unpack(IOHelper.getResourceURL("pro/gravit/launchserver/defaults/proguard.cfg"), config);
|
||||
}
|
||||
|
||||
public void genWords(boolean force) throws IOException {
|
||||
if (IOHelper.exists(words) && !force) return;
|
||||
Files.deleteIfExists(words);
|
||||
SecureRandom rand = SecurityHelper.newRandom();
|
||||
rand.setSeed(SecureRandom.getSeed(32));
|
||||
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(IOHelper.newOutput(words), IOHelper.UNICODE_CHARSET))) {
|
||||
String projectName = srv.config.projectName.replaceAll("\\W", "");
|
||||
String lowName = projectName.toLowerCase();
|
||||
String upName = projectName.toUpperCase();
|
||||
for (int i = 0; i < Short.MAX_VALUE; i++) out.println(generateString(rand, lowName, upName, 14));
|
||||
}
|
||||
}
|
||||
|
||||
public void prepare(boolean force) {
|
||||
try {
|
||||
IOHelper.createParentDirs(config);
|
||||
genWords(force);
|
||||
genConfig(force);
|
||||
} catch (IOException e) {
|
||||
LogHelper.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,18 +15,9 @@ public class RegLimiterComponent extends IPLimiter implements NeedGarbageCollect
|
|||
|
||||
public List<String> excludeIps = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void preInit(LaunchServer launchServer) {
|
||||
this.launchServer = launchServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(LaunchServer launchServer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(LaunchServer launchServer) {
|
||||
this.launchServer = launchServer;
|
||||
launchServer.authHookManager.registraion.registerHook(this::registerHook);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
import pro.gravit.launchserver.binary.tasks.exe.Launch4JTask;
|
||||
import pro.gravit.launchserver.components.AuthLimiterComponent;
|
||||
import pro.gravit.launchserver.components.Component;
|
||||
import pro.gravit.launchserver.components.ProGuardComponent;
|
||||
import pro.gravit.launchserver.components.RegLimiterComponent;
|
||||
import pro.gravit.launchserver.dao.provider.DaoProvider;
|
||||
import pro.gravit.utils.Version;
|
||||
|
@ -93,11 +94,8 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
|||
newConfig.launcher = new LauncherConf();
|
||||
newConfig.launcher.guardType = "no";
|
||||
newConfig.launcher.compress = true;
|
||||
newConfig.launcher.attachLibraryBeforeProGuard = false;
|
||||
newConfig.launcher.deleteTempFiles = true;
|
||||
newConfig.launcher.enabledProGuard = true;
|
||||
newConfig.launcher.stripLineNumbers = true;
|
||||
newConfig.launcher.proguardGenMappings = true;
|
||||
|
||||
newConfig.sign = new JarSignerConf();
|
||||
|
||||
|
@ -112,6 +110,8 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) {
|
|||
regLimiterComponent.rateLimitMillis = 1000 * 60 * 60 * 10; //Блок на 10 часов
|
||||
regLimiterComponent.message = "Превышен лимит регистраций";
|
||||
newConfig.components.put("regLimiter", regLimiterComponent);
|
||||
ProGuardComponent proGuardComponent = new ProGuardComponent();
|
||||
newConfig.components.put("proguard", proGuardComponent);
|
||||
return newConfig;
|
||||
}
|
||||
|
||||
|
@ -293,14 +293,11 @@ public static class NettyUpdatesBind {
|
|||
|
||||
public static class LauncherConf {
|
||||
public String guardType;
|
||||
public boolean attachLibraryBeforeProGuard;
|
||||
public boolean compress;
|
||||
@Deprecated
|
||||
public boolean warningMissArchJava;
|
||||
public boolean enabledProGuard;
|
||||
public boolean stripLineNumbers;
|
||||
public boolean deleteTempFiles;
|
||||
public boolean proguardGenMappings;
|
||||
public boolean certificatePinning;
|
||||
public int memoryLimit = 256;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
package pro.gravit.utils.command;
|
||||
|
||||
public abstract class SubCommand extends Command {
|
||||
private String defaultArgs;
|
||||
private String defaultUsage;
|
||||
|
||||
public SubCommand() {
|
||||
}
|
||||
|
||||
public SubCommand(String defaultArgs, String defaultUsage) {
|
||||
this.defaultArgs = defaultArgs;
|
||||
this.defaultUsage = defaultUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return null;
|
||||
return defaultArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return null;
|
||||
return defaultUsage;
|
||||
}
|
||||
}
|
||||
|
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit 02ff0dc35355d47dc181d93acb1bf11d6eb57bc4
|
||||
Subproject commit 34cece4a9809b12ddc6c13d89c7bd7daabcb2068
|
Loading…
Reference in a new issue