[Soot-list] Fwd: AW: Inserting Log.i() in jimple..

Modhi Alsobiehy m99m20 at hotmail.com
Sat Sep 13 14:11:17 EDT 2014


Your quick response is highly recommended!
Thank you!
-Best,
Modhi

> On Sep 9, 2014, at 9:43 AM, "Modhi Alsobiehy" <m99m20 at hotmail.com> wrote:
> 
> Hi all,
> 
> I sent this email earlier last week but it did not go through because of the size! I reduced the size and hopefully it will go through this time!
> 
> Your quick response is highly appreciated!
> 
> Thank you!
> 
>> From: Modhi Alsobiehy <m99m20 at hotmail.com>
>> Date: September 3, 2014 at 2:36:57 PM CDT
>> To: Steven Arzt <Steven.Arzt at cased.de>, "soot-list at CS.McGill.CA" <soot-list at CS.McGill.CA>, "soot-list at sable.mcgill.ca" <soot-list at sable.mcgill.ca>
>> 
>> Subject: Re: AW: [Soot-list] Inserting Log.i() in jimple..
>> 
>> Hi Steven,
>> 
>> The following is the full source code, I attached the files involved as well..
>> Thank you,,
>> 
>> Modhi,,
> 
> 
>> 
>> Full Code:
>> ------------------
>> import java.io.BufferedReader;
>> import java.io.BufferedWriter;
>> import java.io.FileNotFoundException;
>> import java.io.FileReader;
>> import java.io.FileWriter;
>> import java.io.IOException;
>> import java.util.ArrayList;
>> import java.util.Arrays;
>> import java.util.Collections;
>> import java.util.Iterator;
>> import java.util.List;
>> import java.util.Map;
>> 
>> import android.provider.Settings;
>> import soot.Body;
>> import soot.G;
>> 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.Value;
>> import soot.jimple.AbstractStmtSwitch;
>> import soot.jimple.InvokeStmt;
>> import soot.jimple.Jimple;
>> import soot.jimple.StringConstant;
>> import soot.options.Options;
>> import soot.util.Chain;
>> 
>> 
>> 
>> public class AndroidInstrument {
>>  static String output="";
>>  static ArrayList<String> logLines = new ArrayList<String>();
>>  
>>   public static void main(String[] args) {
>>   
>>    try {
>>     logLines = infoflowResults();
>>    } catch (IOException e1) {
>>     // TODO Auto-generated catch block
>>     e1.printStackTrace();
>>    }
>>    
>>    soot.G.reset(); 
>>    
>>    final String androidJar = "D:/AndroidADT/adt-bundle-windows-x86_64-20131030/sdk/platforms/";
>>   
>>    List<String> argsList = new ArrayList<String>(Arrays.asList(args)); 
>>    
>>    //Scene.v().loadClassAndSupport("android.util.Log");
>>   
>>    Scene.v().addBasicClass("android.util.Log",SootClass.SIGNATURES);
>>    
>>          Scene.v().addBasicClass("java.lang.System",SootClass.SIGNATURES);
>>          
>>          
>>          PackManager.v().getPack("jtp").add(new Transform("jtp.myInstrumenter", new MyBodyTransformer()
>>          {
>>    @Override
>>    protected void internalTransform(final Body b, String phaseName, Map options) 
>>    {
>>     final PatchingChain<Unit> units = b.getUnits();
>>     
>>     //important to use snapshotIterator here
>>      
>>     for(Iterator<Unit> iter = units.snapshotIterator(); iter.hasNext();) 
>>     {
>>       final Unit u = iter.next();
>>       
>>       u.apply(new AbstractStmtSwitch() 
>>       {
>>        
>>        public void caseInvokeStmt(InvokeStmt stmt) 
>>        {
>>         
>>         if(logLines.contains(stmt.toString()))
>>         { 
>>          Local tmpRef = addTmpRef(b);
>>          System.out.println("tmpRef"+tmpRef.toString());
>>          Local tmpString1 = addTmpString1(b);
>>          Local tmpString2 = addTmpString2(b);
>>          System.out.println("tmpString1"+tmpString1.toString());
>>          System.out.println("tmpString2"+tmpString2.toString());
>>          
>>            // insert "tmpRef = android.util.Log.i;" 
>>                units.insertAfter(Jimple.v().newAssignStmt( 
>>                              tmpRef, Jimple.v().newStaticFieldRef( 
>>                              Scene.v().getField("<android.util.Log: int i>").makeRef())), u);
>> 
>>                // insert "tmpString = 'stmt.getUseBoxes().toString()';" 
>>                String stmtStr = stmt.getUseBoxes().toString();
>>                units.insertAfter(Jimple.v().newAssignStmt(tmpString1,
>>                              StringConstant.v(stmtStr)), u);
>>                stmtStr = stmt.getUseBoxes().get(1).getValue().toString();
>>                units.insertAfter(Jimple.v().newAssignStmt(tmpString2,
>>                             StringConstant.v(stmtStr)), u);
>>                
>>                // insert "tmpRef.i(tmpString);" 
>>                SootMethod toCall = Scene.v().getSootClass("android.util.Log").getMethod("int i(java.lang.String,java.lang.String");                    
>>                units.insertAfter(Jimple.v().newInvokeStmt(
>>                              Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), tmpString1, tmpString2 )), u);
>>                
>>                //check that we did not mess up the Jimple
>>                b.validate();
>>          
>>          }
>>         
>>        }//caseInvokeStmt
>>          
>>       } // anbstractStmtSwitch
>>       );// apply
>>      } // for iterator
>>     }// internalTransformer closed
>> 
>>   }));
>>   
>>         
>>   argsList.addAll(Arrays.asList(new String[] {
>>     "-cp" , androidJar    
>>     }));
>>     
>>   String apk = "D:/simpleCal.apk";
>>   
>>   Options.v().set_src_prec(Options.src_prec_apk);
>>   
>>   Options.v().set_process_dir(Collections.singletonList(apk));
>>   
>>   Options.v().set_android_jars(androidJar);
>>   
>>   Options.v().set_whole_program(true);
>>   
>>   Options.v().set_allow_phantom_refs(true);
>>   
>>   Options.v().set_output_format(Options.output_format_none);
>>   
>>   Options.v().force_android_jar();
>>   
>>   args = argsList.toArray(new String[0]);
>>   
>>   soot.Main.main(args);
>>   
>>   // to check output of soot
>>   
>>  }
>> 
>>    // ===============================================================
>>   static Local addTmpRef(Body body)
>>    {
>>    Local tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("android.util.Log"));
>>    body.getLocals().add(tmpRef);
>>    return tmpRef;
>>    }
>>    //--------------------------------------------------   
>>    static Local addTmpString1(Body body)
>>    {
>>     Local tmpString = Jimple.v().newLocal("tmpString1", RefType.v("java.lang.String"));
>>     body.getLocals().add(tmpString);
>>     return tmpString;
>>    }
>>   //--------------------------------------------------  
>>   static Local addTmpString2(Body body)
>>    {
>>     Local tmpString = Jimple.v().newLocal("tmpString2", RefType.v("java.lang.String"));
>>     body.getLocals().add(tmpString);
>>     return tmpString;
>>    }
>>   //--------------------------------------------------  
>>   static ArrayList<String> infoflowResults() throws IOException
>>   {
>>    ArrayList<String> logLine = new ArrayList<String>();
>>    FileReader fr = new FileReader("D:/FlowDroid/FlowDroidResults.txt");
>>    BufferedReader txtReader = new BufferedReader(fr);
>>     
>>    String line = txtReader.readLine();
>>    while(!(line== null))
>>    {
>>     if(line.matches("\\s*Found a flow to sink .*, from the following sources:.*"))
>>     {
>>      line = line.replaceFirst(".*Found\\sa\\sflow\\sto\\ssink\\s", "");
>>      line = line.replaceFirst("(on line\\s\\d+)*\\, from the following sources:", "");
>>      logLine.add(line);
>>      
>>     }// end if
>>     line=txtReader.readLine();
>>    }// end while
>>    fr.close();
>>    return logLine;
>>    
>>   }
>> }
>> 
>> 
>> Sent from Windows Mail
> <simpleCal.apk>
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20140913/44126303/attachment-0003.html 
-------------- next part --------------
_______________________________________________
Soot-list mailing list
Soot-list at CS.McGill.CA
https://mailman.CS.McGill.CA/mailman/listinfo/soot-list


More information about the Soot-list mailing list