Skip to content

Commit

Permalink
Merge pull request #593 from java-sec/feat-transform-log
Browse files Browse the repository at this point in the history
feat: 策略hook增加每个类匹配策略命中的情况日志打印以便观测排查问题
  • Loading branch information
CC11001100 authored Sep 25, 2023
2 parents e9aec46 + 8969395 commit 15581b7
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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);
Expand Down

0 comments on commit 15581b7

Please sign in to comment.