[TASK] Randomized Runtime

This commit is contained in:
Jeroen Ketelaar
2019-06-12 12:02:09 +02:00
committed by Dark98
parent 4cec83f0c3
commit 6cdb58b64c
@@ -1,8 +1,11 @@
package org.parabot.core.asm.redirect; package org.parabot.core.asm.redirect;
import org.parabot.api.calculations.Random;
import org.parabot.core.Core;
import org.parabot.core.asm.RedirectClassAdapter; import org.parabot.core.asm.RedirectClassAdapter;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
public class RuntimeRedirect { public class RuntimeRedirect {
@@ -11,32 +14,32 @@ public class RuntimeRedirect {
} }
public static int availableProcessors(Runtime r) { public static int availableProcessors(Runtime r) {
return 2; return Random.between(1, 4);
} }
public static long totalMemory(Runtime runtime) { public static long totalMemory(Runtime runtime) {
return (long) 1024; return (long) Random.between(1024, 4096);
} }
public static long freeMemory(Runtime runtime) { public static long freeMemory(Runtime runtime) {
return (long) 1024; return (long) Random.between(1024, 4096);
} }
public static Process exec(Runtime r, String[] s) { public static Process exec(Runtime r, String[] s) {
System.out.println("Blocked attempted command: " + s); Core.verbose("Blocked attempted command: " + Arrays.toString(s));
throw RedirectClassAdapter.createSecurityException(); throw RedirectClassAdapter.createSecurityException();
} }
public static Process exec(Runtime r, String s) { public static Process exec(Runtime r, String s) {
if (s.contains("ping")) { if (s.contains("ping")) {
System.out.println("Faked attempted command: " + s); Core.verbose("Faked attempted command: " + s);
try { try {
return r.exec("ping 8.8.8.8"); return r.exec("ping 8.8.8.8");
} catch (IOException e) { } catch (IOException e) {
throw RedirectClassAdapter.createSecurityException(); throw RedirectClassAdapter.createSecurityException();
} }
} else { } else {
System.out.println("Blocked attempted command: " + s); Core.verbose("Blocked attempted command: " + s);
throw RedirectClassAdapter.createSecurityException(); throw RedirectClassAdapter.createSecurityException();
} }
} }