<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Pallavi,<div class=""><br class=""></div><div class="">I haven’t tested it but I think you have to write:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="color: #931a68" class=""><b class="">final</b></span> Jimple <span style="color: #7e504f" class="">jimple</span> = Jimple.v();</div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="color: #931a68" class=""><b class="">final</b></span> RefType <span style="color: #7e504f" class="">foStreamType</span> = RefType.v(<span style="color: #3933ff" class="">"java.io.FileOutputStream"</span>);</div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(57, 51, 255);" class=""><span style="color: #931a68" class=""><b class="">final</b></span><span style="color: #000000" class=""> SootMethod </span><span style="color: #7e504f" class="">constructor</span><span style="color: #000000" class=""> = Scene.v().getMethod(</span>"java.io.FileOutputStream: void &lt;init&gt;(java.lang.String)"<span style="color: #000000" class="">);</span></div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(126, 80, 79);" class=""><span style="color: #931a68" class=""><b class="">final</b></span><span style="color: #000000" class=""> Local </span>fileLocal<span style="color: #000000" class=""> = </span>jimple<span style="color: #000000" class="">.newLocal(</span><span style="color: #3933ff" class="">"writing"</span><span style="color: #000000" class="">, </span>foStreamType<span style="color: #000000" class="">);</span></div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="color: #7e504f" class="">body</span>.getLocals().add(<span style="color: #7e504f" class="">fileLocal</span>);</div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(126, 80, 79);" class=""><span style="color: rgb(147, 26, 104);" class=""><b class="">final</b></span>&nbsp;<span style="color: #000000" class="">Stmt </span>assignStmt<span style="color: #000000" class=""> = </span>jimple<span style="color: #000000" class="">.newAssignStmt(</span>fileLocal<span style="color: #000000" class="">, </span>jimple<span style="color: #000000" class="">.newNewExpr(</span>foStreamType<span style="color: #000000" class="">));</span></div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="color: rgb(147, 26, 104);" class=""><b class="">final</b></span>&nbsp;Stmt <span style="color: #7e504f" class="">invokeStmt</span> = <span style="color: #7e504f" class="">jimple</span>.newInvokeStmt(<span style="color: #7e504f" class="">jimple</span>.newSpecialInvokeExpr(<span style="color: #7e504f" class="">fileLocal</span>, <span style="color: #7e504f" class="">constructor</span>.makeRef(), StringConstant.v(<span style="color: #3933ff" class="">"file.txt"</span>)));</div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro';" class=""><span style="color: #7e504f" class="">units</span>.insertBefore(<span style="color: #7e504f" class="">invokeStmt</span>, <span style="color: #7e504f" class="">stmt</span>);</div><div style="margin: 0px; line-height: normal; font-family: 'Source Code Pro'; color: rgb(126, 80, 79);" class="">units<span style="color: #000000" class="">.insertBefore(</span>assignStmt<span style="color: #000000" class="">, </span>invokeStmt<span style="color: #000000" class="">);</span></div></div><div class=""><span style="color: #000000" class=""><br class=""></span></div><div class=""><span style="color: #000000" class="">Regards, Bernhard</span></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 13.01.2017 um 13:16 schrieb Pallavi Majumder &lt;<a href="mailto:s8pamaju@stud.uni-saarland.de" class="">s8pamaju@stud.uni-saarland.de</a>&gt;:</div><br class="Apple-interchange-newline"><div class="">


<meta http-equiv="content-type" content="text/html; charset=utf-8" class="">
<title class=""></title>

