[Soot-list] How to create java.lang.Object variable and boolean constant better when custom an entry point?

liuyuan at fastmail.com liuyuan at fastmail.com
Tue Jun 23 13:53:11 EDT 2020


Hi all,

I'm trying to analyze a Java library. I created an entry point and it works, but I have two questions about the details.

I created the main point to call the following method residing in the library.
public static List<String> parse(Object target, String[] args, boolean failOnExtraFlags)The key code about passing arguments is as follows.
SootMethod toCall = Scene.v().getMethod(
                "<com.sampullara.cli.Args: java.util.List parse(java.lang.Object,java.lang.String[],boolean)>");

Local arg1 = Jimple.v().newLocal("arg1", RefType.v("java.lang.String"));
body.getLocals().add(arg1);
Stmt s2 = Jimple.v().newAssignStmt (arg1, StringConstant.v("Hello world!"));
units.addFirst(s2);

units.add(Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(toCall.makeRef(), arg1, StringConstant.v("Hello world!"), DIntConstant.v(1, BooleanType.v()))));
units.add(Jimple.v().newReturnVoidStmt());
Q1: Although the above code works, I'm not sure if there is a better way to define the arguments, especially the first (i.e., arg1) and third (i.e., DIntConstant.v(1, BooleanType.v())) arguments.
Q2: The callee is a static method, according to Java, it can be called by an instance or a class directly. But if I use "Jimple.v().newVirtualInvokeExpr", it will throw the following error:
wrong static-ness 
at soot.jimple.internal.AbstractVirtualInvokeExpr.<init>(AbstractVirtualInvokeExpr.java:46) 
at soot.jimple.internal.JVirtualInvokeExpr.<init>(JVirtualInvokeExpr.java:39) 
at soot.jimple.Jimple.newVirtualInvokeExpr(Jimple.java:469) 
at soot.jimple.Jimple.newVirtualInvokeExpr(Jimple.java:476)

If I change it to "Jimple.v().newStaticInvokeExpr", the code could work. So if the callee is static, I have to use the "newStaticInvokeExpr"?

Thank you again!

Best regards,
Yuan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20200623/f7eeb71e/attachment.html>


More information about the Soot-list mailing list