public MethodDependency propagate(int parameterIndex, DependencyType type) { getVariable(parameterIndex).propagate(type); return this; }
private void reachArrayCopy(MethodDependency method) { DependencyNode src = method.getVariable(1); DependencyNode dest = method.getVariable(3); src.getArrayItem().connect(dest.getArrayItem()); } }
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(); } } } }); } }
public static void includeStackTraceMethods(DependencyAnalyzer dependencyAnalyzer) { MethodDependency dep; DependencyType stringType = dependencyAnalyzer.getType("java.lang.String"); dep = dependencyAnalyzer.linkMethod(new MethodReference( StackTraceElement.class, "<init>", String.class, String.class, String.class, int.class, void.class)); dep.getVariable(0).propagate(dependencyAnalyzer.getType(StackTraceElement.class.getName())); dep.getVariable(1).propagate(stringType); dep.getVariable(2).propagate(stringType); dep.getVariable(3).propagate(stringType); dep.use(); dep = dependencyAnalyzer.linkMethod(new MethodReference( Throwable.class, "setStackTrace", StackTraceElement[].class, void.class)); dep.getVariable(0).propagate(dependencyAnalyzer.getType(Throwable.class.getName())); dep.getVariable(1).propagate(dependencyAnalyzer.getType("[Ljava/lang/StackTraceElement;")); dep.getVariable(1).getArrayItem().propagate(dependencyAnalyzer.getType(StackTraceElement.class.getName())); dep.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(); } }); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { MethodDependency addMethod = agent.linkMethod(new MethodReference(PlatformQueue.class, "wrap", Object.class, PlatformObject.class)); addMethod.getVariable(1).connect(method.getResult()); }
@Override public void methodReached(DependencyAgent agent, MethodDependency method) { switch (method.getMethod().getName()) { case "clone": method.getVariable(0).connect(method.getResult()); break; } } }
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])); } } } }); }
private void reachGetComponentType(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(t -> { if (!t.getName().startsWith("[")) { return; } String typeName = t.getName().substring(1); if (typeName.charAt(0) == 'L') { typeName = ((ValueType.Object) ValueType.parse(typeName)).getClassName(); } method.getResult().getClassValueNode().propagate(agent.getType(typeName)); }); }
private ExceptionConsumer createExceptionConsumer(MethodDependency methodDep, BasicBlockReader block) { List<? extends TryCatchBlockReader> tryCatchBlocks = block.readTryCatchBlocks(); ClassReader[] exceptions = new ClassReader[tryCatchBlocks.size()]; DependencyNode[] vars = new DependencyNode[tryCatchBlocks.size()]; for (int i = 0; i < tryCatchBlocks.size(); ++i) { TryCatchBlockReader tryCatch = tryCatchBlocks.get(i); if (tryCatch.getExceptionType() != null) { exceptions[i] = dependencyAnalyzer.getClassSource().get(tryCatch.getExceptionType()); } if (tryCatch.getHandler().getExceptionVariable() != null) { vars[i] = methodDep.getVariable(tryCatch.getHandler().getExceptionVariable().getIndex()); } } return new ExceptionConsumer(dependencyAnalyzer, exceptions, vars, methodDep); }
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 reachGetInterfaces(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null) { for (String iface : cls.getInterfaces()) { method.getResult().getClassValueNode().propagate(agent.getType(iface)); } } }); }
@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(); } } } }
private void reachGetSuperclass(DependencyAgent agent, MethodDependency method) { method.getVariable(0).getClassValueNode().addConsumer(type -> { String className = type.getName(); if (className.startsWith("[")) { return; } ClassReader cls = agent.getClassSource().get(className); if (cls != null && cls.getParent() != null) { method.getResult().getClassValueNode().propagate(agent.getType(cls.getParent())); } }); }
@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 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"); }
private void handleFieldSet(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getFields) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<String> accessibleFields = getAccessibleFields(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (String fieldName : accessibleFields) { FieldReader field = cls.getField(fieldName); FieldDependency fieldDep = agent.linkField(field.getReference()).addLocation(location); propagateSet(agent, field.getType(), method.getVariable(2), fieldDep.getValue(), location); linkClassIfNecessary(agent, field, location); } }); }
@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(); }
private void handleFieldGet(DependencyAgent agent, MethodDependency method) { CallLocation location = new CallLocation(method.getReference()); DependencyNode classValueNode = agent.linkMethod(getFields) .addLocation(location) .getVariable(0).getClassValueNode(); classValueNode.addConsumer(reflectedType -> { if (reflectedType.getName().startsWith("[")) { return; } Set<String> accessibleFields = getAccessibleFields(agent, reflectedType.getName()); ClassReader cls = agent.getClassSource().get(reflectedType.getName()); for (String fieldName : accessibleFields) { FieldReader field = cls.getField(fieldName); FieldDependency fieldDep = agent.linkField(field.getReference()) .addLocation(location); propagateGet(agent, field.getType(), fieldDep.getValue(), method.getResult(), location); linkClassIfNecessary(agent, field, location); } }); }