From 7057cd339423839b08e42bbaa72ba4c8fc7bcf7d Mon Sep 17 00:00:00 2001 From: pengzhile Date: Fri, 3 Dec 2021 18:04:26 +0800 Subject: [PATCH] config: add ignorecase rule types Signed-off-by: pengzhile --- README.md | 20 +++++++++++-------- pom.xml | 3 ++- .../zhile/research/ja/netfilter/Launcher.java | 2 +- .../ja/netfilter/commons/ConfigParser.java | 6 +----- .../research/ja/netfilter/enums/RuleType.java | 8 ++++++-- .../ja/netfilter/rulers/EqualICRuler.java | 8 ++++++++ .../ja/netfilter/rulers/KeywordICRuler.java | 8 ++++++++ .../ja/netfilter/rulers/PrefixICRuler.java | 8 ++++++++ .../ja/netfilter/rulers/SuffixICRuler.java | 8 ++++++++ 9 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 src/main/java/io/zhile/research/ja/netfilter/rulers/EqualICRuler.java create mode 100644 src/main/java/io/zhile/research/ja/netfilter/rulers/KeywordICRuler.java create mode 100644 src/main/java/io/zhile/research/ja/netfilter/rulers/PrefixICRuler.java create mode 100644 src/main/java/io/zhile/research/ja/netfilter/rulers/SuffixICRuler.java diff --git a/README.md b/README.md index 490d755..9b1346e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# ja-netfilter v1.1.5 +# ja-netfilter v1.1.6 ### A javaagent lib for network filter ## Usage -* download from the [releases page](https://github.com/pengzhile/ja-netfilter/releases) +* download from the [releases page](https://github.com/ja-netfilter/ja-netfilter/releases) * add `-javaagent:/absolute/path/to/ja-netfilter.jar` argument (**Change to your actual path**) * add as an argument of the `java` command. eg: `java -javaagent:/absolute/path/to/ja-netfilter.jar -jar executable_jar_file.jar` * some apps support the `JVM Options file`, you can add as a line of the `JVM Options file`. @@ -36,11 +36,15 @@ EQUAL,https://someurl [DNS] EQUAL,somedomain -# EQUAL Use `equals` to compare -# KEYWORD Use `contains` to compare -# PREFIX Use `startsWith` to compare -# SUFFIX Use `endsWith` to compare -# REGEXP Use regular expressions to match +# EQUAL Use `equals` to compare +# EQUAL_IC Use `equals` to compare, ignore case +# KEYWORD Use `contains` to compare +# KEYWORD_IC Use `contains` to compare, ignore case +# PREFIX Use `startsWith` to compare +# PREFIX_IC Use `startsWith` to compare, ignore case +# SUFFIX Use `endsWith` to compare +# SUFFIX_IC Use `endsWith` to compare, ignore case +# REGEXP Use regular expressions to match ``` ## Debug info @@ -52,7 +56,7 @@ EQUAL,somedomain ## Plugin system * for developer: - * view the [scaffold project](https://github.com/pengzhile/ja-netfilter-sample-plugin) written for the plugin system + * view the [scaffold project](https://github.com/ja-netfilter/ja-netfilter-sample-plugin) written for the plugin system * compile your plugin and publish it * just use your imagination~ diff --git a/pom.xml b/pom.xml index 4c0279a..2f76aa0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.zhile.research ja-netfilter - 1.1.5 + 1.1.6 UTF-8 @@ -47,6 +47,7 @@ true + neo io.zhile.research.ja.netfilter.Launcher io.zhile.research.ja.netfilter.Launcher true diff --git a/src/main/java/io/zhile/research/ja/netfilter/Launcher.java b/src/main/java/io/zhile/research/ja/netfilter/Launcher.java index f5d69de..f2f1edd 100644 --- a/src/main/java/io/zhile/research/ja/netfilter/Launcher.java +++ b/src/main/java/io/zhile/research/ja/netfilter/Launcher.java @@ -9,7 +9,7 @@ import java.net.URL; import java.util.jar.JarFile; public class Launcher { - private static final String VERSION = "v1.1.5"; + private static final String VERSION = "v1.1.6"; public static void main(String[] args) { printUsage(); diff --git a/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java b/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java index fdc6ff3..13a1b32 100644 --- a/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java +++ b/src/main/java/io/zhile/research/ja/netfilter/commons/ConfigParser.java @@ -44,11 +44,7 @@ public class ConfigParser { throw new Exception("Empty section name! Line: " + lineNumber); } - lastSection = section; - if (null == map.get(lastSection)) { - // do NOT override existing sections - map.put(lastSection, new ArrayList<>()); - } + map.computeIfAbsent(lastSection = section, k -> new ArrayList<>()); break; case '#': case ';': diff --git a/src/main/java/io/zhile/research/ja/netfilter/enums/RuleType.java b/src/main/java/io/zhile/research/ja/netfilter/enums/RuleType.java index 4e9d325..a46b54b 100644 --- a/src/main/java/io/zhile/research/ja/netfilter/enums/RuleType.java +++ b/src/main/java/io/zhile/research/ja/netfilter/enums/RuleType.java @@ -4,10 +4,14 @@ import io.zhile.research.ja.netfilter.rulers.*; public enum RuleType { PREFIX(new PrefixRuler()), + PREFIX_IC(new PrefixICRuler()), SUFFIX(new SuffixRuler()), + SUFFIX_IC(new SuffixICRuler()), KEYWORD(new KeywordRuler()), - REGEXP(new RegExpRuler()), - EQUAL(new EqualRuler()); + KEYWORD_IC(new KeywordICRuler()), + EQUAL(new EqualRuler()), + EQUAL_IC(new EqualICRuler()), + REGEXP(new RegExpRuler()); private final Ruler ruler; diff --git a/src/main/java/io/zhile/research/ja/netfilter/rulers/EqualICRuler.java b/src/main/java/io/zhile/research/ja/netfilter/rulers/EqualICRuler.java new file mode 100644 index 0000000..ef12785 --- /dev/null +++ b/src/main/java/io/zhile/research/ja/netfilter/rulers/EqualICRuler.java @@ -0,0 +1,8 @@ +package io.zhile.research.ja.netfilter.rulers; + +public class EqualICRuler implements Ruler { + @Override + public boolean test(String rule, String content) { + return content.equalsIgnoreCase(rule); + } +} diff --git a/src/main/java/io/zhile/research/ja/netfilter/rulers/KeywordICRuler.java b/src/main/java/io/zhile/research/ja/netfilter/rulers/KeywordICRuler.java new file mode 100644 index 0000000..1529b4c --- /dev/null +++ b/src/main/java/io/zhile/research/ja/netfilter/rulers/KeywordICRuler.java @@ -0,0 +1,8 @@ +package io.zhile.research.ja.netfilter.rulers; + +public class KeywordICRuler implements Ruler { + @Override + public boolean test(String rule, String content) { + return content.toLowerCase().contains(rule.toLowerCase()); + } +} diff --git a/src/main/java/io/zhile/research/ja/netfilter/rulers/PrefixICRuler.java b/src/main/java/io/zhile/research/ja/netfilter/rulers/PrefixICRuler.java new file mode 100644 index 0000000..fb28235 --- /dev/null +++ b/src/main/java/io/zhile/research/ja/netfilter/rulers/PrefixICRuler.java @@ -0,0 +1,8 @@ +package io.zhile.research.ja.netfilter.rulers; + +public class PrefixICRuler implements Ruler { + @Override + public boolean test(String rule, String content) { + return content.toLowerCase().startsWith(rule.toLowerCase()); + } +} diff --git a/src/main/java/io/zhile/research/ja/netfilter/rulers/SuffixICRuler.java b/src/main/java/io/zhile/research/ja/netfilter/rulers/SuffixICRuler.java new file mode 100644 index 0000000..ce3deb0 --- /dev/null +++ b/src/main/java/io/zhile/research/ja/netfilter/rulers/SuffixICRuler.java @@ -0,0 +1,8 @@ +package io.zhile.research.ja.netfilter.rulers; + +public class SuffixICRuler implements Ruler { + @Override + public boolean test(String rule, String content) { + return content.toLowerCase().endsWith(rule.toLowerCase()); + } +}