-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #593 from java-sec/feat-transform-log
feat: 策略hook增加每个类匹配策略命中的情况日志打印以便观测排查问题
- Loading branch information
Showing
1 changed file
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,11 +9,15 @@ | |
import io.dongtai.iast.core.handler.hookpoint.models.policy.PolicyNode; | ||
import io.dongtai.iast.core.utils.AsmUtils; | ||
import io.dongtai.log.DongTaiLog; | ||
import org.objectweb.asm.*; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.MethodVisitor; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.commons.JSRInlinerAdapter; | ||
|
||
import java.lang.reflect.Modifier; | ||
import java.util.*; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -29,11 +33,14 @@ public DispatchClassPlugin() { | |
public ClassVisitor dispatch(ClassVisitor classVisitor, ClassContext classContext, Policy policy) { | ||
ancestors = classContext.getAncestors(); | ||
className = classContext.getClassName(); | ||
Set<String> matchedClassNameSet = policy.getMatchedClass(classContext,className, ancestors); | ||
Set<String> matchedClassNameSet = policy.getMatchedClass(classContext, className, ancestors); | ||
|
||
// 匹配的时候增加日志方便根据类或者策略观测定位问题 | ||
if (0 == matchedClassNameSet.size()) { | ||
DongTaiLog.trace("class = {}, no matching policy, so ignored.", classContext.getClassName()); | ||
return classVisitor; | ||
} | ||
DongTaiLog.trace("class = {}, matching policy classes = {}", classContext.getClassName(), String.join(", ", matchedClassNameSet)); | ||
|
||
classContext.setMatchedClassSet(matchedClassNameSet); | ||
return new ClassVisit(classVisitor, classContext, policy); | ||
|