<html><head></head><body><div style="color:#000; background-color:#fff; font-family:bookman old style, new york, times, serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1469293317308_2864">Hi all, <br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1469293317308_2921">I am going to use soot to instrument the APK file.</div><div id="yui_3_16_0_ym19_1_1469293317308_2964" dir="ltr">So I have a question that how and what should I put for args in the following line:</div><pre id="yui_3_16_0_ym19_1_1469293317308_2998">soot.Main.main(args);<br></pre><div id="yui_3_16_0_ym19_1_1469293317308_2995" dir="ltr">I don't know what and how should I feed args to my code and also finally where the instrumented apk should be stored? How can I access that? I am using the following code:</div><div id="yui_3_16_0_ym19_1_1469293317308_3050" dir="ltr"><br></div><pre id="yui_3_16_0_ym19_1_1469293317308_3111">import java.util.Iterator;
import java.util.Map;

import soot.Body;
import soot.BodyTransformer;
import soot.Local;
import soot.PackManager;
import soot.PatchingChain;
import soot.RefType;
import soot.Scene;
import soot.SootClass;
import soot.SootMethod;
import soot.Transform;
import soot.Unit;
import soot.jimple.AbstractStmtSwitch;
import soot.jimple.InvokeExpr;
import soot.jimple.InvokeStmt;
import soot.jimple.Jimple;
import soot.jimple.StringConstant;
import soot.options.Options;</pre><pre id="yui_3_16_0_ym19_1_1469293317308_3084">public class AndroidInstrument {
        
        public static void main(String[] args) {
                
                //prefer Android APK files// -src-prec apk
                Options.v().set_src_prec(Options.src_prec_apk);
                
                //output as APK, too//-f J
                Options.v().set_output_format(Options.output_format_dex);
                
        // resolve the PrintStream and System soot-classes
                Scene.v().addBasicClass("java.io.PrintStream",SootClass.SIGNATURES);
        Scene.v().addBasicClass("java.lang.System",SootClass.SIGNATURES);

        PackManager.v().getPack("jtp").add(new Transform("jtp.myInstrumenter", new BodyTransformer() {

                        @Override
                        protected void internalTransform(final Body b, String phaseName, @SuppressWarnings("rawtypes") Map options) {
                                final PatchingChain&lt;Unit&gt; units = b.getUnits();
                                
                                //important to use snapshotIterator here
                                for(Iterator&lt;Unit&gt; iter = units.snapshotIterator(); iter.hasNext();) {
                                        final Unit u = iter.next();
                                        u.apply(new AbstractStmtSwitch() {
                                                
                                                public void caseInvokeStmt(InvokeStmt stmt) {
                                                        InvokeExpr invokeExpr = stmt.getInvokeExpr();
                                                        if(invokeExpr.getMethod().getName().equals("onDraw")) {

                                                                Local tmpRef = addTmpRef(b);
                                                                Local tmpString = addTmpString(b);
                                                                
                                                                  // insert "tmpRef = java.lang.System.out;" 
                                                        units.insertBefore(Jimple.v().newAssignStmt( 
                                                                      tmpRef, Jimple.v().newStaticFieldRef( 
                                                                      Scene.v().getField("&lt;java.lang.System: java.io.PrintStream out&gt;").makeRef())), u);

                                                        // insert "tmpLong = 'HELLO';" 
                                                        units.insertBefore(Jimple.v().newAssignStmt(tmpString, 
                                                                      StringConstant.v("HELLO")), u);
                                                        
                                                        // insert "tmpRef.println(tmpString);" 
                                                        SootMethod toCall = Scene.v().getSootClass("java.io.PrintStream").getMethod("void println(java.lang.String)");                    
                                                        units.insertBefore(Jimple.v().newInvokeStmt(
                                                                      Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), tmpString)), u);
                                                        
                                                        //check that we did not mess up the Jimple
                                                        b.validate();
                                                        }
                                                }
                                                
                                        });
                                }
                        }


                }));
                
                soot.Main.main(args);
        }

    private static Local addTmpRef(Body body)
    {
        Local tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream"));
        body.getLocals().add(tmpRef);
        return tmpRef;
    }
    
    private static Local addTmpString(Body body)
    {
        Local tmpString = Jimple.v().newLocal("tmpString", RefType.v("java.lang.String")); 
        body.getLocals().add(tmpString);
        return tmpString;
    }
}<br><br>Thank you<br></pre></div></body></html>