refactor: merge VM options read rule into VM options rule
This commit is contained in:
@@ -9,7 +9,7 @@ import static org.objectweb.asm.Opcodes.*;
|
|||||||
|
|
||||||
public class FileInputStreamTransformer implements MyTransformer {
|
public class FileInputStreamTransformer implements MyTransformer {
|
||||||
|
|
||||||
private static final String RULE = "com/novitechie/rules/VMOptionsReadRule";
|
private static final String RULE = "com/novitechie/rules/VMOptionsRule";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHookClassName() {
|
public String getHookClassName() {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import static org.objectweb.asm.Opcodes.*;
|
|||||||
|
|
||||||
public class FilesTransformer implements MyTransformer {
|
public class FilesTransformer implements MyTransformer {
|
||||||
|
|
||||||
private static final String RULE = "com/novitechie/rules/VMOptionsReadRule";
|
private static final String RULE = "com/novitechie/rules/VMOptionsRule";
|
||||||
private static final String PATH_DESC = "(Ljava/nio/file/Path;)Z";
|
private static final String PATH_DESC = "(Ljava/nio/file/Path;)Z";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
package com.novitechie.rules;
|
|
||||||
|
|
||||||
import com.janetfilter.core.commons.DebugInfo;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class VMOptionsReadRule {
|
|
||||||
|
|
||||||
private static final String VMOPTIONS_SUFFIX = ".vmoptions";
|
|
||||||
|
|
||||||
public static boolean shouldHide(Path path) {
|
|
||||||
return isVMOptions(path) && StackTraceRule.check();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File redirectFile(File file) {
|
|
||||||
if (isVMOptions(file) && StackTraceRule.check()) {
|
|
||||||
return hookFile(file);
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String redirectPath(String path) {
|
|
||||||
if (isVMOptions(path) && StackTraceRule.check()) {
|
|
||||||
return hookFile(new File(path)).getPath();
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] emptyBytes(Path path) {
|
|
||||||
log(path);
|
|
||||||
return new byte[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String emptyString(Path path) {
|
|
||||||
log(path);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> emptyLines(Path path) {
|
|
||||||
log(path);
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputStream emptyInputStream(Path path) {
|
|
||||||
log(path);
|
|
||||||
return new ByteArrayInputStream(new byte[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BufferedReader emptyBufferedReader(Path path) {
|
|
||||||
log(path);
|
|
||||||
return new BufferedReader(new StringReader(""));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isVMOptions(Path path) {
|
|
||||||
return path != null && isVMOptions(path.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isVMOptions(File file) {
|
|
||||||
return file != null && isVMOptions(file.getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isVMOptions(String path) {
|
|
||||||
return path != null && path.toLowerCase(Locale.ROOT).endsWith(VMOPTIONS_SUFFIX);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File hookFile(File fallback) {
|
|
||||||
Path path = VMOptionsRule.hook();
|
|
||||||
return path == null ? fallback : path.toFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void log(Path path) {
|
|
||||||
DebugInfo.output("======================Hide VMOptions read: " + path);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,25 @@ package com.novitechie.rules;
|
|||||||
|
|
||||||
import com.janetfilter.core.commons.DebugInfo;
|
import com.janetfilter.core.commons.DebugInfo;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.StringReader;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author YeloChick
|
* @author YeloChick
|
||||||
*/
|
*/
|
||||||
public class VMOptionsRule {
|
public class VMOptionsRule {
|
||||||
|
|
||||||
|
private static final String VMOPTIONS_SUFFIX = ".vmoptions";
|
||||||
|
|
||||||
public static Path hook() {
|
public static Path hook() {
|
||||||
DebugInfo.output("======================Hide VMOptions");
|
DebugInfo.output("======================Hide VMOptions");
|
||||||
String tmpdir = System.getProperty("java.io.tmpdir");
|
String tmpdir = System.getProperty("java.io.tmpdir");
|
||||||
@@ -27,4 +36,68 @@ public class VMOptionsRule {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean shouldHide(Path path) {
|
||||||
|
return isVMOptions(path) && StackTraceRule.check();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File redirectFile(File file) {
|
||||||
|
if (isVMOptions(file) && StackTraceRule.check()) {
|
||||||
|
return hookFile(file);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String redirectPath(String path) {
|
||||||
|
if (isVMOptions(path) && StackTraceRule.check()) {
|
||||||
|
return hookFile(new File(path)).getPath();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] emptyBytes(Path path) {
|
||||||
|
log(path);
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String emptyString(Path path) {
|
||||||
|
log(path);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> emptyLines(Path path) {
|
||||||
|
log(path);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream emptyInputStream(Path path) {
|
||||||
|
log(path);
|
||||||
|
return new ByteArrayInputStream(new byte[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BufferedReader emptyBufferedReader(Path path) {
|
||||||
|
log(path);
|
||||||
|
return new BufferedReader(new StringReader(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isVMOptions(Path path) {
|
||||||
|
return path != null && isVMOptions(path.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isVMOptions(File file) {
|
||||||
|
return file != null && isVMOptions(file.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isVMOptions(String path) {
|
||||||
|
return path != null && path.toLowerCase(Locale.ROOT).endsWith(VMOPTIONS_SUFFIX);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File hookFile(File fallback) {
|
||||||
|
Path path = hook();
|
||||||
|
return path == null ? fallback : path.toFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void log(Path path) {
|
||||||
|
DebugInfo.output("======================Hide VMOptions read: " + path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user