[Soot-list] Problem to start with Soot
Jin Li
lijin1988 at gmail.com
Wed Jul 16 21:12:07 EDT 2014
Hi Susanne,
I ran your code in my eclipse, everything is ok except you should add
public static void main(String[] args)
Best regards
Jin
2014-07-15 18:12 GMT+08:00 Susanne Koch <Susanne_Koch91 at web.de>:
> Hello everybody,
>
> I try to make a easy transformation from a class-file (Hello World) to a
> Jimple-file. It is implemented after the creat class-tutorial.
> My problem is, when I want to run it with soot (command line), I get this
> RuntumeException:
> Attempt to create RefType containing a / --> ../../../workspace/SootUse1
> at soot.RefType.<init>(RefType.java:53)
> at soot.RefType.<init>(RefType.java:68)
> at soot.SootClass.<init>(SootClass.java:87)
> at soot.SootClass.<init>(SootClass.java:101)
> at soot.SootResolver.makeClassFer/SootResolver.java:108)
> and so on...
>
> I don't understand, what the problem is. Can somebody help me please?
>
> Your sincerely
> S. Koch
>
> This is my code:
>
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> import java.io.OutputStreamWriter;
> import java.io.PrintWriter;
> import java.util.Arrays;
> import soot.*;
> import soot.jimple.*;
> import soot.options.Options;
> import soot.util.Chain;
> public class Ausf {
> public void main(String[] args) throws IOException {
> Scene.v().loadClassAndSupport("java.lang.Object");
> Scene.v().loadClassAndSupport("java.lang.System");
> SootClass sClass;
> SootMethod method;
> sClass = new SootClass("HelloWorld", Modifier.PUBLIC);
> sClass.setSuperclass(Scene.v().getSootClass("java.lang.Object"));
> Scene.v().addClass(sClass);
> method = new SootMethod("main", Arrays.asList(new Type[] {
> ArrayType.v(
> RefType.v("java.lang.String"), 1) }), VoidType.v(),
> Modifier.PUBLIC | Modifier.STATIC);
> sClass.addMethod(method);
> {
> JimpleBody body = Jimple.v().newBody(method);
> method.setActiveBody(body);
> Chain<Unit> units = body.getUnits();
> Local arg, tmpRef;
> arg = Jimple.v().newLocal("l0",
> ArrayType.v(RefType.v("java.lang.String"), 1));
> body.getLocals().add(arg);
> tmpRef = Jimple.v().newLocal("tmpRef",
> RefType.v("java.io.PrintStream"));
> body.getLocals().add(tmpRef);
> units.add(Jimple.v().newIdentityStmt(
> arg,
> Jimple.v().newParameterRef(
> ArrayType.v(RefType.v("java.lang.String"), 1),
> 0)));
> {
> SootMethod toCall =
> Scene.v().getMethod("<java.io.PrintStream: void
> println(java.lang.String)>");
> units.add(Jimple.v().newInvokeStmt(
>
> Jimple.v().newVirtualInvokeExpr(tmpRef,toCall.makeRef(),
> StringConstant.v("Hello world!"))));
> units.add(Jimple.v().newReturnVoidStmt());
> }
> String fileName = SourceLocator.v().getFileNameFor(sClass,
> Options.output_format_jimple);
> OutputStream streamOut = new
> FileOutputStream(fileName);
> PrintWriter writerOut = new PrintWriter(
> new OutputStreamWriter(streamOut));
> Printer.v().printTo(sClass, writerOut);
> writerOut.flush();
> streamOut.close();
> }
> }
> }
>
> _______________________________________________
> 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/20140717/e34b5a96/attachment-0001.html
More information about the Soot-list
mailing list