use of org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue in project soot by Sable.
the class DexPrinter method buildInnerClassAttribute.
private List<Annotation> buildInnerClassAttribute(SootClass parentClass, InnerClassAttribute t, Set<String> skipList) {
if (t.getSpecs() == null)
return null;
List<Annotation> anns = null;
for (Tag t2 : t.getSpecs()) {
InnerClassTag icTag = (InnerClassTag) t2;
// In Dalvik, both the EnclosingMethod/EnclosingClass tag and the
// InnerClass tag are written to the inner class which is different
// to Java. We thus check whether this tag actually points to our
// outer class.
String outerClass = DexInnerClassParser.getOuterClassNameFromTag(icTag);
String innerClass = icTag.getInnerClass().replaceAll("/", ".");
// next tag.
if (!parentClass.hasOuterClass() || !innerClass.equals(parentClass.getName()))
continue;
// If the outer class points to the very same class, we null it
if (parentClass.getName().equals(outerClass) && icTag.getOuterClass() == null)
outerClass = null;
// Do not write garbage. Never.
if (parentClass.getName().equals(outerClass))
continue;
// This is an actual inner class. Write the annotation
if (skipList.add("Ldalvik/annotation/InnerClass;")) {
// InnerClass annotation
List<AnnotationElement> elements = new ArrayList<AnnotationElement>();
ImmutableAnnotationElement flagsElement = new ImmutableAnnotationElement("accessFlags", new ImmutableIntEncodedValue(icTag.getAccessFlags()));
elements.add(flagsElement);
ImmutableEncodedValue nameValue;
if (icTag.getShortName() != null && !icTag.getShortName().isEmpty())
nameValue = new ImmutableStringEncodedValue(icTag.getShortName());
else
nameValue = ImmutableNullEncodedValue.INSTANCE;
ImmutableAnnotationElement nameElement = new ImmutableAnnotationElement("name", nameValue);
elements.add(nameElement);
if (anns == null)
anns = new ArrayList<Annotation>();
anns.add(new ImmutableAnnotation(AnnotationVisibility.SYSTEM, "Ldalvik/annotation/InnerClass;", elements));
}
}
return anns;
}
use of org.jf.dexlib2.immutable.value.ImmutableIntEncodedValue in project soot by Sable.
the class DexPrinter method makeConstantItem.
private EncodedValue makeConstantItem(SootField sf, Tag t) {
if (!(t instanceof ConstantValueTag))
throw new RuntimeException("error: t not ConstantValueTag.");
if (t instanceof IntegerConstantValueTag) {
Type sft = sf.getType();
IntegerConstantValueTag i = (IntegerConstantValueTag) t;
if (sft instanceof BooleanType) {
int v = i.getIntValue();
if (v == 0) {
return ImmutableBooleanEncodedValue.FALSE_VALUE;
} else if (v == 1) {
return ImmutableBooleanEncodedValue.TRUE_VALUE;
} else {
throw new RuntimeException("error: boolean value from int with value != 0 or 1.");
}
} else if (sft instanceof CharType) {
return new ImmutableCharEncodedValue((char) i.getIntValue());
} else if (sft instanceof ByteType) {
return new ImmutableByteEncodedValue((byte) i.getIntValue());
} else if (sft instanceof IntType) {
return new ImmutableIntEncodedValue(i.getIntValue());
} else if (sft instanceof ShortType) {
return new ImmutableShortEncodedValue((short) i.getIntValue());
} else {
throw new RuntimeException("error: unexpected constant tag type: " + t + " for field " + sf);
}
} else if (t instanceof LongConstantValueTag) {
LongConstantValueTag l = (LongConstantValueTag) t;
return new ImmutableLongEncodedValue(l.getLongValue());
} else if (t instanceof DoubleConstantValueTag) {
DoubleConstantValueTag d = (DoubleConstantValueTag) t;
return new ImmutableDoubleEncodedValue(d.getDoubleValue());
} else if (t instanceof FloatConstantValueTag) {
FloatConstantValueTag f = (FloatConstantValueTag) t;
return new ImmutableFloatEncodedValue(f.getFloatValue());
} else if (t instanceof StringConstantValueTag) {
StringConstantValueTag s = (StringConstantValueTag) t;
if (sf.getType().equals(RefType.v("java.lang.String")))
return new ImmutableStringEncodedValue(s.getStringValue());
else
// Results in "Bogus static initialization"
return null;
} else
throw new RuntimeException("Unexpected constant type");
}
Aggregations