use of soot.tagkit.AnnotationStringElem in project robovm by robovm.
the class ObjCMemberPlugin method addBindSelectorAnnotation.
static void addBindSelectorAnnotation(SootMethod method, String selectorName) {
AnnotationTag annotationTag = new AnnotationTag(BIND_SELECTOR, 1);
annotationTag.addElem(new AnnotationStringElem(selectorName, 's', "value"));
addRuntimeVisibleAnnotation(method, annotationTag);
}
use of soot.tagkit.AnnotationStringElem in project robovm by robovm.
the class AttributesEncoder method encodeAnnotationElementValue.
private PackedStructureConstant encodeAnnotationElementValue(AnnotationElem ae) {
PackedStructureType type = getAnnotationElementType(ae);
Value kind = new IntegerConstant((byte) ae.getKind());
if (ae instanceof AnnotationIntElem) {
AnnotationIntElem aie = (AnnotationIntElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(aie.getValue()));
} else if (ae instanceof AnnotationLongElem) {
AnnotationLongElem ale = (AnnotationLongElem) ae;
return new PackedStructureConstant(type, kind, new IntegerConstant(ale.getValue()));
} else if (ae instanceof AnnotationFloatElem) {
AnnotationFloatElem afe = (AnnotationFloatElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(afe.getValue()));
} else if (ae instanceof AnnotationDoubleElem) {
AnnotationDoubleElem ade = (AnnotationDoubleElem) ae;
return new PackedStructureConstant(type, kind, new FloatingPointConstant(ade.getValue()));
} else if (ae instanceof AnnotationStringElem) {
AnnotationStringElem ase = (AnnotationStringElem) ae;
return new PackedStructureConstant(type, kind, getStringOrNull(ase.getValue()));
} else if (ae instanceof AnnotationClassElem) {
AnnotationClassElem ace = (AnnotationClassElem) ae;
addDependencyIfNeeded(ace.getDesc());
return new PackedStructureConstant(type, kind, getStringOrNull(ace.getDesc()));
} else if (ae instanceof AnnotationEnumElem) {
AnnotationEnumElem aee = (AnnotationEnumElem) ae;
addDependencyIfNeeded(aee.getTypeName());
return new PackedStructureConstant(type, kind, getStringOrNull(aee.getTypeName()), getStringOrNull(aee.getConstantName()));
} else if (ae instanceof AnnotationArrayElem) {
AnnotationArrayElem aae = (AnnotationArrayElem) ae;
Value[] values = new Value[aae.getNumValues() + 2];
values[0] = kind;
values[1] = new IntegerConstant((char) aae.getNumValues());
for (int i = 0; i < aae.getNumValues(); i++) {
values[i + 2] = encodeAnnotationElementValue(aae.getValueAt(i));
}
return new PackedStructureConstant(type, values);
} else if (ae instanceof AnnotationAnnotationElem) {
AnnotationAnnotationElem aae = (AnnotationAnnotationElem) ae;
return new PackedStructureConstant(type, kind, encodeAnnotationTagValue(aae.getValue()));
}
throw new IllegalArgumentException("Unknown AnnotationElem type: " + ae.getClass());
}
use of soot.tagkit.AnnotationStringElem in project soot by Sable.
the class AnnotationElemBuilder method getAnnotationElement.
public AnnotationElem getAnnotationElement(String name, Object value) {
AnnotationElem elem;
if (value instanceof Byte) {
elem = new AnnotationIntElem((Byte) value, 'B', name);
} else if (value instanceof Boolean) {
elem = new AnnotationIntElem(((Boolean) value) ? 1 : 0, 'Z', name);
} else if (value instanceof Character) {
elem = new AnnotationIntElem((Character) value, 'C', name);
} else if (value instanceof Short) {
elem = new AnnotationIntElem((Short) value, 'S', name);
} else if (value instanceof Integer) {
elem = new AnnotationIntElem((Integer) value, 'I', name);
} else if (value instanceof Long) {
elem = new AnnotationLongElem((Long) value, 'J', name);
} else if (value instanceof Float) {
elem = new AnnotationFloatElem((Float) value, 'F', name);
} else if (value instanceof Double) {
elem = new AnnotationDoubleElem((Double) value, 'D', name);
} else if (value instanceof String) {
elem = new AnnotationStringElem(value.toString(), 's', name);
} else if (value instanceof Type) {
Type t = (Type) value;
elem = new AnnotationClassElem(t.getDescriptor(), 'c', name);
} else if (value.getClass().isArray()) {
ArrayList<AnnotationElem> annotationArray = new ArrayList<AnnotationElem>();
if (value instanceof byte[]) {
for (Object element : (byte[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof boolean[]) {
for (Object element : (boolean[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof char[]) {
for (Object element : (char[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof short[]) {
for (Object element : (short[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof int[]) {
for (Object element : (int[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof long[]) {
for (Object element : (long[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof float[]) {
for (Object element : (float[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof double[]) {
for (Object element : (double[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof String[]) {
for (Object element : (String[]) value) annotationArray.add(getAnnotationElement(name, element));
} else if (value instanceof Type[]) {
for (Object element : (Type[]) value) annotationArray.add(getAnnotationElement(name, element));
} else
throw new UnsupportedOperationException("Unsupported array value type: " + value.getClass());
elem = new AnnotationArrayElem(annotationArray, '[', name);
} else
throw new UnsupportedOperationException("Unsupported value type: " + value.getClass());
return (elem);
}
use of soot.tagkit.AnnotationStringElem 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 soot.tagkit.AnnotationStringElem in project soot by Sable.
the class DexAnnotation method handleMethodAnnotation.
/**
* Converts method and method parameters annotations from Dexlib to Jimple
*
* @param h
* @param method
*/
public void handleMethodAnnotation(Host h, Method method) {
Set<? extends Annotation> aSet = method.getAnnotations();
if (!(aSet == null || aSet.isEmpty())) {
List<Tag> tags = handleAnnotation(aSet, null);
if (tags != null)
for (Tag t : tags) if (t != null) {
h.addTag(t);
}
}
String[] parameterNames = null;
int i = 0;
for (MethodParameter p : method.getParameters()) {
String name = p.getName();
if (name != null) {
parameterNames = new String[method.getParameters().size()];
parameterNames[i] = name;
}
i++;
}
if (parameterNames != null) {
h.addTag(new ParamNamesTag(parameterNames));
}
// Is there any parameter annotation?
boolean doParam = false;
List<? extends MethodParameter> parameters = method.getParameters();
for (MethodParameter p : parameters) {
if (p.getAnnotations().size() > 0) {
doParam = true;
break;
}
}
if (doParam) {
VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(parameters.size(), AnnotationConstants.RUNTIME_VISIBLE);
for (MethodParameter p : parameters) {
List<Tag> tags = handleAnnotation(p.getAnnotations(), null);
// so that we keep the order intact.
if (tags == null) {
tag.addVisibilityAnnotation(null);
continue;
}
VisibilityAnnotationTag paramVat = new VisibilityAnnotationTag(AnnotationConstants.RUNTIME_VISIBLE);
tag.addVisibilityAnnotation(paramVat);
for (Tag t : tags) {
if (t == null)
continue;
AnnotationTag vat = null;
if (!(t instanceof VisibilityAnnotationTag)) {
if (t instanceof DeprecatedTag) {
vat = new AnnotationTag("Ljava/lang/Deprecated;");
} else if (t instanceof SignatureTag) {
SignatureTag sig = (SignatureTag) t;
ArrayList<AnnotationElem> sigElements = new ArrayList<AnnotationElem>();
for (String s : SootToDexUtils.splitSignature(sig.getSignature())) sigElements.add(new AnnotationStringElem(s, 's', "value"));
AnnotationElem elem = new AnnotationArrayElem(sigElements, '[', "value");
vat = new AnnotationTag("Ldalvik/annotation/Signature;", Collections.singleton(elem));
} else {
throw new RuntimeException("error: unhandled tag for parameter annotation in method " + h + " (" + t + ").");
}
} else {
vat = ((VisibilityAnnotationTag) t).getAnnotations().get(0);
}
paramVat.addAnnotation(vat);
}
}
if (tag.getVisibilityAnnotations().size() > 0)
h.addTag(tag);
}
}
Aggregations