Skip to content

Commit

Permalink
SimpleClassMatcher support read classname from bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Nov 24, 2020
1 parent 641360a commit 6c8bb25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.HashSet;
import java.util.Set;

import com.alibaba.bytekit.utils.AsmUtils;

/**
*
* @author hengyunabc 2020-11-12
Expand All @@ -28,7 +30,7 @@ public SimpleClassMatcher(Collection<String> names) {
public boolean match(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) {
if (className == null) {
return false;
className = AsmUtils.className(classfileBuffer);
}
className = className.replace('/', '.');
if (classNames != null && classNames.contains(className)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,8 @@ public static int setMajorVersion(int version, int majorVersion) {
return (version & 0xFFFF0000) | majorVersion;
}

public static String className(byte[] classBytes) {
return new ClassReader(classBytes).getClassName();
}

}

0 comments on commit 6c8bb25

Please sign in to comment.