<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&nbsp;sig&nbsp;: 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&nbsp;SootMethod&nbsp;openconnectionMethod&nbsp;= 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&lt;Edge&gt;&nbsp;openconnectionEdges&nbsp;=&nbsp;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&nbsp;(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&nbsp;callIntoopenconnection&nbsp;=&nbsp;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&nbsp;srcUnit&nbsp;=&nbsp;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&nbsp;method&nbsp;=&nbsp;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&nbsp;callSites&nbsp;=&nbsp;new&nbsp;SelectedCallSite(method.getDeclaringClass(),&nbsp;method,&nbsp;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&nbsp;b&nbsp;=&nbsp;method.retrieveActiveBody();</span></div><div class="" style=""><span class="" style="">Value&nbsp;tmpRef&nbsp;= 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&nbsp;tmpString&nbsp;= 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">&nbsp; &nbsp; &nbsp;&nbsp;// insert "tmpRef = java.lang.System.out;"&nbsp;</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(&nbsp;tmpRef, Jimple.v().newStaticFieldRef( Scene.v().getField("&lt;java.lang.System: java.io.PrintStream out&gt;").makeRef())),&nbsp;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">&nbsp; &nbsp;&nbsp;// insert "tmpLong = 'HELLO';"&nbsp;</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,&nbsp;</span></div><div class="" style="" id="yui_3_16_0_1_1434745589928_2905"><span class="" style="" id="yui_3_16_0_1_1434745589928_2904">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;StringConstant.v("HELLO")),&nbsp;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">&nbsp; &nbsp;&nbsp;// insert "tmpRef.println(tmpString);"&nbsp;</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&nbsp;toCall&nbsp;= Scene.v().getSootClass("java.io.PrintStream").getMethod("void println(java.lang.String)");&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</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)&nbsp;tmpRef,&nbsp;toCall.makeRef(),&nbsp;tmpString)),&nbsp;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.&nbsp;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&nbsp;</span></div></div></body></html>