mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Фикс чита на основе глобальных переменных часть 2
This commit is contained in:
parent
6091be7606
commit
4e75894438
1 changed files with 11 additions and 52 deletions
|
@ -7,68 +7,27 @@
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
public class EnvHelper {
|
||||
private static final boolean TST;
|
||||
private static final boolean HASXW;
|
||||
public static final String[] toTest;
|
||||
public static final Pattern[] test;
|
||||
|
||||
static {
|
||||
toTest = new String[] { "_JAVA_OPTIONS", "_JAVA_OPTS", "JAVA_OPTS", "JAVA_OPTIONS" };
|
||||
test = new Pattern[] { Pattern.compile("-xm.*\\d+[KMG]") };
|
||||
TST = check0();
|
||||
HASXW = check1();
|
||||
}
|
||||
|
||||
public static void addEnv(ProcessBuilder builder) {
|
||||
if (hasOptsEnv()) {
|
||||
Map<String, String> repl = new HashMap<>();
|
||||
for (String str : toTest) {
|
||||
repl.put(str, "");
|
||||
repl.put(str.toLowerCase(Locale.US), "");
|
||||
}
|
||||
JVMHelper.appendVars(builder, repl);
|
||||
Map<String, String> repl = builder.environment();
|
||||
for (String str : toTest) {
|
||||
repl.put(str, "");
|
||||
repl.put(str.toLowerCase(Locale.US), "");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean check0() {
|
||||
for (String test : toTest)
|
||||
if (System.getProperty(test) != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Вынужденное решение ибо тест на наличие -Xm* этакой нужен.
|
||||
*/
|
||||
private static boolean check1() {
|
||||
if (hasOptsEnv())
|
||||
for (String testStr : toTest)
|
||||
if (System.getenv(testStr) != null) {
|
||||
String str = System.getenv(testStr).toLowerCase(Locale.US);
|
||||
StringTokenizer st = new StringTokenizer(str);
|
||||
while (st.hasMoreTokens())
|
||||
if (CommonHelper.multiMatches(test, st.nextToken()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void checkDangerousParametrs() {
|
||||
if (hasOptsEnv())
|
||||
for (String t : toTest)
|
||||
if (System.getenv(t) != null) {
|
||||
String env = System.getenv(t).toLowerCase(Locale.US);
|
||||
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|
||||
|| env.contains("-agentpath") || env.contains("-agentlib"))
|
||||
throw new SecurityException("JavaAgent in global optings not allow");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasOptsEnv() {
|
||||
return TST;
|
||||
}
|
||||
|
||||
public static boolean hasWarnPreDef() {
|
||||
return HASXW;
|
||||
for (String t : toTest)
|
||||
if (System.getenv(t) != null) {
|
||||
String env = System.getenv(t).toLowerCase(Locale.US);
|
||||
if (env.contains("-cp") || env.contains("-classpath") || env.contains("-javaagent")
|
||||
|| env.contains("-agentpath") || env.contains("-agentlib"))
|
||||
throw new SecurityException("JavaAgent in global optings not allow");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue