Code Monkey home page Code Monkey logo

jphantom's Introduction

JPhantom

A tool for Java program complementation. It takes a single jar as its main argument and complements it by creating a new jar that adds dummy implementations for every phantom class detected in the original one. (A phantom class is a class that is referenced somewhere but its definition is missing.)

The phantom classes in the produced jar will contain every missing field and method that was referenced and used in the original jar, as well as a supertype that respects every type constraint that was found (e.g., if phantom class B was used in a place where known class A was expected, and a widening reference conversion took place, then we must conclude that class A is a supertype of B).

You can read more about the underlying problem of class hierarchy complementation in the OOPSLA '13 paper (or the presentation slides).

Release

To list JPhantom as a dependency using Maven, add the following to your pom.xml:

<dependency>
  <groupId>org.clyze</groupId>
  <artifactId>jphantom</artifactId>
  <version>1.3</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  compile 'org.clyze:jphantom:1.3'
}

Usage

java -jar <jphantom>  <injar> [--debug] [--help] [--save-class-files] [-d <dir>] [-o <outjar>] [-v (--log, --verbose) N]

 <injar>                 : the jar to be complemented
 --debug                 : Debug mode
 --help                  : Help
 --save-class-files      : Save phantom class files
 -d <dir>                : Phantom-classes destination directory
 -o <outjar>             : the destination path of the complemented jar
 -v (--log, --verbose) N : Level of verbosity

You can use the --save-class-files option to save the generated class files for the phantom classes that were detected in the process. This is handy when you want to inspect only the code that was autogenerated, without having to extract the relevant class files from the complemented jar.

You can also increase the level of verbosity to log every constraint that was detected by using the --verbose N option.

jphantom's People

Contributors

col-e avatar gbalats avatar gkastrinis avatar sblackshear avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jphantom's Issues

NPE in ClassMembers

Hi George,
I'm getting an NPE in ClassMembers$Record:

Exception in thread "main" java.lang.NullPointerException
at jphantom.ClassMembers$Record.lookupIMethod(ClassMembers.java:199)
at jphantom.ClassMembers$Record.lookupMethod(ClassMembers.java:148)
at jphantom.ClassMembers.lookupMethod(ClassMembers.java:49)
at jphantom.adapters.ClassPhantomExtractor$MethodPhantomExtractor.visitMethodInsn(ClassPhantomExtractor.java:260)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1320)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:938)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:669)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
at jphantom.Driver.(Driver.java:82)
at jphantom.Driver.(Driver.java:44)
at jphantom.Driver.main(Driver.java:314)

I took a quick look at it and it appears that the problem is that the rec local is null, but I could not easily tell whether the right fix would be adding a guard or fixing up a broken invariant elsewhere.

As before, the JAR that causes the issue is quite large (contains the entire Android library). so I have posted it here instead.

Sam

NPE in AbstractClassHierarchy

I'm using JPhantom as part of an a preprocessing tool for static analysis of Android. I've found JPhantom to be extremely useful for this task, but it occasionally crashes with the following error when I use it to fill in missing dependencies in the Android library:

Exception in thread "main" java.lang.NullPointerException
at jphantom.tree.AbstractClassHierarchy.checkedObject(AbstractClassHierarchy.java:14)
at jphantom.tree.IncrementalClassHierarchy.contains(IncrementalClassHierarchy.java:109)
at jphantom.ClassMembers$Record.lookupField(ClassMembers.java:82)
at jphantom.ClassMembers.lookupField(ClassMembers.java:30)
at jphantom.adapters.ClassPhantomExtractor$MethodPhantomExtractor.visitFieldInsn(ClassPhantomExtractor.java:403)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1318)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:938)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:669)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:506)
at jphantom.Driver.(Driver.java:82)
at jphantom.Driver.(Driver.java:44)
at jphantom.Driver.main(Driver.java:314)

I've sent you a JAR that exhibits this problem via email since it is too big to attach here.

I currently work around this problem by in ClassPhantomExtractor by replacing

FieldSignature sign = members.lookupField(phantom, name);

with

FieldSignature sign = null;
try {
  sign = members.lookupField(phantom, name);            
} catch (NullPointerException e) {              
  System.out.println("WARNING! Lookup of " + name + " in " + phantom + " failed.");
  break;
}

Clearly, this is not ideal, but it allows JPhantom to continue the complementation without crashing. I'm guessing there is a much better fix than this, but I don't understand the internals of JPhantom enough to know what it is.

NPE in hier.ClassHierarchies

On class jphantom.hier.ClassHierarchies.java, method ClassHierarchy fromJar(JarFile file) around this statement:

Type clazz = Type.getObjectType(reader.getClassName());                    
Type superclass = Type.getObjectType(reader.getSuperName());

When reader is of the type Object, the superName will be null, thus it throws NPE. However when I tried to patch it myself by continuing loop when it finds superName == null, it still throws RuntimeException.

I tested with this apk https://github.com/chighwater/mirror/blob/master/me.organize.android.apk
Please let me know if you need any test files because JPhantom was run via Droidel.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.