-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- handling individual attributes in their respective classes - added support for array types - added assertion of arguments and return types
- Loading branch information
Showing
19 changed files
with
474 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
# jcfl | ||
Java class file loader | ||
|
||
Introduction | ||
============ | ||
|
||
JCFL is a system used to represent Java code in a way suitable for | ||
analysis. | ||
|
||
Loading Classes | ||
=============== | ||
|
||
The Gradle main class is `com.jbalint.jora.proto.JarToRdf`. A jar must | ||
be given on the command line. The result will be created in a | ||
subdirectory called `output` under the directory from which Gradle is | ||
invoked. | ||
|
||
``` | ||
$ gradle run -Pjar=$JAVA_HOME/jre/lib/rt.jar | ||
``` | ||
|
||
``` | ||
$ stardog data add db -g "http://jbalint/javap/jar#rt.jar" output/rt.jar.javap.ttl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,59 @@ | ||
package com.jbalint.jcfl; | ||
|
||
public class AttributeInfo { | ||
import java.io.IOException; | ||
|
||
public abstract class AttributeInfo { | ||
public String type; | ||
|
||
public static AttributeInfo parseAttribute(ConstantPoolInfo constantPool[], UnsignedDataInputStream is) throws IOException { | ||
int typeIndex = is.readUShort(); | ||
String type = constantPool[typeIndex].asString(); | ||
long length = is.readUInt(); | ||
if ("ConstantValue".equals(type)) { | ||
return ConstantValue.parse(constantPool, is); | ||
} else if ("Code".equals(type)) { | ||
return Code.parse(constantPool, is); | ||
} else if ("StackMapTable".equals(type)) { | ||
} else if ("Exceptions".equals(type)) { | ||
return Exceptions.parse(constantPool, is); | ||
} else if ("BootstrapMethods".equals(type)) { | ||
} else if ("InnerClasses".equals(type)) { | ||
return InnerClasses.parse(constantPool, is); | ||
} else if ("EnclosingMethod".equals(type)) { | ||
return EnclosingMethod.parse(constantPool, is); | ||
} else if ("Synthetic".equals(type)) { | ||
Synthetic info = new Synthetic(); | ||
info.type = type; | ||
return info; | ||
} else if ("Signature".equals(type)) { | ||
return Signature.parse(constantPool, is); | ||
} else if ("RuntimeVisibleAnnotations".equals(type)) { | ||
} else if ("RuntimeInvisibleAnnotations".equals(type)) { | ||
} else if ("RuntimeVisibleParameterAnnotations".equals(type)) { | ||
} else if ("RuntimeInvisibleParameterAnnotations".equals(type)) { | ||
} else if ("RuntimeVisibleTypeAnnotations".equals(type)) { | ||
} else if ("RuntimeInvisibleTypeAnnotations".equals(type)) { | ||
} else if ("AnnotationDefault".equals(type)) { | ||
} else if ("MethodParameters".equals(type)) { | ||
} else if ("SourceFile".equals(type)) { | ||
SourceFile info = new SourceFile(); | ||
info.type = type; | ||
info.sourceFile = constantPool[is.readUShort()].asString(); | ||
return info; | ||
} else if ("SourceDebugExtension".equals(type)) { | ||
} else if ("LineNumberTable".equals(type)) { | ||
return LineNumberTable.parse(constantPool, is); | ||
} else if ("LocalVariableTable".equals(type)) { | ||
return LocalVariableTable.parse(constantPool, is); | ||
} else if ("LocalVariableTypeTable".equals(type)) { | ||
return LocalVariableTypeTable.parse(constantPool, is); | ||
} else if ("Deprecated".equals(type)) { | ||
Deprecated info = new Deprecated(); | ||
info.type = type; | ||
return info; | ||
} | ||
// TODO handle ignored attributes. ideally they will all be parsed | ||
for (int i = 0; i < length; ++i) { is.read(); } | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
package com.jbalint.jcfl; | ||
|
||
import java.io.IOException; | ||
|
||
public class EnclosingMethod extends AttributeInfo { | ||
public static final String TYPE_NAME = EnclosingMethod.class.getSimpleName(); | ||
|
||
public ClassInfo clazz; | ||
public NameAndType method; | ||
} | ||
|
||
public static EnclosingMethod parse(ConstantPoolInfo constantPool[], UnsignedDataInputStream is) throws IOException { | ||
EnclosingMethod info = new EnclosingMethod(); | ||
info.type = TYPE_NAME; | ||
info.clazz = (ClassInfo) constantPool[is.readUShort()]; | ||
// may be null | ||
info.method = (NameAndType) constantPool[is.readUShort()]; | ||
return info; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
package com.jbalint.jcfl; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class InnerClasses extends AttributeInfo { | ||
public static final String TYPE_NAME = InnerClasses.class.getSimpleName(); | ||
|
||
public static class InnerClass { | ||
public int innerClassInfoIndex; | ||
public int outerClassInfoIndex; | ||
public int innerNameIndex; | ||
public int innerClassAccessFlags; | ||
} | ||
public List<InnerClass> classes = new ArrayList<>(); | ||
|
||
public static InnerClasses parse(ConstantPoolInfo constantPool[], UnsignedDataInputStream is) throws IOException { | ||
InnerClasses info = new InnerClasses(); | ||
info.type = TYPE_NAME; | ||
int numberOfClasses = is.readUShort(); | ||
for (int i = 0; i < numberOfClasses; ++i) { | ||
InnerClasses.InnerClass inner = new InnerClasses.InnerClass(); | ||
inner.innerClassInfoIndex = is.readUShort(); | ||
inner.outerClassInfoIndex = is.readUShort(); | ||
inner.innerNameIndex = is.readUShort(); | ||
inner.innerClassAccessFlags = is.readUShort(); | ||
info.classes.add(inner); | ||
} | ||
return info; | ||
} | ||
} |
Oops, something went wrong.