[Soot-list] ERROR: oops <java.io.FileOutputStream: void <init>(java.lang.String)
Bernhard Berger
berber at tzi.de
Fri Jan 13 07:37:23 EST 2017
Hi Pallavi,
I haven’t tested it but I think you have to write:
final Jimple jimple = Jimple.v();
final RefType foStreamType = RefType.v("java.io.FileOutputStream");
final SootMethod constructor = Scene.v().getMethod("java.io.FileOutputStream: void <init>(java.lang.String)");
final Local fileLocal = jimple.newLocal("writing", foStreamType);
body.getLocals().add(fileLocal);
final Stmt assignStmt = jimple.newAssignStmt(fileLocal, jimple.newNewExpr(foStreamType));
final Stmt invokeStmt = jimple.newInvokeStmt(jimple.newSpecialInvokeExpr(fileLocal, constructor.makeRef(), StringConstant.v("file.txt")));
units.insertBefore(invokeStmt, stmt);
units.insertBefore(assignStmt, invokeStmt);
Regards, Bernhard
> Am 13.01.2017 um 13:16 schrieb Pallavi Majumder <s8pamaju at stud.uni-saarland.de>:
>
> Hi Bernhard,
>
> I am quite new to Soot so this may sound very silly.
>
> If I want to instrument this code:
> FileOutputStream writer=new FileOutputStream("file.txt");
>
> The jimple representation is:
> java.io.FileOutputStream $r6;
> $r6 = new java.io.FileOutputStream;
> specialinvoke $r6.<java.io.FileOutputStream: void <init>(java.lang.String)>("file.txt");
>
> Now to do this I write my code as:
> final Local fileLocal=Jimple.v().newLocal("writing",RefType.v("java.io.FileOutputStream"));
> body.getLocals().add(fileLocal);
>
> //What is the code for creating $r6 = new java.io.FileOutputStream;
>
> units .insertBefore(Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(fileLocal, Scene.v() .getMethod("java.io.FileOutputStream: void <init>(java.lang.String)").makeRef( StringConstant.v("file.txt"))),stmt);
> 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.
>
> Thanks,
> Pallavi
>
>
>
>
>
> Quoting Bernhard Berger <berber at tzi.de <mailto:berber at tzi.de>>:
>
>> Hi Pallavi,
>>
>>
>> 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.
>>
>> Regards, Bernhard
>>
>>> Am 12.01.2017 um 11:41 schrieb Pallavi Majumder <s8pamaju at stud.uni-saarland.de <mailto:s8pamaju at stud.uni-saarland.de>>:
>>>
>>>
> Hi All,
>
> I want to instrument the below code using soot:
>
> PrintStream writing=new PrintStream(new FileOutputStream("file.txt"));
>
> So I thought I'll start with creating the FileOutputStream object first.
>
> Soot Code:
>
> final Local fileLocal=Jimple.v().newLocal("writing",
> RefType.v("java.io.FileOutputStream"));
> body.getLocals().add(fileLocal);
> units
> .insertBefore(Jimple.v()
> .newInvokeStmt(Jimple.v()
> .newSpecialInvokeExpr(fileLocal, Scene.v()
> .getMethod("<java.io.FileOutputStream: void <init>(java.lang.String)").makeRef(),
> StringConstant.v("file.txt"))),stmt);
>
> When I run this it gives the exception:
> Worker thread execution failed: oops <java.io.FileOutputStream: void <init>(java.lang.String)
>
>
> Does anyone know a solution to this?
>
> Thanks,
> Pallavi
>
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA <mailto:Soot-list at CS.McGill.CA>
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20170113/58f962f8/attachment-0001.html
More information about the Soot-list
mailing list