<div style="font-family:Arial;font-size:14px" class=""><p class="">Hi Bernhard,<br class="">
<br class="">
I am quite new to Soot so this may sound very silly.&nbsp;<br class="">
<br class="">
If I want to instrument this code:<br class="">
FileOutputStream writer=new FileOutputStream("file.txt");<br class="">
<br class="">
The jimple representation is:<br class="">
java.io.FileOutputStream $r6;<br class="">
$r6 = new java.io.FileOutputStream;<br class="">
specialinvoke $r6.&lt;java.io.FileOutputStream: void &lt;init&gt;(java.lang.String)&gt;("file.txt");<br class="">
<br class="">
Now to do this I write my code as:<br class="">
final Local fileLocal=Jimple.v().newLocal("writing",RefType.v("java.io.FileOutputStream"));<br class="">
body.getLocals().add(fileLocal);<br class="">
<br class="">
//What is the code for creating&nbsp;$r6 = new java.io.FileOutputStream;</p>
<div class="">units .insertBefore(Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(fileLocal, Scene.v() .getMethod("java.io.FileOutputStream: void &lt;init&gt;(java.lang.String)").makeRef( StringConstant.v("file.txt"))),stmt);</div><p class="">I am not able to create the "new FileOutputStream", when I create using newInstanceFieldRef it somehow throws error. Can you tell me what exactly is the code to use here.<br class="">
<br class="">
Thanks,<br class="">
Pallavi<br class="">
&nbsp;</p><p class=""><br class="">
<br class="">
<br class="">
Quoting Bernhard Berger &lt;<a href="mailto:berber@tzi.de" class="">berber@tzi.de</a>&gt;:</p>
<blockquote style="border-left:2px solid blue;margin-left:2px;padding-left:12px;" type="cite" class=""><p class="">Hi Pallavi,</p>
<div class="">&nbsp;</div>
<div class="">is the exception thrown by Soot or by the application you are instrumenting? I think you forgot to call the new operator. If you take a look at some Jimple code you will see that for object creation there will be a JNewExpr (the result will be assigned to you local) and afterwards you are going to call the constructor.</div>
<div class="">&nbsp;</div>
<div class="">Regards, Bernhard</div>
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">Am 12.01.2017 um 11:41 schrieb Pallavi Majumder &lt;<a href="mailto:s8pamaju@stud.uni-saarland.de" class="">s8pamaju@stud.uni-saarland.de</a>&gt;:</div>
<br class="Apple-interchange-newline">
<div class="">&nbsp;</div>
</blockquote>
</div>
</div>
</blockquote>
<div style="font-family:Arial;font-size:14px" class=""><p class="">Hi All,<br class="">
<br class="">
I want to instrument the below code using soot:<br class="">
<br class="">
PrintStream writing=new PrintStream(new FileOutputStream("file.txt"));<br class="">
<br class="">
So I thought I'll start with creating the FileOutputStream object first.<br class="">
<br class="">
Soot Code:</p>
<div class="">final Local fileLocal=Jimple.v().newLocal("writing",</div>
<div class="">RefType.v("java.io.FileOutputStream"));<br class="">
body.getLocals().add(fileLocal);<br class="">
<div class="">units</div>
<div class="">.insertBefore(Jimple.v()</div>
<div class="">.newInvokeStmt(Jimple.v()</div>
<div class="">.newSpecialInvokeExpr(fileLocal, Scene.v()</div>
<div class="">.getMethod("&lt;java.io.FileOutputStream: void &lt;init&gt;(java.lang.String)").makeRef(),</div>
<div class="">StringConstant.v("file.txt"))),stmt);<br class="">
<br class="">
When I run this it gives the exception:<br class="">
Worker thread execution failed: oops &lt;java.io.FileOutputStream: void &lt;init&gt;(java.lang.String)</div>
</div><p class=""><br class="">
<br class="">
Does anyone know a solution to this?<br class="">
<br class="">
Thanks,<br class="">
Pallavi</p>
</div><p class="">_______________________________________________<br class="">
Soot-list mailing list<br class="">
<a href="mailto:Soot-list@CS.McGill.CA" class="">Soot-list@CS.McGill.CA</a><br class="">
<a href="https://mailman.CS.McGill.CA/mailman/listinfo/soot-list" class="">https://mailman.CS.McGill.CA/mailman/listinfo/soot-list</a><br class="">
<br class="">
<br class="">
<br class=""></p>
</div>
</div></blockquote></div><br class=""></div></body></html>