<div dir="ltr"><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;">Hi,all<br style="box-sizing: border-box;">I did instrumentation in apks,but encountered a problem.My steps:</p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;">I used source code to generate apk, which could run normally.</li></ul><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;">`<br style="box-sizing: border-box;">public class InstrumentationHelper {</p><pre style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; font-stretch: normal; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-radius: 3px; color: rgb(51, 51, 51);"><code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; background: transparent; border-radius: 3px; word-break: normal; display: inline; overflow: visible; line-height: inherit; word-wrap: normal;">public int[] randomArr = {1, 2, 3};

public MethodContainer method(int index) {

    Map&lt;Integer, MethodContainer&gt; methodMap = new HashMap();

    MethodContainer mC1 = new MethodContainer1();
    MethodContainer mC2 = new MethodContainer2();
    MethodContainer mC3 = new MethodContainer3();

    methodMap.put(1, mC2);
    methodMap.put(2, mC3);
    methodMap.put(3, mC1);

    return methodMap.get(randomArr[index]);

}
</code></pre><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;">}`</p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;"><p style="box-sizing: border-box; margin-bottom: 16px;">I used command <code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; padding-top: 0.2em; padding-bottom: 0.2em; background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px;">java -Xmx6g -jar soot-trunk.jar soot.Main -w -allow-phantom-refs -android-jars D:\AndroidSDK\platforms\ -src-prec apk -f jimple -process-dir app-debug.apk</code> to transform apk into jimple files.</p></li><li style="box-sizing: border-box; margin-top: 0.25em; margin-left: 0px;"><p style="box-sizing: border-box; margin-bottom: 16px;">I did my instrumentation according with jimple file generated.<br style="box-sizing: border-box;"><a href="https://cloud.githubusercontent.com/assets/15721702/18819508/9568518a-83c4-11e6-9675-af7169bbe77a.png" target="_blank" style="box-sizing: border-box; background-color: transparent; color: rgb(64, 120, 192);"><img src="https://cloud.githubusercontent.com/assets/15721702/18819508/9568518a-83c4-11e6-9675-af7169bbe77a.png" alt="image" style="box-sizing: content-box; border-style: none; max-width: 100%;"></a></p></li></ul><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;">The left of picture was jimple generated form apk,the other was I used soot&#39;s api to construct.</p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;">When I did instrumentation with this statement <code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; padding-top: 0.2em; padding-bottom: 0.2em; background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px;">$i0 = $r6[$i0];</code>,Soot reported error:</li></ul><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;">Stack trace:</p><pre style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; font-stretch: normal; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-radius: 3px; color: rgb(51, 51, 51);">Warning: Bad use of primitive type at $i0 = $r6[$i0] in &lt;com.example.InstrumentationHelper: com.example.MethodContainer method(int)&gt; in &lt;com.example.InstrumentationHelper: com.example.MethodContainer method(int)&gt;
    at soot.validation.CheckTypesValidator.checkCopy(CheckTypesValidator.java:95)
    at soot.validation.CheckTypesValidator.validate(CheckTypesValidator.java:45)
    at soot.Body.validate(Body.java:258)
    at soot.jimple.JimpleBody.validate(JimpleBody.java:120)
    at soot.jimple.JimpleBody.validate(JimpleBody.java:110)
    at soot.PackManager.runBodyPacks(PackManager.java:988)
    at soot.PackManager.access$000(PackManager.java:138)
    at soot.PackManager$1.run(PackManager.java:633)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
</pre><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;"><p style="box-sizing: border-box; margin-bottom: 16px;">To do this instrumentation,I used these api:<br style="box-sizing: border-box;">` // Set method&#39;s parameter</p><pre style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; margin-bottom: 16px; font-stretch: normal; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-radius: 3px;"><code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; background: transparent; border-radius: 3px; word-break: normal; display: inline; overflow: visible; line-height: inherit; word-wrap: normal;">    List&lt;Type&gt; parameterTypes = new ArrayList&lt;&gt;();
    Type intParam = IntType.v();
    parameterTypes.add(intParam);
    body.getMethod().setParameterTypes(parameterTypes);
    Local intLocal = Jimple.v().newLocal(&quot;$i0&quot;, intParam);
    body.getLocals().add(intLocal);
</code></pre><p style="box-sizing: border-box; margin-bottom: 16px;">`</p></li></ul><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; padding-top: 0.2em; padding-bottom: 0.2em; background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px;">arrLocal = Jimple.v().newLocal(&quot;$r6&quot;, ArrayType.v(RefType.v(&quot;int&quot;), 1));body.getLocals().add(arrLocal); </code></p><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><code style="box-sizing: border-box; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace; font-size: 11.9px; padding-top: 0.2em; padding-bottom: 0.2em; background-color: rgba(0, 0, 0, 0.0392157); border-radius: 3px;">units.insertBefore(Jimple.v().newAssignStmt(intLocal, Jimple.v().newArrayRef(arrLocal, intLocal)), stmt);</code></p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;">Can you give me some advices on this issue?Maybe it&#39;s in connection with autoboxing?</li></ul></div>