<div dir="ltr">Hi all,<div><br></div><div>I am new to Soot, and working on building a static analysis upon Spark pointer analysis.</div><div>I have some expectations of the behavior reflection resolutions, and wonder if the built-in resolver can meet my requirement.</div><div><br></div><div>I want to see my analysis only reaching the classes appeared in the `forName()` call as shown in the example at the end, and not including other classes not reachable from the entry points.</div><div>And then I got confused by the document (<a href="https://www.sable.mcgill.ca/soot/doc/soot/options/CGOptions.html#safe_newinstance()">https://www.sable.mcgill.ca/soot/doc/soot/options/CGOptions.html#safe_newinstance()</a>) which says</div><div><i>Safe newInstance -- Handle Class.newInstance() calls conservatively... When this option is set to false, any calls to Class.newInstance() are assumed not to call the constructor of the created object</i>".</div><div><br></div><div>I cannot get required bahaviors either by turning safe-new-instance on or off, because with this option on, all the classes are reachable; with the option off, non of the class is resolved.</div><div>I wonder if this is because Soot does not support my requirements, or because I set up my analysis in a wrong way.</div><div>Could you give me some suggestions?</div><div><br></div><div>Here is the part of my analysis to enumerate all the classes reachable from the entry point (Simple3.main). I am using callGraph and ReachableMethods.</div><div>```</div><div>  CallGraph callGraph = Scene.v().getCallGraph();</div><div>  List<SootMethod> lm = Scene.v().getEntryPoints();</div><div>  Set<String> sigs = new HashSet<String>();</div><div>  for (SootMethod em: lm) {</div><div>         ReachableMethods rm;</div><div>         rm = new ReachableMethods(callGraph, Collections.singleton(em));</div><div>         rm.update();</div><div>         QueueReader<MethodOrMethodContext> qr = rm.listener();</div><div>         while (qr.hasNext()) {</div><div>           MethodOrMethodContext momc = qr.next();</div><div>           if (momc != null) {</div><div>             SootMethod m = momc.method();</div><div>             if (m.isConcrete()) {</div><div>                  String sig = m.getBytecodeSignature();</div><div>                  if (sigs.add(sig)) {</div><div>                      SootClass cl = m.getDeclaringClass();</div><div>                      System.out.println("Found "+cl.getType());</div>                  }<br>               }<br>                   }<div>      }<br><div>  }<br><div>```</div><div><div><br></div><div>Here is my command line arguments:</div><div>```</div><div>-cp $JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/charsets.jar:$JAVA_HOME/lib/resources.jar:$JAVA_HOME/lib/jsse.jar:$JAVA_HOME/lib/jce.jar:$SOOT_DIR/target/classes/ -process-dir simple3_classes/ -main-class Simple3 -d simple3Output -w -p cg.spark enabled:true  -p cg safe-newinstance:true<br></div><div>```</div></div><div>I also tried to turn `types-for-invoke:true` on and those two cases still happened.<br></div><div><br></div><div>Here is my simple example. </div><div>I expected to see only the "Goat" class accessed, but other animal class "Cat" also appeared if I turned "safe-newinstance" on; none of "Goat" and "Cat" appeared with "safe-newinstance" off.</div><div>``` </div><div>// Goat.java</div><div>class Goat {</div><div>    private String name;</div><div>    public Goat(String n) {<br>        name = n;<br>    }<br></div><div>}</div><div><div>// Cat.java</div><div>class Cat {</div><div>    private String name;</div><div>    public Cat(String n) {<br>        name = n;<br>    }<br></div><div>}</div></div><div>//Simple3.java</div><div>import java.lang.reflect.*;<br>public class Simple3 {<br>    public static void main(String[] args) {<br>        try {<br>            Class<?> clazz = Class.forName("Goat");<br>            Constructor<?> cons = clazz.getConstructor(String.class);<br>            Object o = cons.newInstance("Data");<br>            System.out.println("this is my instance:" + o.toString());<br>        }<br>        catch (Exception e) {<br>            System.out.println("Error " + e.getMessage());<br>            e.printStackTrace();<br>        }<br>    }<br>}<br></div><div>```<br></div></div></div><div><br></div><div>Thanks so much,</div><div>Yirui </div></div>