@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodReference ref = method.getReference(); Set<MethodReference> callbackMethods = repository.callbackMethods.get(ref); if (callbackMethods != null) { for (MethodReference callbackMethod : callbackMethods) { agent.linkMethod(callbackMethod).addLocation(new CallLocation(ref)).use(); } } }
private void reachGetLength(DependencyAgent agent, MethodDependency method) { method.getVariable(1).addConsumer(type -> { if (!type.getName().startsWith("[")) { MethodReference cons = new MethodReference(IllegalArgumentException.class, "<init>", void.class); agent.linkMethod(cons).use(); } }); }
void initClass(ClassDependency cls, CallLocation location) { ClassReader reader = cls.getClassReader(); MethodReader method = reader.getMethod(CLINIT_METHOD); if (method != null) { deferredTasks.add(() -> { MethodDependency initMethod = linkMethod(method.getReference()); if (location != null) { initMethod.addLocation(location); } initMethod.use(); }); } }
@Override public void cloneArray(VariableReader receiver, VariableReader array) { DependencyNode arrayNode = getNode(array); MethodDependency cloneDep = getAnalyzer().linkMethod(CLONE_METHOD); cloneDep.addLocation(impreciseLocation); cloneDep.use(); }
private void reachSet(DependencyAgent agent, MethodDependency method) { method.getVariable(3).connect(method.getVariable(1).getArrayItem()); method.getVariable(1).addConsumer(type -> { if (type.getName().startsWith("[")) { String typeName = type.getName().substring(1); for (int i = 0; i < primitiveTypes.length; ++i) { if (primitiveTypes[i].toString().equals(typeName)) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, primitives[i].toLowerCase() + "Value", primitiveTypes[i]); agent.linkMethod(methodRef).use(); } } } }); } }
@Override public void classReached(DependencyAgent agent, String className) { for (MethodReader reader : agent.getClassSource().get(className).getMethods()) { AnnotationReader annotation = reader.getAnnotations().get(Export.class.getName()); if (annotation != null) { agent.linkMethod(reader.getReference()).use(); } } }
@Override protected void invokeSpecial(VariableReader receiver, VariableReader instance, MethodReference method, List<? extends VariableReader> arguments) { CallLocation callLocation = impreciseLocation; if (instance == null) { dependencyAnalyzer.linkClass(method.getClassName()).initClass(callLocation); } MethodDependency methodDep = dependencyAnalyzer.linkMethod(method); methodDep.addLocation(callLocation); methodDep.use(); }
private void reachFunctorMethods(DependencyAgent agent, String type) { ClassReader cls = agent.getClassSource().get(type); if (cls != null) { for (MethodReader method : cls.getMethods()) { if (!method.hasModifier(ElementModifier.STATIC)) { agent.linkMethod(method.getReference()).use(); } } } }
private void attachConstructor(DependencyAgent agent, String type, CallLocation location) { MethodReference ref = new MethodReference(type, "<init>", ValueType.VOID); MethodDependency methodDep = agent.linkMethod(ref); methodDep.addLocation(location); methodDep.getVariable(0).propagate(agent.getType(type)); methodDep.use(); } }
private void reachGet(DependencyAgent agent, MethodDependency method) { method.getVariable(1).getArrayItem().connect(method.getResult()); method.getVariable(1).addConsumer(type -> { if (type.getName().startsWith("[")) { String typeName = type.getName().substring(1); for (int i = 0; i < primitiveTypes.length; ++i) { if (primitiveTypes[i].toString().equals(typeName)) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, "valueOf", primitiveTypes[i], ValueType.object(wrapper)); agent.linkMethod(methodRef).use(); method.getResult().propagate(agent.getType("java.lang." + primitiveWrappers[i])); } } } }); }
public void addEntryPoint(MethodReference methodRef, String... argumentTypes) { ValueType[] parameters = methodRef.getDescriptor().getParameterTypes(); if (parameters.length + 1 != argumentTypes.length) { throw new IllegalArgumentException("argumentTypes length does not match the number of method's arguments"); } MethodDependency method = linkMethod(methodRef); method.use(); DependencyNode[] varNodes = method.getVariables(); varNodes[0].propagate(getType(methodRef.getClassName())); for (int i = 0; i < argumentTypes.length; ++i) { varNodes[i + 1].propagate(getType(argumentTypes[i])); } }
@Override public void nullCheck(VariableReader receiver, VariableReader value) { DependencyNode valueNode = getNode(value); DependencyNode receiverNode = getNode(receiver); if (valueNode != null) { valueNode.connect(receiverNode); } MethodDependency npeMethod = getAnalyzer().linkMethod(NPE_INIT_METHOD); npeMethod.addLocation(getCallLocation()); npeMethod.use(); }
@Override public void classReached(DependencyAgent agent, String className) { ClassReader cls = agent.getClassSource().get(className); for (MethodReader method : cls.getMethods()) { AnnotationReader exposeAnnot = method.getAnnotations().get(JSMethodToExpose.class.getName()); if (exposeAnnot != null) { MethodDependency methodDep = agent.linkMethod(method.getReference()); methodDep.getVariable(0).propagate(agent.getType(className)); methodDep.use(); } } } }
@Override public void started(DependencyAgent agent) { allClasses = agent.createNode(); allClasses.addConsumer(c -> { if (agent.getClassSource().isSuperType("java.lang.Throwable", c.getName()).orElse(false)) { MethodDependency methodDep = agent.linkMethod(new MethodReference(c.getName(), GET_MESSAGE)); methodDep.getVariable(0).propagate(c); methodDep.use(); } }); agent.linkClass("java.lang.Throwable"); }
@Override public void monitorEnter(VariableReader objectRef) { if (getAnalyzer().asyncSupported) { MethodDependency methodDep = getAnalyzer().linkMethod(MONITOR_ENTER_METHOD); methodDep.addLocation(getCallLocation()); getNode(objectRef).connect(methodDep.getVariable(1)); methodDep.use(); } MethodDependency methodDep = getAnalyzer().linkMethod(MONITOR_ENTER_SYNC_METHOD); methodDep.addLocation(getCallLocation()); getNode(objectRef).connect(methodDep.getVariable(1)); methodDep.use(); }
@Override public void monitorExit(VariableReader objectRef) { if (getAnalyzer().asyncSupported) { MethodDependency methodDep = getAnalyzer().linkMethod(MONITOR_EXIT_METHOD); methodDep.addLocation(getCallLocation()); getNode(objectRef).connect(methodDep.getVariable(1)); methodDep.use(); } MethodDependency methodDep = getAnalyzer().linkMethod(MONITOR_EXIT_SYNC_METHOD); methodDep.addLocation(getCallLocation()); getNode(objectRef).connect(methodDep.getVariable(1)); methodDep.use(); }
@Override public void stringConstant(VariableReader receiver, String cst) { DependencyNode node = getNode(receiver); if (node != null) { node.propagate(getAnalyzer().getType("java.lang.String")); } MethodDependency method = getAnalyzer().linkMethod(STRING_INIT_FROM_CHARS_METHOD); method.addLocation(getCallLocation()); method.use(); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { AnnotationReader delegateAnnot = method.getMethod().getAnnotations().get(DelegateTo.class.getName()); if (delegateAnnot != null) { String delegateMethodName = delegateAnnot.getValue("value").getString(); ClassReader cls = agent.getClassSource().get(method.getReference().getClassName()); for (MethodReader delegate : cls.getMethods()) { if (delegate.getName().equals(delegateMethodName)) { if (delegate != method.getMethod()) { MethodDependency dep = agent.linkMethod(delegate.getReference()); dep.use(); method.addLocationListener(dep::addLocation); } } } } }
@Override public void cloneArray(VariableReader receiver, VariableReader array) { DependencyNode arrayNode = getNode(array); DependencyNode receiverNode = getNode(receiver); if (arrayNode != null && receiverNode != null) { arrayNode.addConsumer(receiverNode::propagate); arrayNode.getArrayItem().connect(receiverNode.getArrayItem()); } MethodDependency cloneDep = getAnalyzer().linkMethod(CLONE_METHOD); cloneDep.addLocation(getCallLocation()); arrayNode.connect(cloneDep.getVariable(0)); cloneDep.use(); }