soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
546 stars 66 forks source link

There are no throw statements in Jimple #925

Closed slimming-fat closed 2 months ago

slimming-fat commented 2 months ago

I use method sootMethod.getBody().getStmts() to obtain jimple,there are no throw statements(new RuntimeException(e)) in Jimple. Demo code:

public static void main(String[] args) {
        Class appClass = ReflectionTest.class;
        Object appObj = null;
        try {
            appObj = appClass.newInstance();
            Method method1 = appClass.getDeclaredMethod("foo");
            method1.invoke(appObj);
            bar();
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException |
                 NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

Jimple:

{
    java.lang.String[] args;
    unknown $stack4, $stack5, appClass, appObj, method1;

    args := @parameter0: java.lang.String[];
    appClass = class "Lneu/demo/ReflectionTest;";
    appObj = virtualinvoke appClass.<java.lang.Class: java.lang.Object newInstance()>();
    $stack4 = newarray (java.lang.Class)[0];
    method1 = virtualinvoke appClass.<java.lang.Class: java.lang.reflect.Method getDeclaredMethod(java.lang.String,java.lang.Class[])>("foo", $stack4);
    $stack5 = newarray (java.lang.Object)[0];
    virtualinvoke method1.<java.lang.reflect.Method: java.lang.Object invoke(java.lang.Object,java.lang.Object[])>(appObj, $stack5);
    staticinvoke <neu.demo.ReflectionTest: void bar()>();

    return;
}
swissiety commented 2 months ago

Which version and configuration did you use?

slimming-fat commented 2 months ago

Which version and configuration did you use?

Thank you, I found the reason. The bytecode after compilation looks like this, which is why there are no throw statements in Jimple.

public static void main(String[] args) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
    Class appClass = ReflectionTest.class;
    Object appObj = appClass.newInstance();
    Method method1 = appClass.getDeclaredMethod("foo");
    method1.invoke(appObj);
    bar();
 }