Skip to content

Instantly share code, notes, and snippets.

@martinschaef
Created April 14, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinschaef/56e070cd7a9c5ecd4a2957d72fd2b92f to your computer and use it in GitHub Desktop.
Save martinschaef/56e070cd7a9c5ecd4a2957d72fd2b92f to your computer and use it in GitHub Desktop.
import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.Set;
import com.ibm.wala.cast.java.ipa.callgraph.JavaSourceAnalysisScope;
import com.ibm.wala.cast.java.loader.JavaSourceLoaderImpl;
import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.ipa.cha.ClassHierarchyException;
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
import lombok.extern.slf4j.Slf4j;
import magpiebridge.converter.ClassConverter;
import magpiebridge.converter.WalaToSootIRConverter;
@Slf4j
public class CustomWalaConverter extends WalaToSootIRConverter {
private final ClassConverter classConverter;
public CustomWalaConverter(@Nonnull Set<String> sourcePath,
@Nonnull Set<String> libPath,
String exclusionFilePath) {
super(sourcePath, libPath, exclusionFilePath);
walaOptions.setAllowPhantomClass(true);
classConverter = new ClassConverter();
}
protected Iterator<IClass> iterateWalaJavaSourceClasses() {
if (this.classHierarchy == null) {
try {
this.classHierarchy = ClassHierarchyFactory.makeWithRoot(this.scope, this.factory);
} catch (ClassHierarchyException e) {
log.error(e.getLocalizedMessage());
throw new RuntimeException(e);
}
}
this.classHierarchy.getLoaders();
return this.classHierarchy.getLoader(JavaSourceAnalysisScope.SOURCE).iterateAllClasses();
}
@Override
public void convert() {
Iterator it = this.iterateWalaJavaSourceClasses();
while (it.hasNext()) {
final IClass klass = (IClass) it.next();
final JavaSourceLoaderImpl.JavaClass walaClass = (JavaSourceLoaderImpl.JavaClass) klass;
try {
classConverter.convertClass(walaClass);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getLocalizedMessage());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment