mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
UnpackHelper
This commit is contained in:
parent
a944282469
commit
e286c951df
4 changed files with 41 additions and 63 deletions
|
@ -10,11 +10,7 @@
|
|||
import ru.gravit.launcher.hasher.DirWatcher;
|
||||
import ru.gravit.launcher.hasher.HashedDir;
|
||||
import ru.gravit.utils.NativeJVMHalt;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.JVMHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
import ru.gravit.utils.helper.SecurityHelper;
|
||||
import ru.gravit.utils.helper.*;
|
||||
import ru.gravit.utils.helper.SecurityHelper.DigestAlgorithm;
|
||||
import ru.zaxar163.GuardBind;
|
||||
|
||||
|
@ -68,33 +64,7 @@ static void safeHalt(int exitcode)
|
|||
}
|
||||
|
||||
public static final String NAME = Launcher.getConfig().projectname;
|
||||
public static String avn32 = null, avn64 = null;
|
||||
public static Path wrap32 = null, wrap64 = null;
|
||||
|
||||
private static Path handle(Path mustdiedll, String resource) {
|
||||
try {
|
||||
InputStream in = IOHelper.newInput(IOHelper.getResourceURL(resource));
|
||||
byte[] orig = IOHelper.toByteArray(in);
|
||||
in.close();
|
||||
if (IOHelper.exists(mustdiedll)) {
|
||||
if (!matches(mustdiedll, orig))
|
||||
transfer(orig, mustdiedll);
|
||||
} else
|
||||
transfer(orig, mustdiedll);
|
||||
} catch (Exception e) {
|
||||
if (e instanceof RuntimeException)
|
||||
throw (RuntimeException) e;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return mustdiedll;
|
||||
}
|
||||
|
||||
public static void loadVared() {
|
||||
if (JVMHelper.JVM_BITS == 32)
|
||||
GuardBind.startAbs(System.getProperty("avn32"));
|
||||
else if (JVMHelper.JVM_BITS == 64)
|
||||
GuardBind.startAbs(System.getProperty("avn64"));
|
||||
}
|
||||
public static Path wrapper = null, avanguard = null;
|
||||
|
||||
public static void main(boolean init) {
|
||||
if (init)
|
||||
|
@ -114,40 +84,21 @@ public static void main(boolean init) {
|
|||
GuardBind.avnStartDefence();
|
||||
CommonHelper.newThread("Security Thread", true, new SecurityThread()).start();
|
||||
}
|
||||
|
||||
private static boolean matches(Path mustdiedll, byte[] in) {
|
||||
try {
|
||||
return Arrays.equals(SecurityHelper.digest(DigestAlgorithm.MD5, in),
|
||||
SecurityHelper.digest(DigestAlgorithm.MD5, mustdiedll));
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void processArched(Path arch32, Path arch64, Path wrapper32, Path wrapper64) {
|
||||
System.setProperty("avn32", IOHelper.toAbs(arch32));
|
||||
System.setProperty("avn64", IOHelper.toAbs(arch64));
|
||||
avn32 = IOHelper.toAbs(arch32);
|
||||
avn64 = IOHelper.toAbs(arch64);
|
||||
wrap32 = IOHelper.toAbsPath(wrapper32);
|
||||
wrap64 = IOHelper.toAbsPath(wrapper64);
|
||||
public static void load()
|
||||
{
|
||||
GuardBind.startAbs(avanguard.toString());
|
||||
}
|
||||
|
||||
public static void start(Path path1) throws IOException {
|
||||
Path path = path1.resolve("guard");
|
||||
processArched(handle(path.resolve("Avanguard32.dll"), "Avanguard32.dll"),
|
||||
handle(path.resolve("Avanguard64.dll"), "Avanguard64.dll"),
|
||||
handle(path.resolve(NAME + "32.exe"), "wrapper32.exe"),
|
||||
handle(path.resolve(NAME + "64.exe"), "wrapper64.exe"));
|
||||
Path avanguard = path.resolve(JVMHelper.OS_BITS == 64 ? "Avanguard64.dll" : "Avanguard32.dll");
|
||||
Path wrapper = path.resolve(JVMHelper.OS_BITS == 64 ? NAME + "64.exe" : NAME + "32.exe");
|
||||
UnpackHelper.unpack(JVMHelper.OS_BITS == 64 ? "Avanguard64.dll" : "Avanguard32.dll",avanguard);
|
||||
UnpackHelper.unpack(JVMHelper.OS_BITS == 64 ? "wrapper64.dll" : "wrapper32.dll",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();
|
||||
}
|
||||
|
||||
private static void transfer(byte[] orig, Path mustdiedll) throws IOException {
|
||||
IOHelper.createParentDirs(mustdiedll);
|
||||
if (!IOHelper.exists(mustdiedll))
|
||||
mustdiedll.toFile().createNewFile();
|
||||
IOHelper.transfer(orig, mustdiedll, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ public void start(String... args) throws Throwable {
|
|||
Invocable invoker = (Invocable) engine;
|
||||
if (Launcher.isUsingAvanguard()) {
|
||||
AvanguardStarter.start(DirBridge.dir);
|
||||
AvanguardStarter.loadVared();
|
||||
AvanguardStarter.load();
|
||||
AvanguardStarter.main(false);
|
||||
}
|
||||
Launcher.modulesManager.postInitModules();
|
||||
|
|
|
@ -339,7 +339,7 @@ public static Process launch(
|
|||
List<String> args = new LinkedList<>();
|
||||
boolean wrapper = isUsingWrapper();
|
||||
Path javaBin;
|
||||
if (wrapper) javaBin = JVMHelper.JVM_BITS == 64 ? AvanguardStarter.wrap64 : AvanguardStarter.wrap32;
|
||||
if (wrapper) javaBin = AvanguardStarter.wrapper;
|
||||
else if(isDownloadJava)
|
||||
{
|
||||
//Linux и Mac не должны скачивать свою JVM
|
||||
|
@ -406,7 +406,6 @@ public static void main(String... args) throws Throwable {
|
|||
LauncherConfig.getAutogenConfig().initModules(); //INIT
|
||||
Launcher.modulesManager.preInitModules();
|
||||
if (Launcher.isUsingAvanguard()) {
|
||||
AvanguardStarter.loadVared();
|
||||
AvanguardStarter.main(false);
|
||||
}
|
||||
checkJVMBitsAndVersion();
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package ru.gravit.utils.helper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class UnpackHelper {
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static boolean unpack(String resource, Path target) throws IOException {
|
||||
byte[] orig = IOHelper.read(IOHelper.getResourceURL(resource));
|
||||
if(IOHelper.exists(target))
|
||||
{
|
||||
if(matches(target,orig)) return false;
|
||||
}
|
||||
if (!IOHelper.exists(target))
|
||||
target.toFile().createNewFile();
|
||||
IOHelper.transfer(orig,target,false);
|
||||
return true;
|
||||
}
|
||||
private static boolean matches(Path target, byte[] in) {
|
||||
try {
|
||||
return Arrays.equals(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, in),
|
||||
SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, target));
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue