use of org.jf.dexlib2.iface.value.CharEncodedValue in project atlas by alibaba.
the class EncodedValueAdaptor method writeTo.
public static void writeTo(@Nonnull IndentingWriter writer, @Nonnull EncodedValue encodedValue, @Nullable String containingClass) throws IOException {
switch(encodedValue.getValueType()) {
case ValueType.ANNOTATION:
AnnotationEncodedValueAdaptor.writeTo(writer, (AnnotationEncodedValue) encodedValue, containingClass);
return;
case ValueType.ARRAY:
ArrayEncodedValueAdaptor.writeTo(writer, (ArrayEncodedValue) encodedValue, containingClass);
return;
case ValueType.BOOLEAN:
BooleanRenderer.writeTo(writer, ((BooleanEncodedValue) encodedValue).getValue());
return;
case ValueType.BYTE:
ByteRenderer.writeTo(writer, ((ByteEncodedValue) encodedValue).getValue());
return;
case ValueType.CHAR:
CharRenderer.writeTo(writer, ((CharEncodedValue) encodedValue).getValue());
return;
case ValueType.DOUBLE:
DoubleRenderer.writeTo(writer, ((DoubleEncodedValue) encodedValue).getValue());
return;
case ValueType.ENUM:
EnumEncodedValue enumEncodedValue = (EnumEncodedValue) encodedValue;
boolean useImplicitReference = false;
if (enumEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
writer.write(".enum ");
ReferenceUtil.writeFieldDescriptor(writer, enumEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.FIELD:
FieldEncodedValue fieldEncodedValue = (FieldEncodedValue) encodedValue;
useImplicitReference = false;
if (fieldEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
ReferenceUtil.writeFieldDescriptor(writer, fieldEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.FLOAT:
FloatRenderer.writeTo(writer, ((FloatEncodedValue) encodedValue).getValue());
return;
case ValueType.INT:
IntegerRenderer.writeTo(writer, ((IntEncodedValue) encodedValue).getValue());
return;
case ValueType.LONG:
LongRenderer.writeTo(writer, ((LongEncodedValue) encodedValue).getValue());
return;
case ValueType.METHOD:
MethodEncodedValue methodEncodedValue = (MethodEncodedValue) encodedValue;
useImplicitReference = false;
if (methodEncodedValue.getValue().getDefiningClass().equals(containingClass)) {
useImplicitReference = true;
}
ReferenceUtil.writeMethodDescriptor(writer, methodEncodedValue.getValue(), useImplicitReference);
return;
case ValueType.NULL:
writer.write("null");
return;
case ValueType.SHORT:
ShortRenderer.writeTo(writer, ((ShortEncodedValue) encodedValue).getValue());
return;
case ValueType.STRING:
ReferenceFormatter.writeStringReference(writer, ((StringEncodedValue) encodedValue).getValue());
return;
case ValueType.TYPE:
writer.write(((TypeEncodedValue) encodedValue).getValue());
}
}
use of org.jf.dexlib2.iface.value.CharEncodedValue in project soot by Sable.
the class DexAnnotation method handleAnnotationElement.
private ArrayList<AnnotationElem> handleAnnotationElement(AnnotationElement ae, List<? extends EncodedValue> evList) {
ArrayList<AnnotationElem> aelemList = new ArrayList<AnnotationElem>();
for (EncodedValue ev : evList) {
int type = ev.getValueType();
AnnotationElem elem = null;
switch(type) {
case // BYTE
0x00:
{
ByteEncodedValue v = (ByteEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'B', ae.getName());
break;
}
case // SHORT
0x02:
{
ShortEncodedValue v = (ShortEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'S', ae.getName());
break;
}
case // CHAR
0x03:
{
CharEncodedValue v = (CharEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'C', ae.getName());
break;
}
case // INT
0x04:
{
IntEncodedValue v = (IntEncodedValue) ev;
elem = new AnnotationIntElem(v.getValue(), 'I', ae.getName());
break;
}
case // LONG
0x06:
{
LongEncodedValue v = (LongEncodedValue) ev;
elem = new AnnotationLongElem(v.getValue(), 'J', ae.getName());
break;
}
case // FLOAT
0x10:
{
FloatEncodedValue v = (FloatEncodedValue) ev;
elem = new AnnotationFloatElem(v.getValue(), 'F', ae.getName());
break;
}
case // DOUBLE
0x11:
{
DoubleEncodedValue v = (DoubleEncodedValue) ev;
elem = new AnnotationDoubleElem(v.getValue(), 'D', ae.getName());
break;
}
case // STRING
0x17:
{
StringEncodedValue v = (StringEncodedValue) ev;
elem = new AnnotationStringElem(v.getValue(), 's', ae.getName());
break;
}
case // TYPE
0x18:
{
TypeEncodedValue v = (TypeEncodedValue) ev;
elem = new AnnotationClassElem(v.getValue(), 'c', ae.getName());
break;
}
case // FIELD (Dalvik specific?)
0x19:
{
FieldEncodedValue v = (FieldEncodedValue) ev;
FieldReference fr = v.getValue();
String fieldSig = "";
fieldSig += DexType.toSootAT(fr.getDefiningClass()) + ": ";
fieldSig += DexType.toSootAT(fr.getType()) + " ";
fieldSig += fr.getName();
elem = new AnnotationStringElem(fieldSig, 'f', ae.getName());
break;
}
case // METHOD (Dalvik specific?)
0x1a:
{
MethodEncodedValue v = (MethodEncodedValue) ev;
MethodReference mr = v.getValue();
String className = DexType.toSootICAT(mr.getDefiningClass());
String returnType = DexType.toSootAT(mr.getReturnType());
String methodName = mr.getName();
String parameters = "";
for (CharSequence p : mr.getParameterTypes()) {
parameters += DexType.toSootAT(p.toString());
}
String mSig = className + " |" + methodName + " |" + parameters + " |" + returnType;
elem = new AnnotationStringElem(mSig, 'M', ae.getName());
break;
}
case // ENUM : Warning -> encoding Dalvik specific!
0x1b:
{
EnumEncodedValue v = (EnumEncodedValue) ev;
FieldReference fr = v.getValue();
elem = new AnnotationEnumElem(DexType.toSootAT(fr.getType()).toString(), fr.getName(), 'e', ae.getName());
break;
}
case // ARRAY
0x1c:
{
ArrayEncodedValue v = (ArrayEncodedValue) ev;
ArrayList<AnnotationElem> l = handleAnnotationElement(ae, v.getValue());
if (l != null)
elem = new AnnotationArrayElem(l, '[', ae.getName());
break;
}
case // ANNOTATION
0x1d:
{
AnnotationEncodedValue v = (AnnotationEncodedValue) ev;
AnnotationTag t = new AnnotationTag(DexType.toSootAT(v.getType()).toString());
for (AnnotationElement newElem : v.getElements()) {
List<EncodedValue> l = new ArrayList<EncodedValue>();
l.add(newElem.getValue());
List<AnnotationElem> aList = handleAnnotationElement(newElem, l);
if (aList != null)
for (AnnotationElem e : aList) t.addElem(e);
}
elem = new AnnotationAnnotationElem(t, '@', ae.getName());
break;
}
case // NULL (Dalvik specific?)
0x1e:
{
elem = new AnnotationStringElem(null, 'N', ae.getName());
break;
}
case // BOOLEAN
0x1f:
{
BooleanEncodedValue v = (BooleanEncodedValue) ev;
elem = new AnnotationBooleanElem(v.getValue(), 'Z', ae.getName());
break;
}
default:
{
throw new RuntimeException("Unknown annotation element 0x" + Integer.toHexString(type));
}
}
if (elem != null)
aelemList.add(elem);
}
return aelemList;
}
use of org.jf.dexlib2.iface.value.CharEncodedValue in project soot by Sable.
the class DexField method addConstantTag.
/**
* Add constant tag. Should only be called if field is final.
*
* @param df
* @param sf
*/
private static void addConstantTag(SootField df, Field sf) {
Tag tag = null;
EncodedValue ev = sf.getInitialValue();
if (ev instanceof BooleanEncodedValue) {
tag = new IntegerConstantValueTag(((BooleanEncodedValue) ev).getValue() == true ? 1 : 0);
} else if (ev instanceof ByteEncodedValue) {
tag = new IntegerConstantValueTag(((ByteEncodedValue) ev).getValue());
} else if (ev instanceof CharEncodedValue) {
tag = new IntegerConstantValueTag(((CharEncodedValue) ev).getValue());
} else if (ev instanceof DoubleEncodedValue) {
tag = new DoubleConstantValueTag(((DoubleEncodedValue) ev).getValue());
} else if (ev instanceof FloatEncodedValue) {
tag = new FloatConstantValueTag(((FloatEncodedValue) ev).getValue());
} else if (ev instanceof IntEncodedValue) {
tag = new IntegerConstantValueTag(((IntEncodedValue) ev).getValue());
} else if (ev instanceof LongEncodedValue) {
tag = new LongConstantValueTag(((LongEncodedValue) ev).getValue());
} else if (ev instanceof ShortEncodedValue) {
tag = new IntegerConstantValueTag(((ShortEncodedValue) ev).getValue());
} else if (ev instanceof StringEncodedValue) {
tag = new StringConstantValueTag(((StringEncodedValue) ev).getValue());
}
if (tag != null)
df.addTag(tag);
}
Aggregations