feat: support plugin update zip scan and .vmoptions read interception
This commit is contained in:
@@ -11,56 +11,54 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class CanaryAutoScanner {
|
||||
private static final List<FilterRule> DEFAULT_SCAN_PLUGINS = Collections.unmodifiableList(Arrays.asList(new FilterRule(RuleType.EQUAL, "izhangzhihao.rainbow.brackets")));
|
||||
private static final List<FilterRule> DEFAULT_SCAN_PACKAGES = Collections.unmodifiableList(Arrays.asList(new FilterRule(RuleType.PREFIX, "com.janetfilter."), new FilterRule(RuleType.PREFIX, "com.novitechie.")));
|
||||
public class CanaryAutoScanner {
|
||||
|
||||
private static final List<FilterRule> DEFAULT_SCAN_PLUGINS = Arrays.asList(
|
||||
new FilterRule(RuleType.EQUAL, "izhangzhihao.rainbow.brackets"));
|
||||
private static final List<FilterRule> DEFAULT_SCAN_PACKAGES = Arrays.asList(
|
||||
new FilterRule(RuleType.PREFIX, "com.janetfilter."),
|
||||
new FilterRule(RuleType.PREFIX, "com.novitechie."));
|
||||
|
||||
private CanaryAutoScanner() {
|
||||
}
|
||||
|
||||
public static final class AutoScanResult {
|
||||
private final List<FilterRule> classRules;
|
||||
private final boolean markerResourceExists;
|
||||
|
||||
private AutoScanResult(List<FilterRule> classRules, boolean markerResourceExists) {
|
||||
this.classRules = classRules == null ? Collections.emptyList() : classRules;
|
||||
this.markerResourceExists = markerResourceExists;
|
||||
}
|
||||
|
||||
public static AutoScanResult empty() {
|
||||
return new AutoScanResult(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
public List<FilterRule> getClassRules() {
|
||||
return new ArrayList(this.classRules);
|
||||
}
|
||||
|
||||
public boolean isMarkerResourceExists() {
|
||||
return this.markerResourceExists;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<FilterRule> scan(PluginConfig config) {
|
||||
return scanWithResult(config).getClassRules();
|
||||
}
|
||||
|
||||
public static AutoScanResult scanWithResult(PluginConfig config) {
|
||||
try {
|
||||
return doScan(config);
|
||||
} catch (Exception e) {
|
||||
DebugInfo.warn("[PRIVACY-SCAN] Auto scan failed; continue without generated rules", e);
|
||||
return AutoScanResult.empty();
|
||||
} catch (LinkageError e) {
|
||||
DebugInfo.warn("[PRIVACY-SCAN] Auto scan unavailable; continue without generated rules", e);
|
||||
return AutoScanResult.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static AutoScanResult doScan(PluginConfig config) {
|
||||
List<FilterRule> pluginRules = rules(config, "Auto_Scan_Plugin", DEFAULT_SCAN_PLUGINS);
|
||||
List<FilterRule> packageRules = rules(config, "Auto_Scan_Package", DEFAULT_SCAN_PACKAGES);
|
||||
List<FilterRule> excludeRules = emptyIfNull(config.getBySection("Auto_Scan_Exclude"));
|
||||
|
||||
if (pluginRules.isEmpty() || packageRules.isEmpty()) {
|
||||
DebugInfo.warn("[PRIVACY-SCAN] Auto scan disabled: plugin or package rules are empty");
|
||||
return AutoScanResult.empty();
|
||||
}
|
||||
|
||||
List<File> scanTargets = JbDirectoryScanner.getPluginDir(config);
|
||||
if (scanTargets.isEmpty()) {
|
||||
DebugInfo.warn("[PRIVACY-SCAN] No plugin scan targets found");
|
||||
return AutoScanResult.empty();
|
||||
}
|
||||
|
||||
DebugInfo.output("[PRIVACY-SCAN] Plugin targets: " + fileSummary(scanTargets));
|
||||
DebugInfo.output("[PRIVACY-SCAN] Scan_Plugin: " + ruleSummary(pluginRules));
|
||||
DebugInfo.output("[PRIVACY-SCAN] Scan_Package: " + ruleSummary(packageRules));
|
||||
DebugInfo.output("[PRIVACY-SCAN] Exclude_Package: " + ruleSummary(excludeRules));
|
||||
|
||||
CanaryScanner.ScanResult result = CanaryScanner.scan(scanTargets, pluginRules, packageRules, excludeRules);
|
||||
List<String> classNames = result.getClassNames();
|
||||
List<FilterRule> classRules = new ArrayList<>(classNames.size());
|
||||
@@ -116,4 +114,26 @@ public final class CanaryAutoScanner {
|
||||
}
|
||||
return summary.toString();
|
||||
}
|
||||
|
||||
public static class AutoScanResult {
|
||||
private final List<FilterRule> classRules;
|
||||
private final boolean markerResourceExists;
|
||||
|
||||
private AutoScanResult(List<FilterRule> classRules, boolean markerResourceExists) {
|
||||
this.classRules = classRules == null ? Collections.emptyList() : classRules;
|
||||
this.markerResourceExists = markerResourceExists;
|
||||
}
|
||||
|
||||
public static AutoScanResult empty() {
|
||||
return new AutoScanResult(Collections.emptyList(), false);
|
||||
}
|
||||
|
||||
public List<FilterRule> getClassRules() {
|
||||
return new ArrayList<>(classRules);
|
||||
}
|
||||
|
||||
public boolean isMarkerResourceExists() {
|
||||
return markerResourceExists;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user