<div dir="ltr"><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;">`<br style="box-sizing: border-box;">public class InstrumentationHelper {</p><pre style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", 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, "Liberation Mono", 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<Integer, MethodContainer> 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;">}`</p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 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, "Liberation Mono", 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;">The left of picture was jimple generated form apk,the other was I used soot's api to construct.</p><ul style="box-sizing: border-box; padding-left: 2em; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 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, "Liberation Mono", 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;">Stack trace:</p><pre style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", 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 <com.example.InstrumentationHelper: com.example.MethodContainer method(int)> in <com.example.InstrumentationHelper: com.example.MethodContainer method(int)>
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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 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's parameter</p><pre style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", 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, "Liberation Mono", 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<Type> parameterTypes = new ArrayList<>();
Type intParam = IntType.v();
parameterTypes.add(intParam);
body.getMethod().setParameterTypes(parameterTypes);
Local intLocal = Jimple.v().newLocal("$i0", 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;"><code style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", 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("$r6", ArrayType.v(RefType.v("int"), 1));body.getLocals().add(arrLocal); </code></p><p style="box-sizing: border-box; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;"><code style="box-sizing: border-box; font-family: Consolas, "Liberation Mono", 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, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px;"><li style="box-sizing: border-box; margin-left: 0px;">Can you give me some advices on this issue?Maybe it's in connection with autoboxing?</li></ul></div>