use of soot.javaToJimple.IInitialResolver.Dependencies in project soot by Sable.
the class AsmClassSource method resolve.
@Override
public Dependencies resolve(SootClass sc) {
InputStream d = null;
try {
d = foundFile.inputStream();
ClassReader clsr = new ClassReader(d);
SootClassBuilder scb = new SootClassBuilder(sc);
clsr.accept(scb, ClassReader.SKIP_FRAMES);
Dependencies deps = new Dependencies();
deps.typesToSignature.addAll(scb.deps);
return deps;
} catch (IOException e) {
throw new RuntimeException("Error: Failed to create class reader from class source.", e);
} finally {
try {
if (d != null) {
d.close();
d = null;
}
} catch (IOException e) {
throw new RuntimeException("Error: Failed to close source input stream.", e);
} finally {
close();
}
}
}
use of soot.javaToJimple.IInitialResolver.Dependencies in project soot by Sable.
the class JavaClassSource method resolve.
public Dependencies resolve(SootClass sc) {
if (Options.v().verbose())
logger.debug("resolving [from .java]: " + className);
IInitialResolver resolver;
if (Options.v().polyglot())
resolver = InitialResolver.v();
else
resolver = JastAddInitialResolver.v();
if (fullPath != null) {
resolver.formAst(fullPath.getPath(), SourceLocator.v().sourcePath(), className);
}
// System.out.println("about to call initial resolver in j2j: "+sc.getName());
Dependencies references = resolver.resolveFromJavaFile(sc);
/*
* 1st March 2006
* Nomair
* This seems to be a good place to calculate all the
* AST Metrics needed from Java's AST
*/
if (Options.v().ast_metrics()) {
// System.out.println("CALLING COMPUTEASTMETRICS!!!!!!!");
Node ast = InitialResolver.v().getAst();
if (ast == null) {
logger.debug("No compatible AST available for AST metrics. Skipping. Try -polyglot option.");
} else {
ComputeASTMetrics metrics = new ComputeASTMetrics(ast);
metrics.apply();
}
}
return references;
}
use of soot.javaToJimple.IInitialResolver.Dependencies in project soot by Sable.
the class JimpleClassSource method resolve.
public Dependencies resolve(SootClass sc) {
if (Options.v().verbose())
logger.debug("resolving [from .jimple]: " + className);
InputStream classFile = null;
try {
// Parse jimple file
classFile = foundFile.inputStream();
soot.jimple.parser.JimpleAST jimpAST = new soot.jimple.parser.JimpleAST(classFile);
jimpAST.getSkeleton(sc);
// Set method source for all methods
JimpleMethodSource mtdSrc = new JimpleMethodSource(jimpAST);
Iterator<SootMethod> mtdIt = sc.methodIterator();
while (mtdIt.hasNext()) {
SootMethod sm = mtdIt.next();
sm.setSource(mtdSrc);
}
// set outer class if not set (which it should not be) and class name contains outer class indicator
String outerClassName = null;
String className = sc.getName();
if (!sc.hasOuterClass() && className.contains("$")) {
if (className.contains("$-")) {
/* This is a special case for generated lambda classes of jack and jill compiler.
* Generated lambda classes may contain '$' which do not indicate an inner/outer
* class separator if the '$' occurs after a inner class with a name starting with
* '-'. Thus we search for '$-' and anything after it including '-' is the inner
* classes name and anything before it is the outer classes name.
*/
outerClassName = className.substring(0, className.indexOf("$-"));
} else {
outerClassName = className.substring(0, className.lastIndexOf('$'));
}
sc.setOuterClass(SootResolver.v().makeClassRef(outerClassName));
}
// Construct the type dependencies of the class
Dependencies deps = new Dependencies();
// The method documentation states it returns RefTypes only, so this is a transformation safe
for (String t : jimpAST.getCstPool()) {
deps.typesToSignature.add(RefType.v(t));
}
if (outerClassName != null)
deps.typesToSignature.add(RefType.v(outerClassName));
return deps;
} catch (IOException e) {
throw new RuntimeException("Error: Failed to create JimpleAST from source input stream for class " + className + ".", e);
} catch (ParserException e) {
throw new RuntimeException("Error: Failed when parsing class " + className + ".", e);
} catch (LexerException e) {
throw new RuntimeException("Error: Failed when lexing class " + className + ".", e);
} finally {
try {
if (classFile != null) {
classFile.close();
classFile = null;
}
} catch (IOException e) {
throw new RuntimeException("Error: Failed to close source input stream.", e);
} finally {
close();
}
}
}
use of soot.javaToJimple.IInitialResolver.Dependencies in project soot by Sable.
the class SootResolver method bringToHierarchyUnchecked.
protected void bringToHierarchyUnchecked(SootClass sc) {
String className = sc.getName();
ClassSource is = SourceLocator.v().getClassSource(className);
try {
boolean modelAsPhantomRef = is == null;
if (modelAsPhantomRef) {
if (!Scene.v().allowsPhantomRefs()) {
String suffix = "";
if (className.equals("java.lang.Object")) {
suffix = " Try adding rt.jar to Soot's classpath, e.g.:\n" + "java -cp sootclasses.jar soot.Main -cp " + ".:/path/to/jdk/jre/lib/rt.jar <other options>";
} else if (className.equals("javax.crypto.Cipher")) {
suffix = " Try adding jce.jar to Soot's classpath, e.g.:\n" + "java -cp sootclasses.jar soot.Main -cp " + ".:/path/to/jdk/jre/lib/rt.jar:/path/to/jdk/jre/lib/jce.jar <other options>";
}
throw new SootClassNotFoundException("couldn't find class: " + className + " (is your soot-class-path set properly?)" + suffix);
} else {
// logger.warn("" + className + " is a
// phantom class!");
sc.setPhantomClass();
}
} else {
Dependencies dependencies = is.resolve(sc);
if (!dependencies.typesToSignature.isEmpty())
classToTypesSignature.putAll(sc, dependencies.typesToSignature);
if (!dependencies.typesToHierarchy.isEmpty())
classToTypesHierarchy.putAll(sc, dependencies.typesToHierarchy);
}
} finally {
if (is != null)
is.close();
}
reResolveHierarchy(sc);
}
use of soot.javaToJimple.IInitialResolver.Dependencies in project soot by Sable.
the class CoffiClassSource method resolve.
public Dependencies resolve(SootClass sc) {
if (Options.v().verbose())
logger.debug("resolving [from .class]: " + className);
List<Type> references = new ArrayList<Type>();
try {
soot.coffi.Util.v().resolveFromClassFile(sc, classFile, fileName, references);
} finally {
close();
}
addSourceFileTag(sc);
IInitialResolver.Dependencies deps = new IInitialResolver.Dependencies();
deps.typesToSignature.addAll(references);
return deps;
}
Aggregations