<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }div.FoxDiv20200623122639073119 { }body { font-size: 10.5pt; font-family: 'Microsoft YaHei UI'; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>Hi all,</div><div><br></div><div>I'm trying to analyze a Java library. I created an entry point and it works, but I have two questions about the details.</div><div><br></div><div>I created the <i>main</i> point to call the following method residing in the library.</div><div><pre style="font-family: Consolas, courier; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-weight: bold;
color: #7f0055;
">public</span> <span style="font-weight: bold;
color: #7f0055;
">static</span> List<String> parse(Object target, String[] args, <span style="font-weight: bold;
color: #7f0055;
">boolean</span> failOnExtraFlags)</pre><pre style="font-family: Consolas, courier; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">The key code about passing arguments is as follows.</pre><pre style="font-family: Consolas, courier; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><div style="color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; background-color: rgb(30, 30, 30);"><div><span style="color: #4ec9b0;">SootMethod</span> <span style="color: #9cdcfe;">toCall</span> = <span style="color: #9cdcfe;">Scene</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">getMethod</span>(</div><div> <span style="color: #ce9178;">"<com.sampullara.cli.Args: java.util.List parse(java.lang.Object,java.lang.String[],boolean)>"</span>);</div><br><div><span style="color: #4ec9b0;">Local</span> <span style="color: #9cdcfe;">arg1</span> = <span style="color: #9cdcfe;">Jimple</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">newLocal</span>(<span style="color: #ce9178;">"arg1"</span>, <span style="color: #9cdcfe;">RefType</span>.<span style="color: #dcdcaa;">v</span>(<span style="color: #ce9178;">"java.lang.String"</span>));</div><div><span style="color: #9cdcfe;">body</span>.<span style="color: #dcdcaa;">getLocals</span>().<span style="color: #dcdcaa;">add</span>(arg1);</div><div><span style="color: #4ec9b0;">Stmt</span> <span style="color: #9cdcfe;">s2</span> = <span style="color: #9cdcfe;">Jimple</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">newAssignStmt</span> (arg1, <span style="color: #9cdcfe;">StringConstant</span>.<span style="color: #dcdcaa;">v</span>(<span style="color: #ce9178;">"Hello world!"</span>));</div><div><span style="color: #9cdcfe;">units</span>.<span style="color: #dcdcaa;">addFirst</span>(s2);</div><br><div><span style="color: #9cdcfe;">units</span>.<span style="color: #dcdcaa;">add</span>(<span style="color: #9cdcfe;">Jimple</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">newInvokeStmt</span>(<span style="color: #9cdcfe;">Jimple</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">newStaticInvokeExpr</span>(<span style="color: #9cdcfe;">toCall</span>.<span style="color: #dcdcaa;">makeRef</span>(), arg1, <span style="color: #9cdcfe;">StringConstant</span>.<span style="color: #dcdcaa;">v</span>(<span style="color: #ce9178;">"Hello world!"</span>), <span style="color: #9cdcfe;">DIntConstant</span>.<span style="color: #dcdcaa;">v</span>(<span style="color: #b5cea8;">1</span>, <span style="color: #9cdcfe;">BooleanType</span>.<span style="color: #dcdcaa;">v</span>()))));</div><div><span style="color: #9cdcfe;">units</span>.<span style="color: #dcdcaa;">add</span>(<span style="color: #9cdcfe;">Jimple</span>.<span style="color: #dcdcaa;">v</span>().<span style="color: #dcdcaa;">newReturnVoidStmt</span>());</div></div></pre></div>
<div>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., <span style="color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; font-size: 10.5pt; background-color: rgb(30, 30, 30);">arg1</span><span style="font-size: 10.5pt; line-height: 1.5; background-color: transparent;">) and third (i.e., </span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; color: rgb(156, 220, 254); background-color: rgb(30, 30, 30);">DIntConstant</span><span style="font-size: 10.5pt; color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; background-color: rgb(30, 30, 30);">.</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; color: rgb(220, 220, 170); background-color: rgb(30, 30, 30);">v</span><span style="font-size: 10.5pt; color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; background-color: rgb(30, 30, 30);">(</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; color: rgb(181, 206, 168); background-color: rgb(30, 30, 30);">1</span><span style="font-size: 10.5pt; color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; background-color: rgb(30, 30, 30);">, </span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; color: rgb(156, 220, 254); background-color: rgb(30, 30, 30);">BooleanType</span><span style="font-size: 10.5pt; color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; background-color: rgb(30, 30, 30);">.</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; color: rgb(220, 220, 170); background-color: rgb(30, 30, 30);">v</span><span style="font-size: 10.5pt; color: rgb(212, 212, 212); font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; background-color: rgb(30, 30, 30);">())</span><span style="font-size: 10.5pt; line-height: 1.5; background-color: transparent;">) arguments.</span></div><div><span style="font-size: 10.5pt; line-height: 1.5; background-color: transparent;">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 "</span><span style="font-family: 'DejaVu Sans Mono'; font-size: 9.8pt; line-height: 1.5; background-color: transparent;">Jimple</span><span style="color: rgb(8, 8, 8); font-family: 'DejaVu Sans Mono'; font-size: 9.8pt; line-height: 1.5; background-color: transparent;">.</span><span style="color: rgb(8, 8, 8); font-family: 'DejaVu Sans Mono'; font-size: 9.8pt; line-height: 1.5; font-style: italic; background-color: transparent;">v</span><span style="color: rgb(8, 8, 8); font-family: 'DejaVu Sans Mono'; font-size: 9.8pt; line-height: 1.5; background-color: transparent;">().newVirtualInvokeExpr", it will throw the following error:</span></div><div><span style="font-size: 13.0667px; line-height: 19.6px;"><font face="DejaVu Sans Mono"><div style="color: rgb(8, 8, 8); background-color: transparent;">wrong static-ness </div><div style="color: rgb(8, 8, 8); background-color: transparent;">at soot.jimple.internal.AbstractVirtualInvokeExpr.<init>(AbstractVirtualInvokeExpr.java:46) </div><div style="color: rgb(8, 8, 8); background-color: transparent;">at soot.jimple.internal.JVirtualInvokeExpr.<init>(JVirtualInvokeExpr.java:39) </div><div style="color: rgb(8, 8, 8); background-color: transparent;">at soot.jimple.Jimple.newVirtualInvokeExpr(Jimple.java:469) </div><div style="color: rgb(8, 8, 8); background-color: transparent;">at soot.jimple.Jimple.newVirtualInvokeExpr(Jimple.java:476)</div><div style="color: rgb(8, 8, 8); background-color: transparent;"><br></div><div><font color="#080808">If I change it to "</font><span style="background-color: rgb(255, 255, 255);"><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre;">Jimple</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre;">.</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre;">v</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre;">().</span><span style="font-size: 10.5pt; font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre;">newStaticInvokeExpr", the code could work. So if the callee is static, I have to use the "</span></span><span style="font-family: Consolas, 'Courier New', monospace; line-height: 19px; white-space: pre; font-size: 10.5pt; background-color: transparent;">newStaticInvokeExpr</span><span style="font-family: Consolas, 'Courier New', monospace; font-size: 10.5pt; line-height: 19px; white-space: pre;">"?</span></div></font></span></div><div><br></div>Thank you again!<div><br></div><div>Best regards,</div><div>Yuan<blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div><div class="FoxDiv20200623122639073119"><blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em"><div>
</div></blockquote>
</div></div></blockquote>
</div></body></html>