Skip to content

Commit

Permalink
Фикс бага с FileNameMatcher из основной ветки лаунчера
Browse files Browse the repository at this point in the history
  • Loading branch information
Gravit Gravit committed Aug 10, 2018
1 parent a3fabb9 commit a215c5e
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 65 deletions.
2 changes: 0 additions & 2 deletions LaunchServer/source/LaunchServer.java
Expand Up @@ -5,7 +5,6 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URL;
import java.nio.file.DirectoryStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand Down Expand Up @@ -337,7 +336,6 @@ private void generateConfigIfNotExists() throws IOException {
}

public static void main(String... args) throws Throwable {
SecurityHelper.verifyCertificates(LaunchServer.class);
JVMHelper.verifySystemProperties(LaunchServer.class, true);
LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log"));
LogHelper.printVersion("LaunchServer");
Expand Down
2 changes: 0 additions & 2 deletions LaunchServer/source/auth/handler/JsonAuthHandler.java
Expand Up @@ -4,11 +4,9 @@
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import launcher.helper.IOHelper;
import launcher.helper.SecurityHelper;
import launcher.helper.VerifyHelper;
import launcher.serialize.config.entry.BlockConfigEntry;
import launcher.serialize.config.entry.StringConfigEntry;
import launchserver.auth.provider.AuthProviderResult;

import java.io.IOException;
import java.io.InputStreamReader;
Expand Down
1 change: 0 additions & 1 deletion Launcher/source/LauncherEngine.java
Expand Up @@ -69,7 +69,6 @@ public Object loadScript(URL url) throws IOException, ScriptException {
}

public static void main(String... args) throws Throwable {
SecurityHelper.verifyCertificates(Launcher.class);
JVMHelper.verifySystemProperties(Launcher.class, true);
LogHelper.printVersion("Launcher");

Expand Down
3 changes: 0 additions & 3 deletions Launcher/source/client/ClientLauncher.java
Expand Up @@ -7,7 +7,6 @@
import java.lang.invoke.MethodType;
import java.net.URL;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
Expand Down Expand Up @@ -39,7 +38,6 @@
import launcher.helper.JVMHelper.OS;
import launcher.helper.LogHelper;
import launcher.helper.SecurityHelper;
import launcher.helper.VerifyHelper;
import launcher.request.update.LauncherRequest;
import launcher.serialize.HInput;
import launcher.serialize.HOutput;
Expand Down Expand Up @@ -170,7 +168,6 @@ public static void main(String... args) throws Throwable {
// Read hdirs
assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new);
clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new);
} finally {
}

// Verify ClientLauncher sign and classpath
Expand Down
1 change: 0 additions & 1 deletion libLauncher/src/launcher/LauncherClassLoader.java
Expand Up @@ -2,7 +2,6 @@

import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;

public class LauncherClassLoader extends URLClassLoader {
/**
Expand Down
59 changes: 13 additions & 46 deletions libLauncher/src/launcher/hasher/FileNameMatcher.java
Expand Up @@ -2,28 +2,19 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Pattern;

import launcher.LauncherAPI;
import launcher.helper.IOHelper;

public final class FileNameMatcher {
private static final Entry[] NO_ENTRIES = new Entry[0];
private static final String[] NO_ENTRIES = new String[0];

// Instance
private final Entry[] update;
private final Entry[] verify;
private final Entry[] exclusions;
private final String[] update;
private final String[] verify;
private final String[] exclusions;

@LauncherAPI
public FileNameMatcher(String[] update, String[] verify, String[] exclusions) {
this.update = toEntries(update);
this.verify = toEntries(verify);
this.exclusions = toEntries(exclusions);
}

private FileNameMatcher(Entry[] update, Entry[] verify, Entry[] exclusions) {
this.update = update;
this.verify = verify;
this.exclusions = exclusions;
Expand All @@ -44,38 +35,14 @@ public FileNameMatcher verifyOnly() {
return new FileNameMatcher(NO_ENTRIES, verify, exclusions);
}

private static boolean anyMatch(Entry[] entries, Collection<String> path) {
return Arrays.stream(entries).anyMatch(e -> e.matches(path));
}

private static Entry[] toEntries(String... entries) {
return Arrays.stream(entries).map(Entry::new).toArray(Entry[]::new);
}

private static final class Entry {
private static final Pattern SPLITTER = Pattern.compile(Pattern.quote(IOHelper.CROSS_SEPARATOR) + '+');
private final Pattern[] parts;

private Entry(CharSequence exclusion) {
parts = SPLITTER.splitAsStream(exclusion).map(Pattern::compile).toArray(Pattern[]::new);
}

private boolean matches(Collection<String> path) {
if (parts.length > path.size()) {
return false;
}

// Verify path parts
Iterator<String> iterator = path.iterator();
for (Pattern patternPart : parts) {
String pathPart = iterator.next();
if (!patternPart.matcher(pathPart).matches()) {
return false;
}
}

// All matches
return true;
}
private static boolean anyMatch(String[] entries, Collection<String> path) {
return path.stream().anyMatch(e -> Arrays.stream(entries).anyMatch(p -> p.endsWith(e)));
//for(String p : path)
//{
// for(String e : entries)
// {
// if(p.endsWith(e)) return true;
// }
//}
}
}
9 changes: 0 additions & 9 deletions libLauncher/src/launcher/helper/JVMHelper.java
@@ -1,22 +1,14 @@
package launcher.helper;

import java.io.File;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.cert.CertSelector;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import com.sun.management.OperatingSystemMXBean;
Expand Down Expand Up @@ -97,7 +89,6 @@ public static boolean isJVMMatchesSystemArch() {
@LauncherAPI
public static void verifySystemProperties(Class<?> mainClass, boolean requireSystem) {
Locale.setDefault(Locale.US);

// Verify class loader
LogHelper.debug("Verifying class loader");
if (requireSystem && !mainClass.getClassLoader().equals(LOADER)) {
Expand Down
1 change: 0 additions & 1 deletion libLauncher/src/launcher/helper/SecurityHelper.java
Expand Up @@ -4,7 +4,6 @@
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
Expand Down

0 comments on commit a215c5e

Please sign in to comment.