[Soot-list] Help: How to change the source code by Soot

Barthelemy Dagenais barthed at hotmail.com
Fri May 30 06:57:27 EDT 2008


Hi!

You can use Dava (included in Soot) to produce Java source code from the 
intermediate representation, but it will not look exactly like the original 
source code. The process would look like:

1- Parse source code into Jimple. (this is done automatically by the JastAdd or 
Polyglot frontend)
2- Perform static analysis (usually on Jimple)
3- Transform Jimple into Java source code (this is done automatically by Dava)

The source code produced by Dava is readable, but you will see that some complex 
Java statements will be divided into multiple shorter statements. You will also 
probably loose some information like constants (they will be inlined).

If you do not want to significantly alter the original source code, I see three 
options:

1- You can use line numbers. When you parse the source code into Jimple, there 
is an option to associate the source line number to the jimple statements. You 
could then do your static analysis (with Soot) and add the Java statements in 
the original Java source file using the line numbers to guide the insertion (not 
with Soot).

2- You can perform your static analysis on the AST: there are many frontends you 
can use: Eclipse, JastAdd, Polyglot. Most frontends support some sort of data 
flow analysis, but they are not as convenient as Soot :-)

3- You could heavily annotate the source code during the Jimple transformation 
and use those annotations with Dava, which is a whole research problem by itself...

Cheers,
Barthélémy



Yu Zhang wrote:
> Dear all,
> 
> I want to know whether Soot can work based on Jave Source code.
> 
> For example, after some analysis based on Soot, I want to add some 
> information into the source code.
> The orginial source code is as below:
> public class Temp
> {
>     public void test() {
>         int x = 0;
>     }
> }
> 
> And I want add some code into it, like:
> public class Temp
> {
>     public void test() {
>         int x = 0;
>         System.out.println(x);  //this in the code I want to add
>     }
> }
> 
> How can I do with it?
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list




More information about the Soot-list mailing list