Merge branch 'master' into v4.1.x

This commit is contained in:
zaxar163 2018-11-30 20:52:18 +03:00
commit d6049e71c0
No known key found for this signature in database
GPG key ID: E3B309DD3852DE06
12 changed files with 49 additions and 217 deletions

View file

@ -259,6 +259,7 @@ public static void main(String... args) throws Throwable {
JVMHelper.verifySystemProperties(LaunchServer.class, true);
LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log"));
LogHelper.printVersion("LaunchServer");
LogHelper.printLicense("LauncherServer");
// Start LaunchServer
Instant start = Instant.now();

View file

@ -260,7 +260,7 @@ private void stdBuild() throws IOException {
throw new IOException(String.format("Missing init script file ('%s')", Launcher.INIT_SCRIPT_FILE));
// Write launcher guard dir
IOHelper.walk(runtimeDir, new RuntimeDirVisitor(output, runtime), false);
IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false);
//IOHelper.walk(guardDir, new GuardDirVisitor(output, runtime), false);
}
// Create launcher config file
byte[] launcherConfigBytes;

View file

@ -1,104 +0,0 @@
package ru.gravit.launcher;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import cpw.mods.fml.SafeExitJVMLegacy;
import net.minecraftforge.fml.SafeExitJVM;
import ru.gravit.launcher.hasher.DirWatcher;
import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.utils.NativeJVMHalt;
import ru.gravit.utils.helper.*;
import ru.zaxar163.GuardBind;
public class AvanguardStarter {
static class SecurityThread implements Runnable {
static long macID = GuardBind.avnGetMacId();
@Override
public void run() {
while (!Thread.interrupted()) {
try {
if (macID != GuardBind.avnGetMacId()) {
LogHelper.error("MacID changed");
safeHalt(8);
}
if (!GuardBind.avnIsStarted()) {
LogHelper.error("Avanguard stopped! Process stopped");
safeHalt(5);
}
} catch (NullPointerException e) {
LogHelper.error("Avanguard unloaded! Process stopped");
safeHalt(6);
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
GuardBind.avnGetMacId();
if (!GuardBind.avnIsStarted()) {
LogHelper.error("Thread stopped! Process stopped");
safeHalt(7);
}
}
}
}
}
static void safeHalt(int exitcode) {
try {
SafeExitJVMLegacy.exit(exitcode);
} catch (Throwable ignored) {
}
try {
SafeExitJVM.exit(exitcode);
} catch (Throwable ignored) {
}
NativeJVMHalt halt = new NativeJVMHalt(exitcode);
halt.halt();
}
public static final String NAME = Launcher.getConfig().projectname;
public static Path wrapper = null, avanguard = null;
public static void main(boolean init) {
if (init)
GuardBind.init();
GuardBind.avnRegisterThreatNotifier((int threatType) -> {
System.err.println("Threat " + GuardBind.ThreatType.getThreat(threatType).name());
LogHelper.error("Cheating == crash!");
try {
SafeExitJVM.exit(threatType + 7000);
} catch (Throwable e) {
SafeExitJVMLegacy.exit(threatType + 7000);
}
return false;
});
// нужно делать до пуска таймера!
GuardBind.avnStartDefence();
CommonHelper.newThread("Security Thread", true, new SecurityThread()).start();
}
public static void load() {
GuardBind.startAbs(avanguard.toString());
}
public static void start(Path path1) throws IOException {
Path path = path1.resolve("guard");
if (!IOHelper.exists(path))
Files.createDirectories(path);
Path avanguard = path.resolve(JVMHelper.JVM_BITS == 64 ? "Avanguard64.dll" : "Avanguard32.dll");
Path wrapper = path.resolve(JVMHelper.JVM_BITS == 64 ? NAME + "64.exe" : NAME + "32.exe");
String avanguardResource = JVMHelper.JVM_BITS == 64 ? "Avanguard64.dll" : "Avanguard32.dll";
String wrapperResource = JVMHelper.JVM_BITS == 64 ? "wrapper64.exe" : "wrapper32.exe";
UnpackHelper.unpack(Launcher.getResourceURL(avanguardResource, "guard"), avanguard);
UnpackHelper.unpack(Launcher.getResourceURL(wrapperResource, "guard"), wrapper);
AvanguardStarter.wrapper = wrapper;
AvanguardStarter.avanguard = avanguard;
HashedDir guard = new HashedDir(path, null, true, false);
DirWatcher dirWatcher = new DirWatcher(path, guard, null, false);
CommonHelper.newThread("Guard Directory Watcher", true, dirWatcher).start();
}
}

View file

