plugin-privacy/src/main/java/com/novitechie/StackTraceRule.java
2024-04-15 19:11:24 +08:00

33 lines
1.1 KiB
Java

package com.novitechie;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;
public class StackTraceRule {
private static final Pattern PACKAGE_NAME_PATTERN = Pattern.compile("\\A\\p{ASCII}*\\z");
public static boolean check() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
return true;
}
}
return false;
}
public static Date hook() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 180);
return calendar.getTime();
}
}
return null;
}
}