use of org.jf.dexlib2.AccessFlags in project soot by Sable.
the class DexPrinter method toMethods.
private Collection<Method> toMethods(SootClass clazz) {
if (clazz.getMethods().isEmpty())
return null;
String classType = SootToDexUtils.getDexTypeDescriptor(clazz.getType());
List<Method> methods = new ArrayList<Method>();
for (SootMethod sm : clazz.getMethods()) {
if (sm.isPhantom()) {
// Do not print method bodies for inherited methods
continue;
}
MethodImplementation impl = toMethodImplementation(sm);
List<String> parameterNames = null;
if (sm.hasTag("ParamNamesTag"))
parameterNames = ((ParamNamesTag) sm.getTag("ParamNamesTag")).getNames();
int paramIdx = 0;
List<MethodParameter> parameters = null;
if (sm.getParameterCount() > 0) {
parameters = new ArrayList<MethodParameter>();
for (Type tp : sm.getParameterTypes()) {
String paramType = SootToDexUtils.getDexTypeDescriptor(tp);
parameters.add(new ImmutableMethodParameter(paramType, buildMethodParameterAnnotations(sm, paramIdx), sm.isConcrete() && parameterNames != null ? parameterNames.get(paramIdx) : null));
paramIdx++;
}
}
String returnType = SootToDexUtils.getDexTypeDescriptor(sm.getReturnType());
int accessFlags = SootToDexUtils.getDexAccessFlags(sm);
ImmutableMethod meth = new ImmutableMethod(classType, sm.getName(), parameters, returnType, accessFlags, buildMethodAnnotations(sm), impl);
methods.add(meth);
}
return methods;
}
use of org.jf.dexlib2.AccessFlags in project soot by Sable.
the class DexClassLoader method makeSootClass.
public Dependencies makeSootClass(SootClass sc, ClassDef defItem, DexFile dexFile) {
String superClass = defItem.getSuperclass();
Dependencies deps = new Dependencies();
// source file
String sourceFile = defItem.getSourceFile();
if (sourceFile != null) {
sc.addTag(new SourceFileTag(sourceFile));
}
// super class for hierarchy level
if (superClass != null) {
String superClassName = Util.dottedClassName(superClass);
SootClass sootSuperClass = SootResolver.v().makeClassRef(superClassName);
sc.setSuperclass(sootSuperClass);
deps.typesToHierarchy.add(sootSuperClass.getType());
}
// access flags
int accessFlags = defItem.getAccessFlags();
sc.setModifiers(accessFlags);
// Retrieve interface names
if (defItem.getInterfaces() != null) {
for (String interfaceName : defItem.getInterfaces()) {
String interfaceClassName = Util.dottedClassName(interfaceName);
if (sc.implementsInterface(interfaceClassName))
continue;
SootClass interfaceClass = SootResolver.v().makeClassRef(interfaceClassName);
interfaceClass.setModifiers(interfaceClass.getModifiers() | Modifier.INTERFACE);
sc.addInterface(interfaceClass);
deps.typesToHierarchy.add(interfaceClass.getType());
}
}
if (Options.v().oaat() && sc.resolvingLevel() <= SootClass.HIERARCHY) {
return deps;
}
DexAnnotation da = new DexAnnotation(sc, deps);
// get the fields of the class
for (Field sf : defItem.getStaticFields()) {
loadField(sc, da, sf);
}
for (Field f : defItem.getInstanceFields()) {
loadField(sc, da, f);
}
// get the methods of the class
DexMethod dexMethod = createDexMethodFactory(dexFile, sc);
for (Method method : defItem.getDirectMethods()) {
loadMethod(method, sc, da, dexMethod);
}
for (Method method : defItem.getVirtualMethods()) {
loadMethod(method, sc, da, dexMethod);
}
da.handleClassAnnotation(defItem);
// In contrast to Java, Dalvik associates the InnerClassAttribute
// with the inner class, not the outer one. We need to copy the
// tags over to correspond to the Soot semantics.
InnerClassAttribute ica = (InnerClassAttribute) sc.getTag("InnerClassAttribute");
if (ica != null) {
Iterator<InnerClassTag> innerTagIt = ica.getSpecs().iterator();
while (innerTagIt.hasNext()) {
Tag t = innerTagIt.next();
if (t instanceof InnerClassTag) {
InnerClassTag ict = (InnerClassTag) t;
// Get the outer class name
String outer = DexInnerClassParser.getOuterClassNameFromTag(ict);
if (outer == null) {
// If we don't have any clue what the outer class is, we
// just remove
// the reference entirely
innerTagIt.remove();
continue;
}
// we leave it as it is
if (outer.equals(sc.getName()))
continue;
// Check the inner class to make sure that this tag actually
// refers to the current class as the inner class
String inner = ict.getInnerClass().replaceAll("/", ".");
if (!inner.equals(sc.getName())) {
innerTagIt.remove();
continue;
}
SootClass osc = SootResolver.v().makeClassRef(outer);
if (osc == sc) {
if (!sc.hasOuterClass())
continue;
osc = sc.getOuterClass();
} else
deps.typesToHierarchy.add(osc.getType());
// Get the InnerClassAttribute of the outer class
InnerClassAttribute icat = (InnerClassAttribute) osc.getTag("InnerClassAttribute");
if (icat == null) {
icat = new InnerClassAttribute();
osc.addTag(icat);
}
// Transfer the tag from the inner class to the outer class
InnerClassTag newt = new InnerClassTag(ict.getInnerClass(), ict.getOuterClass(), ict.getShortName(), ict.getAccessFlags());
icat.add(newt);
// Remove the tag from the inner class as inner classes do
// not have these tags in the Java / Soot semantics. The
// DexPrinter will copy it back if we do dex->dex.
innerTagIt.remove();
// within the PackManager in method handleInnerClasses().
if (!sc.hasTag("InnerClassTag")) {
if (((InnerClassTag) t).getInnerClass().replaceAll("/", ".").equals(sc.toString())) {
sc.addTag(t);
}
}
}
}
// remove tag if empty
if (ica.getSpecs().isEmpty()) {
sc.getTags().remove(ica);
}
}
return deps;
}
Aggregations