Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set BodyInterceptors? #609

Closed
ayanamists opened this issue May 28, 2023 · 2 comments
Closed

How to set BodyInterceptors? #609

ayanamists opened this issue May 28, 2023 · 2 comments
Assignees

Comments

@ayanamists
Copy link

By default, the sootup bytecode frontend will output jimple with no type info (for non-arg variables). For example:

{
    java.nio.file.Path l1;
    sun.nio.fs.UnixFileSystemProvider l0;
    unknown $stack4, $stack5, $stack6, $stack7, l2, l3;


    l0 := @this: sun.nio.fs.UnixFileSystemProvider;
    l1 := @parameter0: java.nio.file.Path;
    l2 = staticinvoke <sun.nio.fs.UnixPath: sun.nio.fs.UnixPath toUnixPath(java.nio.file.Path)>(l1);
    l3 = staticinvoke <java.lang.System: java.lang.SecurityManager getSecurityManager()>();

    if l3 == null goto label1;
    $stack5 = new java.lang.RuntimePermission;
    specialinvoke $stack5.<java.lang.RuntimePermission: void <init>(java.lang.String)>("getFileStoreAttributes");
    virtualinvoke l3.<java.lang.SecurityManager: void checkPermission(java.security.Permission)>($stack5);
    virtualinvoke l2.<sun.nio.fs.UnixPath: void checkRead()>();

  label1:
    $stack7 = l0;
    $stack6 = l2;
    $stack4 = virtualinvoke $stack7.<sun.nio.fs.UnixFileSystemProvider: java.nio.file.FileStore getFileStore(sun.nio.fs.UnixPath)>($stack6);

    return $stack4;
}

The stack$_ variables has type unknown. I guessed that I should use TypeAssigner body interceptor.

I tried

public static void main(String[] args) {
    JavaView v = createViewForClassPath(javaClassPath);
    v.configBodyInterceptors((c) -> new ClassLoadingOptions() {
      @Nonnull
      @Override
      public List<BodyInterceptor> getBodyInterceptors() {
        List<BodyInterceptor> res = new ArrayList<>();
        res.add(new CastAndReturnInliner());
        res.add(new LocalSplitter());
        res.add(new TypeAssigner());
        return res;
      }
    });
    System.out.println(v.getBodyInterceptors());
}

private static JavaView createViewForClassPath(String classPath) {
    JavaProject javaProject =
            JavaProject.builder(new JavaLanguage(8))
                    .addInputLocation(
                            new JavaClassPathAnalysisInputLocation(
                                    System.getProperty("java.home") + "/lib/rt.jar"))
                    .build();
    return javaProject.createView();
  }

and

private static JavaView createViewForClassPath(String classPath) {
    JavaProject javaProject =
            JavaProject.builder(new JavaLanguage(8))
                    .addInputLocation(
                            new JavaClassPathAnalysisInputLocation(
                                    System.getProperty("java.home") + "/lib/rt.jar"))
                    .build();
    return javaProject.createView((c) -> new ClassLoadingOptions() {
      @Nonnull
      @Override
      public List<BodyInterceptor> getBodyInterceptors() {
        List<BodyInterceptor> res = new ArrayList<>();
        res.add(new CastAndReturnInliner());
        res.add(new LocalSplitter());
        res.add(new TypeAssigner());
        return res;
      }
    });
  }

But these two ways will both cause System.out.println(v.getBodyInterceptors()); output [], and jimple is not typed. How can I get the typed jimple?

@kadirayk
Copy link
Member

Thanks for raising this issue. This method returns an empty list. We will fix this.

@kadirayk kadirayk self-assigned this May 31, 2023
@kadirayk
Copy link
Member

kadirayk commented Jun 1, 2023

It should work now with fix #614

@kadirayk kadirayk closed this as completed Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants