[Soot-list] Do I understand traps?

Eric Bodden eric.bodden at ec-spride.de
Tue Jan 17 06:05:43 EST 2012


Also with Soot 2.4.0 I am not seeing the Jimple you are seeing. To me
it seems that your soot classpath is wrong, and Soot therefore is
picking up an incorrect version of JTextComponent. In your jimple code
you have references, for instance, to a class "terpword.EkitCore",
which seems highly unusual and probably should not be there. (I don't
have those.)

Eric

On 17 January 2012 11:42, Martin Schäf <martinschaef at googlemail.com> wrote:
> Now that's a problem :( Look at my jimple code below....
> I got this output as follow:
>  - I use a custom subclass of BodyTransformer  (just like in your tutorial)
> @Override
>        protected void internalTransform(Body arg0, String arg1, Map arg2) {
>                SootMethod sootMethod = arg0.getMethod();
>                if (sootMethod.getName().contains("setCaretPosition") ) {
>                        //BREAKPOINT
>                }
>
> at the Breakpoint I check the value of SootMethod.ActiveBody ... which
> has a trap.
>
> I just redownloaded sootclasses-2.4.0.jar from the webpage ...
> Here is the Jimple code:
>
>
>    public void setCaretPosition(int)
>    {
>        terpword.EkitCore r0;
>        int i0;
>        boolean z0, z1;
>        java.lang.IllegalArgumentException r1, $r3;
>        javax.swing.JTextPane $r2;
>
>        r0 := @this: terpword.EkitCore;
> /*3956*/
>        i0 := @parameter0: int;
> /*3956*/
>        z0 = 1;
> /*3956*/
> /*3956*/
>
>     label0:
>        z1 = 1;
> /*3958*/
> /*3958*/
>
>     label1:
>        $r2 = r0.<terpword.EkitCore: javax.swing.JTextPane jtpMain>;
> /*3960*/
>        virtualinvoke $r2.<javax.swing.JTextPane: void
> setCaretPosition(int)>(i0);
> /*3960*/
>
>     label2:
>        goto label4;
> /*3964*/
>
>     label3:
>        $r3 := @caughtexception;
> /*3961*/
>        r1 = $r3;
> /*3961*/
>        z1 = 0;
> /*3962*/
> /*3962*/
>        i0 = i0 + -1;
> /*3963*/
>
>     label4:
>        if z1 != 0 goto label5;
> /*3965*/
>
>        if i0 >= 0 goto label0;
> /*3965*/
>
>     label5:
>        return;
> /*3966*/
>
>        catch java.lang.IllegalArgumentException from label1 to label2
> with label3;
>    }
>
>
>
> 2012/1/17 Eric Bodden <eric.bodden at ec-spride.de>:
>> Are you maybe using an old/buggy version of Soot? For me Soot
>> generates this Jimple code, which has no traps:
>>
>>   public void setCaretPosition(int)
>>    {
>>        javax.swing.text.JTextComponent r0;
>>        int i0, $i1;
>>        javax.swing.text.Document r1;
>>        java.lang.StringBuilder $r2, $r4, $r5;
>>        java.lang.IllegalArgumentException $r3;
>>        java.lang.String $r6;
>>        javax.swing.text.Caret $r7;
>>
>>        r0 := @this: javax.swing.text.JTextComponent;
>>        i0 := @parameter0: int;
>>        r1 = virtualinvoke r0.<javax.swing.text.JTextComponent:
>> javax.swing.text.Document getDocument()>();
>>        if r1 == null goto label2;
>>
>>        $i1 = interfaceinvoke r1.<javax.swing.text.Document: int getLength()>();
>>        if i0 > $i1 goto label0;
>>
>>        if i0 >= 0 goto label1;
>>
>>     label0:
>>        $r3 = new java.lang.IllegalArgumentException;
>>        $r2 = new java.lang.StringBuilder;
>>        specialinvoke $r2.<java.lang.StringBuilder: void <init>()>();
>>        $r4 = virtualinvoke $r2.<java.lang.StringBuilder:
>> java.lang.StringBuilder append(java.lang.String)>("bad position: ");
>>        $r5 = virtualinvoke $r4.<java.lang.StringBuilder:
>> java.lang.StringBuilder append(int)>(i0);
>>        $r6 = virtualinvoke $r5.<java.lang.StringBuilder:
>> java.lang.String toString()>();
>>        specialinvoke $r3.<java.lang.IllegalArgumentException: void
>> <init>(java.lang.String)>($r6);
>>        throw $r3;
>>
>>     label1:
>>        $r7 = r0.<javax.swing.text.JTextComponent:
>> javax.swing.text.Caret caret>;
>>        interfaceinvoke $r7.<javax.swing.text.Caret: void setDot(int)>(i0);
>>
>>     label2:
>>        return;
>>    }
>>
>>
>> Eric
>> On 17 January 2012 11:18, Martin Schäf <martinschaef at googlemail.com> wrote:
>>> Well, the thing with the throws clause is cool with me... but I do not
>>> understand why this method has a trap.
>>> If you look at the source code of javap
>>> javax.swing.text.JTextComponent (see my last email), the exception is
>>> not caught ...
>>> But the SootMethod definitely has a trap referring to a "r..:=
>>> $caughtexception ..$ statement which I do not see in the Java program.
>>>
>>>
>>> 2012/1/17 Eric Bodden <eric.bodden at ec-spride.de>:
>>>> Hi Martin.
>>>>
>>>> While this exception is documented in the JavaDoc, there is no actual
>>>> exception annotation on the method in the JDK's bytecode:
>>>>
>>>> $ javap javax.swing.text.JTextComponent | grep setCaretPosition
>>>>    public void setCaretPosition(int);
>>>>
>>>> You can also see it in the source...
>>>>
>>>>>            public void setCaretPosition(int position) {
>>>>
>>>> That's why Soot says that the method "does not throw anything".
>>>> Basically, this means that the method does not throw any *checked*
>>>> exceptions.
>>>>
>>>>> When debugging into the sootMethod, I find a trap that handles this
>>>>> exception including a catch-block, i.e., it is not thrown out.
>>>>
>>>> The trap would then originate from a try/catch block in the source
>>>> code this sootMethod was generated from.
>>>>
>>>> Eric
>>
>>
>>
>> --
>> Eric Bodden, Ph.D., http://bodden.de/
>> Head of Secure Software Engineering Group at EC SPRIDE
>> Principal Investigator in Secure Services at CASED
>> Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
>> Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt



-- 
Eric Bodden, Ph.D., http://bodden.de/
Head of Secure Software Engineering Group at EC SPRIDE
Principal Investigator in Secure Services at CASED
Tel: +49 6151 16-75422    Fax: +49 6151 16-72051
Room 3.2.14, Mornewegstr. 30, 64293 Darmstadt


More information about the Soot-list mailing list