| 24 | import java.util.List; |
| 25 | |
| 26 | public class MiscPlugin implements Plugin { |
| 27 | |
| 28 | Solver solver; |
| 29 | |
| 30 | public MiscPlugin(EnhanceHandlerContext context) { |
| 31 | solver = context.solver(); |
| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public void onNewCSMethod(CSMethod csMethod) { |
| 36 | StmtVisitor<Void> visitor = new Visitor(csMethod); |
| 37 | csMethod.getMethod().getIR().getStmts().forEach(stmt -> stmt.accept(visitor)); |
| 38 | } |
| 39 | |
| 40 | private class Visitor implements StmtVisitor<Void> { |
| 41 | private final CSMethod csMethod; |
| 42 | |
| 43 | private final Context context; |
| 44 | |
| 45 | private Visitor(CSMethod csMethod) { |
| 46 | this.csMethod = csMethod; |
| 47 | this.context = csMethod.getContext(); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Void visit(Invoke stmt) { |
| 52 | List<String> sigs = new ArrayList<>(List.of( |
| 53 | "<cn.iocoder.yudao.module.infra.framework.file.core.client.FileClient: java.lang.String upload(byte[],java.lang.String,java.lang.String)>", |
| 54 | "<top.tangyh.lamp.file.strategy.FileStrategy: top.tangyh.lamp.file.entity.File upload(org.springframework.web.multipart.MultipartFile,java.lang.String,java.lang.String)>" |
| 55 | )); |
| 56 | if (stmt.isDynamic()) { |
| 57 | return null; |
| 58 | } |
| 59 | MethodRef methodRef = stmt.getMethodRef(); |
| 60 | JMethod jMethod = methodRef.resolveNullable(); |
| 61 | if (jMethod != null && sigs.stream().anyMatch(sig -> sig.equals(jMethod.getSignature()))) { |
| 62 | Var var = InvokeUtils.getVar(stmt, InvokeUtils.BASE); |
| 63 | JClass jClass = jMethod.getDeclaringClass(); |
| 64 | HeapModel heapModel = solver.getHeapModel(); |
| 65 | CSManager csManager = solver.getCSManager(); |
| 66 | ContextSelector contextSelector = solver.getContextSelector(); |
| 67 | PointsToSet pointsToSet = solver.makePointsToSet(); |
| 68 | World.get().getClassHierarchy().getAllSubclassesOf(jClass).stream() |
| 69 | // don't exclude itself because sometimes DI is a concrete type |
| 70 | .filter(c -> !c.isAbstract()).forEach(c -> { |
| 71 | Obj obj = heapModel.getMockObj(() -> "model:%s".formatted(jMethod.getName()), "MiscPlugin", c.getType()); |
| 72 | CSObj csObj = csManager.getCSObj(contextSelector.selectHeapContext(csMethod, obj), obj); |
| 73 | pointsToSet.addObject(csObj); |
| 74 | }); |
| 75 | solver.addVarPointsTo(context, var, pointsToSet); |
| 76 | } |
| 77 | return null; |
| 78 | } |
| 79 | } |
| 80 | } |
nothing calls this directly
no outgoing calls
no test coverage detected