optimize JANF startup performance & fix the encode of config file

Signed-off-by: pengzhile <pengzhile@gmail.com>
This commit is contained in:
pengzhile 2021-12-02 10:58:59 +08:00
parent 07d6f7f136
commit 16c01a34a3
6 changed files with 14 additions and 6 deletions

View File

@ -1,4 +1,4 @@
# ja-netfilter v1.1.3
# ja-netfilter v1.1.4
### A javaagent lib for network filter

View File

@ -6,7 +6,7 @@
<groupId>io.zhile.research</groupId>
<artifactId>ja-netfilter</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -45,6 +45,10 @@ public class Dispatcher implements ClassFileTransformer {
addTransformers(Arrays.asList(transformers));
}
public Set<String> getHookClassNames() {
return transformerMap.keySet();
}
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws IllegalClassFormatException {
do {
if (null == className) {

View File

@ -8,6 +8,7 @@ import io.zhile.research.ja.netfilter.plugin.PluginManager;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.util.Set;
public class Initializer {
public static void init(String args, Instrumentation inst, File currentDirectory) {
@ -28,9 +29,10 @@ public class Initializer {
inst.addTransformer(Dispatcher.getInstance(), true);
Set<String> classSet = Dispatcher.getInstance().getHookClassNames();
for (Class<?> c : inst.getAllLoadedClasses()) {
String name = c.getName();
if (name.startsWith("java.lang.invoke.LambdaForm$") || '[' == name.charAt(0)) {
if (!classSet.contains(name.replace('/', '.'))) {
continue;
}

View File

@ -9,7 +9,7 @@ import java.net.URL;
import java.util.jar.JarFile;
public class Launcher {
private static final String VERSION = "v1.1.3";
private static final String VERSION = "v1.1.4";
public static void main(String[] args) {
printUsage();

View File

@ -5,7 +5,9 @@ import io.zhile.research.ja.netfilter.utils.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -19,7 +21,7 @@ public class ConfigParser {
return map;
}
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
int lineNumber = 0;
String line, lastSection = null;