[Soot-list] soot
Peng Li
lipeng360 at gmail.com
Mon Sep 18 11:06:43 EDT 2006
Thank you for your reply. Yes, I can do the convert in eclipse. However, I
would like do this convert in my program. So I do need to write a program
to translate a class to a jimple. Anybody can give me hlep?
Cheers
Pen
import soot.*;
import soot.options.Options;
import java.io.*;
public class ClassToJimple {
public static void main(String[] args) throws IOException
{
soot.options.Options.v().set_app(true);
Scene.v
().setSootClassPath("C:/workspace/translator;C:/j2sdk1.4.2_12/jre/lib/rt.jar");
SootClass c = Scene.v().loadClassAndSupport("helloworld");
String fileName = SourceLocator.v().getFileNameFor(c,
Options.output_format_jimple);
OutputStream streamOut = new FileOutputStream(fileName);
PrintWriter writerOut = new PrintWriter(new
OutputStreamWriter(streamOut));
Printer.v().printTo(c, writerOut); //this line makes the error
writerOut.flush();
streamOut.close();
}
}
2006/9/18, Raghav Karol <raghav.karol at gmail.com>:
>
> On 9/18/06, Peng Li <lipeng360 at gmail.com> wrote:
> >
> > Hi everyone,
> > I am using soot to write a very simple program to translate a .class
> file to
> > a .jimple file.But because this is my first soot program, I have been
> > stucked for almost 1 week. Could you give me some help?
> >
> > The purpose: write a program to translate a .class file to a .jimple
> file
> > I am using eclipse plug-in. I just install the eclipse plugin as the
> > instruction on the soot website and don't do any setting on my eclipse.
> I
> > don't use any command line to run soot.
>
> The eclipse plugin is not required to write a program to translate a
> class file to a jimple file. You only need, soot, jasmin and polyglot
> jars/classes in your classpath.
>
> Using the eclipse plugin you can easily convert a file to jimple from
> inside eclipse; a soot option should appear when you right click on a
> file in the package explorer in eclipse if the plugin installed
> correctly.
>
> > code:
> >
> >
> > import soot.*;
> > import soot.options.Options;
> > import java.io.*;
> > public class ClassToJimple {
> > public static void main(String[] args) throws IOException
> > {
> > soot.options.Options.v().set_app(true);
> >
> > Scene.v
> ().setSootClassPath("C:/workspace/translator;C:/j2sdk1.4.2_12/jre/lib/rt.jar");
> > SootClass c =
> > Scene.v().loadClassAndSupport("helloworld");
> > String fileName = SourceLocator.v().getFileNameFor(c,
> > Options.output_format_jimple);
> > OutputStream streamOut = new FileOutputStream(fileName);
> > PrintWriter writerOut = new PrintWriter(new
> > OutputStreamWriter(streamOut));
> >
> > Printer.v().printTo(c, writerOut); //this line makes the error
> > writerOut.flush();
> > streamOut.close();
> > }
> > }
>
>
> > I got the following error,
> > Exception in thread "main" java.lang.RuntimeException: method <init> has
> no
> > active body!
> > at soot.Printer.printTo(Printer.java:206)
> > at ClassToJimple.main(ClassToJimple.java :20)
> I use the function given below to retrieve Soot bodies for the
> application classes. As far as I remember something like this occurs
> when you invoke Soot.
>
> private static void retrieveAllBodies() {
> Iterator clIt = Scene.v().getApplicationClasses();
> while (clIt.hasNext()) {
> SootClass cl = (SootClass) clIt.next();
> Iterator methodIt = cl.methodIterator();
> while (methodIt.hasNext()) {
> SootMethod m = (SootMethod) methodIt.next();
>
> if (m.isConcrete()) {
> m.retrieveActiveBody();
> }
> }
> }
> }
>
> > Thank you very much for your help and looking forward to hearing from
> you.
> >
> > Cheers
> >
> > P
> >
> > _______________________________________________
> > Soot-list mailing list
> > Soot-list at sable.mcgill.ca
> > http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
> >
> >
> >
>
>
> --
> Raghav
>
> MSc., Student
> Informatics and Mathematical Modeling
> Technical University of Denmark
>
> +45 606 31 639
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20060918/24cdf23e/attachment.htm
More information about the Soot-list
mailing list