MCPcopy Create free account
hub / github.com/LFYSec/MScan / DubboPlugin

Class DubboPlugin

src/main/java/fdu/secsys/microservice/plugin/DubboPlugin.java:24–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import java.util.Optional;
23
24public class DubboPlugin implements Plugin {
25
26 Logger logger = LogManager.getLogger(DubboPlugin.class);
27
28 Solver solver;
29
30 List<JClass> dubboServices;
31
32 @Override
33 public void setSolver(Solver solver) {
34 this.solver = solver;
35 }
36
37 @Override
38 public void onStart() {
39 dubboServices = World.get().getClassHierarchy().applicationClasses().filter(DubboUtil::isDubboService).toList();
40 }
41
42 @Override
43 public void onNewCSMethod(CSMethod csMethod) {
44 StmtVisitor<Void> visitor = new Visitor(csMethod);
45 csMethod.getMethod().getIR().getStmts().forEach(stmt -> stmt.accept(visitor));
46 }
47
48 private class Visitor implements StmtVisitor<Void> {
49
50 private final CSMethod csMethod;
51
52 private final Context context;
53
54 private Visitor(CSMethod csMethod) {
55 this.csMethod = csMethod;
56 this.context = csMethod.getContext();
57 }
58
59 @Override
60 public Void visit(Invoke callSite) {
61 if (callSite.isInterface()) {
62 MethodRef methodRef = callSite.getMethodRef();
63 JClass declaringClass = methodRef.getDeclaringClass();
64 if (declaringClass != null && declaringClass.isInterface()) {
65 Optional<JClass> serviceClassOp = dubboServices.stream().filter(jClass -> World.get().getClassHierarchy().isSubclass(declaringClass, jClass)).findFirst();
66 if(serviceClassOp.isPresent()) {
67 JClass serviceClass = serviceClassOp.get();
68 JMethod targetMethod = serviceClass.getDeclaredMethods().stream().filter(method -> method.getSubsignature().equals(methodRef.getSubsignature())).findFirst().get();
69 if (callSite.getInvokeExp().getArgCount() > targetMethod.getParamCount()) {
70 return null;
71 }
72 CSManager csManager = solver.getCSManager();
73 CSCallSite csCallSite = csManager.getCSCallSite(context, callSite);
74 Context calleeCtx = solver.getContextSelector().getEmptyContext();
75 CSMethod csCallee = csManager.getCSMethod(calleeCtx, targetMethod);
76 solver.addCallEdge(new Edge<>(CallGraphs.getCallKind(callSite), csCallSite, csCallee));
77 }
78 }
79 }
80 return null;
81 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected