<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:13px"><div class="" style="" id="yui_3_16_0_1_1434745589928_2775"><span class="" style="">Hi,</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2775"><span class="" style=""><br></span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2775"><span class="" style="" id="yui_3_16_0_1_1434745589928_2774">I want to instrument an APK file using Soot. I have implemented an Analysis class which constructs the application call graph and iterates on this graph to find specific system calls. I also wrote a code to insert a simple code before every specified call which is founded in the call graph. This is my code:</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2865"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2866"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2879"><span class="" style="" id="yui_3_16_0_1_1434745589928_2878">for(String sig : Constants.OPENCONNECTION_SIGNATURE) {</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2881"><span class="" style="" id="yui_3_16_0_1_1434745589928_2880">final SootMethod openconnectionMethod = Scene.v().getMethod(sig);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2891"><span class="" style="" id="yui_3_16_0_1_1434745589928_2890">Iterator<Edge> openconnectionEdges = callGraph.edgesInto(openconnectionMethod);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2806"><span class="" style="" id="yui_3_16_0_1_1434745589928_2882">while (openconnectionEdges.hasNext()) {</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2884"><span class="" style="" id="yui_3_16_0_1_1434745589928_2883">Edge callIntoopenconnection = openconnectionEdges.next();</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2777"><span class="" style="" id="yui_3_16_0_1_1434745589928_2885">Unit srcUnit = callIntoopenconnection.srcUnit();</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2893"><span class="" style="" id="yui_3_16_0_1_1434745589928_2892">SootMethod method = callIntoopenconnection.getSrc().method();</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2927"><span class="" style="" id="yui_3_16_0_1_1434745589928_2926">SelectedCallSite callSites = new SelectedCallSite(method.getDeclaringClass(), method, srcUnit);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2805"><span class="" style="" id="yui_3_16_0_1_1434745589928_2894">Body b = method.retrieveActiveBody();</span></div><div class="" style=""><span class="" style="">Value tmpRef = addTmpRef(b);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2896"><span class="" style="" id="yui_3_16_0_1_1434745589928_2895">Value tmpString = addTmpString(b);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2778"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2898"><span class="" style="" id="yui_3_16_0_1_1434745589928_2897"> // insert "tmpRef = java.lang.System.out;" </span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2900"><span class="" style="" id="yui_3_16_0_1_1434745589928_2899">b.getUnits().insertBefore(Jimple.v().newAssignStmt( tmpRef, Jimple.v().newStaticFieldRef( Scene.v().getField("<java.lang.System: java.io.PrintStream out>").makeRef())), srcUnit);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2804"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2779"><span class="" style="" id="yui_3_16_0_1_1434745589928_2901"> // insert "tmpLong = 'HELLO';" </span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2903"><span class="" style="" id="yui_3_16_0_1_1434745589928_2902">b.getUnits().insertBefore(Jimple.v().newAssignStmt(tmpString, </span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2905"><span class="" style="" id="yui_3_16_0_1_1434745589928_2904"> StringConstant.v("HELLO")), srcUnit);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2906"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2908"><span class="" style="" id="yui_3_16_0_1_1434745589928_2907"> // insert "tmpRef.println(tmpString);" </span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2781"><span class="" style="" id="yui_3_16_0_1_1434745589928_2780">SootMethod toCall = Scene.v().getSootClass("java.io.PrintStream").getMethod("void println(java.lang.String)"); </span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2925"><span class="" style="" id="yui_3_16_0_1_1434745589928_2924">b.getUnits().insertBefore(Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr((soot.Local) tmpRef, toCall.makeRef(), tmpString)), srcUnit);</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2803"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2782"><span class="" style="" id="yui_3_16_0_1_1434745589928_2923">b.validate();</span></div><div class="" style=""><span class="" style=""></span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2909"><span class="" style=""></span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2783"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2796"><span class="" style="">}</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2784"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2786"><span class="" style="" id="yui_3_16_0_1_1434745589928_2785">I have also added "PackManager.v().writeOutput();" in the main class of my analysis after perfoming the whole analysis. But when I rum my analysis, there is no soot output. I do not know why I can not get the new version of APK including those instrumentation. Do you know what I'm doing wrong?</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2787"><br><span class="" style=""></span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2794"><span class="" style="" id="yui_3_16_0_1_1434745589928_2793">I would be appreciated if you could help me.</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2792"><span class="" style=""></span><br class="" style=""></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2791"><span class="" style="" id="yui_3_16_0_1_1434745589928_2910">Best Regards,</span></div><div id="yui_3_16_0_1_1434745589928_2412">
</div><div class="" dir="ltr" style="" id="yui_3_16_0_1_1434745589928_2789"><span class="" style="" id="yui_3_16_0_1_1434745589928_2798">Marjan </span></div></div></body></html>