1

I am trying to display all the strings used in a method invocation using SOOT program analysis framework. I am able to check for StringConstant but how do I get values for RefType ? Here is the sample code :

for (Value va : iv.getInvokeExpr().getArgs()) {
    System.out.println("[ARGS : TYPE] " + va.getType() + " with ");

    if (va instanceof StringConstant) {
        System.out.print(va + " ");
    } else if (va instanceof JimpleLocal) {
        JimpleLocal jl = (JimpleLocal) va;
        if (jl.getType() instanceof RefType) {
            RefType rt = (RefType) jl.getType();
            SootClass cls = rt.getSootClass();
            String clsName = cls.getName();
            // recursion possible - backward analysis ?
            if(clsName.equals("java.lang.String")){
                  System.out.print("GOT STRING CLASS - HOW TO GET THE VALUE ?");
             }
         }
    }
}

I am new to the program analysis domain, any pointers will be of great help.

Thanks

Alan Kash
  • 11
  • 1

1 Answers1

0

StringConstant had a getValue Methode. Just cast The value to this type. For locals your questions does not make sense, as they are variables, not constants.

Eric
  • 1,343
  • 1
  • 11
  • 19
  • StringConstant is fine, but if the Local, e.g. $r2, is of **RefType** (java.lang.String), how can I get its runtime value ? One way I could think of is to check the **AssignStmt** for $r2, but that could be recursive, e.g. $r2 = $r1. Is there a better solution for RefType resolution ? – Alan Kash Sep 25 '14 at 19:04