@ -16,6 +16,9 @@
public class ClientLauncherWrapper {
public static void main(String[] arguments) throws IOException, InterruptedException {
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
LogHelper.info("Restart Launcher witch JavaAgent...");
LogHelper.info("If need debug output use -Dlauncher.debug=true");
JVMHelper.checkStackTrace(ClientLauncherWrapper.class);
JVMHelper.verifySystemProperties(Launcher.class, true);
EnvHelper.checkDangerousParams();
@ -38,7 +41,11 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep
if (!LogHelper.isDebugEnabled()) {
Thread.sleep(3000);
if (!process.isAlive()) {
LogHelper.error("Process error code: %d", process.exitValue());
int errorcode = process.exitValue();
if(errorcode != 0)
LogHelper.error("Process exit witch error code: %d", errorcode);
else
LogHelper.info("Process exit witch code 0");
} else {
LogHelper.debug("Process started success");
}

View file

@ -163,6 +163,7 @@ public static void main(String... args) throws Throwable {
EnvHelper.checkDangerousParams();
//if(!LauncherAgent.isStarted()) throw new SecurityException("JavaAgent not set");
LogHelper.printVersion("Launcher");
LogHelper.printLicense("Launcher");
// Start Launcher
Instant start = Instant.now();
try {

View file

@ -332,8 +332,8 @@ public static Process launch(
List<String> args = new LinkedList<>();
boolean wrapper = isUsingWrapper();
Path javaBin;
if (wrapper) javaBin = AvanguardStarter.wrapper;
else if (isDownloadJava) {
/*if (wrapper) javaBin = AvanguardStarter.wrapper;
else*/ if (isDownloadJava) {
//Linux и Mac не должны скачивать свою JVM
if (JVMHelper.OS_TYPE == OS.MUSTDIE)
javaBin = IOHelper.resolveJavaBin(JavaBinPath);
@ -403,11 +403,6 @@ public static void main(String... args) throws Throwable {
engine.loadScript(Launcher.API_SCRIPT_FILE);
engine.loadScript(Launcher.CONFIG_SCRIPT_FILE);
Launcher.modulesManager.preInitModules();
if (Launcher.isUsingAvanguard()) {
AvanguardStarter.start(DirBridge.dir);
AvanguardStarter.load();
AvanguardStarter.main(false);
}
checkJVMBitsAndVersion();
JVMHelper.verifySystemProperties(ClientLauncher.class, true);
EnvHelper.checkDangerousParams();

View file

@ -15,7 +15,6 @@
import ru.gravit.launcher.serialize.HInput;
import ru.gravit.launcher.serialize.HOutput;
import ru.gravit.launcher.serialize.SerializeLimits;
import ru.zaxar163.GuardBind;
public final class AuthRequest extends Request<Result> {
public static final class Result {
@ -77,6 +76,9 @@ protected Result requestDo(HInput input, HOutput output) throws IOException {
output.writeString(Launcher.profile.getTitle(), SerializeLimits.MAX_CLIENT);
output.writeInt(auth_id);
output.writeString(hwid.getHWID().getSerializeString(),0);
//output.writeLong(0);
//output.writeLong(0);
//output.writeLong(0);
output.writeByteArray(encryptedPassword, SecurityHelper.CRYPTO_MAX_LENGTH);
output.flush();

View file

@ -1,95 +0,0 @@
package ru.zaxar163;
import java.nio.file.Path;
import ru.gravit.launcher.LauncherAPI;
import ru.gravit.utils.helper.JVMHelper;
import ru.gravit.utils.helper.LogHelper;
@LauncherAPI
public final class GuardBind {
public interface ThreatNotifier {
boolean call(int threatType);
}
public enum ThreatType {
UNKNOWN_THREAT(0),
REMOTE_THREAD(1),
WINDOWS_HOOKS_INJECTION(2),
UNKNOWN_TRACE_LOAD_LIBRARY(3),
CONTEXT_MANIPULATION(4),
CRITICAL_MODULE_CHANGED(5),
UNKNOWN_INTERCEPTION(6),
UNKNOWN_MEMORY_REGION(7),
UNKNOWN_APC_DESTINATION(8);
public static ThreatType getThreat(int threatType) {
return ThreatType.values()[threatType];
}
private final int id;
ThreatType(int value) {
id = value;
}
public int getValue() {
return id;
}
}
@LauncherAPI
public static native void avnEliminateThreat(int threatType);
@LauncherAPI
public static native long avnGetCpuid();
@LauncherAPI
public static native long avnGetHash(byte[] data);
@LauncherAPI
public static native long avnGetHddId();
@LauncherAPI
public static native long avnGetMacId();
@LauncherAPI
public static native long avnGetSmbiosId();
@LauncherAPI
public static native boolean avnIsStarted();
@LauncherAPI
public static native boolean avnIsStaticLoaded();
@LauncherAPI
public static native void avnRegisterThreatNotifier(ThreatNotifier notifier);
@LauncherAPI
public static native boolean avnStartDefence();
@LauncherAPI
public static native void avnStopDefence();
public static void init() {
LogHelper.debug("Anti-Cheat loading");
if (JVMHelper.OS_TYPE == JVMHelper.OS.MUSTDIE)
if (JVMHelper.JVM_BITS == 32)
System.loadLibrary("Avanguard32");
else if (JVMHelper.JVM_BITS == 64)
System.loadLibrary("Avanguard64");
LogHelper.debug("Anti-Cheat loaded");
}
public static void start(Path path) {
LogHelper.debug("Anti-Cheat loading");
System.load(path.normalize().toAbsolutePath().toFile().getAbsolutePath());
LogHelper.debug("Anti-Cheat loaded");
}
public static void startAbs(String path) {
LogHelper.debug("Anti-Cheat loading");
System.load(path);
LogHelper.debug("Anti-Cheat loaded");
}
}

View file

@ -76,6 +76,8 @@ public static boolean loopAuth(ServerWrapper wrapper, int count, int sleeptime)
public static void main(String[] args) throws Throwable {
ServerWrapper wrapper = new ServerWrapper();
LogHelper.printVersion("ServerWrapper");
LogHelper.printLicense("ServerWrapper");
modulesManager = new ModulesManager(wrapper);
modulesManager.autoload(Paths.get("srv_modules")); //BungeeCord using modules dir
Launcher.modulesManager = modulesManager;
@ -92,6 +94,10 @@ public static void main(String[] args) throws Throwable {
CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep));
modulesManager.initModules();
String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass;
if(classname.length() == 0)
{
LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.cfg or first commandline argument");
}
Class<?> mainClass;
if (config.customClassLoader) {
@SuppressWarnings("unchecked")
@ -104,7 +110,9 @@ public static void main(String[] args) throws Throwable {
String[] real_args = new String[args.length - 1];
System.arraycopy(args, 1, real_args, 0, args.length - 1);
modulesManager.postInitModules();
LogHelper.debug("Invoke main method");
LogHelper.info("ServerWrapper: Project %s, LaunchServer address: %s port %d. Title: %s",config.projectname,config.address,config.port,config.title);
LogHelper.info("Minecraft Version (for profile): %s",wrapper.profile.getVersion().name);
LogHelper.debug("Invoke main method %s", mainClass.getName());
mainMethod.invoke(real_args);
}

View file

@ -57,10 +57,10 @@ public final class Launcher {
private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL);
public static int MAJOR = 4;
public static int MINOR = 0;
public static int PATCH = 8;
public static int MINOR = 1;
public static int PATCH = 0;
public static int BUILD = 0;
public static Version.Type RELEASE = Version.Type.STABLE;
public static Version.Type RELEASE = Version.Type.DEV;
@LauncherAPI
public static LauncherConfig getConfig() {

View file

@ -278,8 +278,8 @@ public boolean isUpdateFastCheck() {
@LauncherAPI
public boolean isWhitelistContains(String username) {
if (!useWhitelist) return true;
return whitelist.stream().anyMatch(e -> e.equals(username));
if (!useWhitelist.getValue()) return true;
return whitelist.stream().anyMatch(e -> e.equalsIgnoreCase(username)); // TODO case sensitive on/off
}
@LauncherAPI

View file

@ -117,6 +117,10 @@ public static void log(Level level, String message, boolean sub) {
public static void printVersion(String product) {
println(JANSI ? ansiFormatVersion(product) : formatVersion(product));
}
@LauncherAPI
public static void printLicense(String product) {
println(JANSI ? ansiFormatLicense(product) : formatLicense(product));
}
@LauncherAPI
public static synchronized void println(String message) {
@ -234,13 +238,23 @@ private static String ansiFormatLog(Level level, String dateTime, String message
private static String ansiFormatVersion(String product) {
return new Ansi().bold(). // Setup
fgBright(Color.MAGENTA).a("sashok724's "). // sashok724's
fgBright(Color.MAGENTA).a("GravitLauncher "). // sashok724's
fgBright(Color.BLUE).a("(fork sashok724's Launcher) ").
fgBright(Color.CYAN).a(product). // Product
fgBright(Color.WHITE).a(" v").fgBright(Color.BLUE).a(Launcher.getVersion().toString()). // Version
fgBright(Color.WHITE).a(" (build #").fgBright(Color.RED).a(Launcher.getVersion().build).fgBright(Color.WHITE).a(')'). // Build#
reset().toString(); // To string
}
private static String ansiFormatLicense(String product) {
return new Ansi().bold(). // Setup
fgBright(Color.MAGENTA).a("License for "). // sashok724's
fgBright(Color.CYAN).a(product). // Product
fgBright(Color.WHITE).a(" GPLv3").fgBright(Color.WHITE).a(". SourceCode: "). // Version
fgBright(Color.YELLOW).a("https://github.com/GravitLauncher/Launcher").
reset().toString(); // To string
}
private static String formatLog(Level level, String message, String dateTime, boolean sub) {
if (sub) {
message = ' ' + message;
@ -249,7 +263,10 @@ private static String formatLog(Level level, String message, String dateTime, bo
}
private static String formatVersion(String product) {
return String.format("sashok724's %s v%s", product, Launcher.getVersion().toString());
return String.format("GravitLauncher (fork sashok724's Launcher) %s v%s", product, Launcher.getVersion().toString());
}
private static String formatLicense(String product) {
return String.format("License for %s GPLv3. SourceCode: https://github.com/GravitLauncher/Launcher", product);
}
static {