@Override public void visitEnum(String name, String desc, String value) { objs.add(new Field(null, value, desc)); } }
if ((fn.access & ACC_STATIC_FINAL) == ACC_STATIC_FINAL) { if (fn.cst == null) { char t = fn.field.getType().charAt(0); if (t == 'L' || t == '[') { fs.put(fn.field.getName() + ":" + fn.field.getType(), fn); } else if (isPrimitiveZero(fn.field.getType(), fn.cst)) { shouldNotBeAssigned.put(fn.field.getName() + ":" + fn.field.getType(), fn); fn.cst = getDefaultValueOfType(fn.field.getType().charAt(0));
public static void doAccept(DexAnnotationVisitor dexAnnotationVisitor, String k, Object value) { if (value instanceof ArrayList) { DexAnnotationVisitor a = dexAnnotationVisitor.visitArray(k); for (Object o : (ArrayList) value) { doAccept(a, null, o); } a.visitEnd(); } else if (value instanceof Ann) { Ann ann = (Ann) value; DexAnnotationVisitor a = dexAnnotationVisitor.visitAnnotation(k, ann.name); for (Map.Entry<String, Object> e : ann.elements) { doAccept(a, e.getKey(), e.getValue()); } a.visitEnd(); } else if (value instanceof Field) { Field f = (Field) value; dexAnnotationVisitor.visitEnum(k, f.getOwner(), f.getName()); } else { dexAnnotationVisitor.visit(k, value); } }
@Override public DexFieldVisitor visitField(int accessFlags, Field field, Object value) { String fieldName = String.format("f%03d_%s", fCount++, field.getName()); out.s("%s(cv);", fieldName); final ArrayOut f = new ArrayOut(); fieldOuts.add(f); f.s("public static void %s(DexClassVisitor cv) {", fieldName); f.push(); f.s("DexFieldVisitor fv=cv.visitField(%s, %s, %s);", Escape.fieldAcc(accessFlags), Escape.v(field), Escape.v(value)); f.s("if(fv != null) {"); f.push(); return new DexFieldVisitor() { @Override public DexAnnotationVisitor visitAnnotation(String name, Visibility visibility) { return new ASMifierAnnotationV("fv", f, name, visibility); } @Override public void visitEnd() { f.s("fv.visitEnd();"); f.pop(); f.s("}"); f.pop(); f.s("}"); } }; }
private int acceptField(ByteBuffer in, int lastIndex, DexClassVisitor dcv, Map<Integer, Integer> fieldAnnotationPositions, Object value, int config) { int diff = (int) readULeb128i(in); int field_access_flags = (int) readULeb128i(in); int field_id = lastIndex + diff; Field field = getField(field_id); // ////////////////////////////////////////////////////////////// DexFieldVisitor dfv = dcv.visitField(field_access_flags, field, value); if (dfv != null) { if ((config & SKIP_ANNOTATION) == 0) { Integer annotation_offset = fieldAnnotationPositions.get(field_id); if (annotation_offset != null) { try { read_annotation_set_item(annotation_offset, dfv); } catch (Exception e) { throw new DexException(e, "while accept annotation in field:%s.", field.toString()); } } } dfv.visitEnd(); } // ////////////////////////////////////////////////////////////// return field_id; }
private void writeAnnotationArrayValue(DexAnnotationVisitor aw, EncodedArray array) { for (EncodedValue value : array.values) { String name = null; Object decodeValue = decodeValue(value); if (value.valueType == VALUE_ENUM) { Field field = (Field) decodeValue; aw.visitEnum(name, field.getOwner(), field.getName()); } else if (decodeValue instanceof EncodedAnnotation) { EncodedAnnotation aannotation = (EncodedAnnotation) decodeValue; DexAnnotationVisitor aaw = aw.visitAnnotation(name, aannotation.type.descriptor.stringData.string); writeAnnotation(aaw, aannotation); aaw.visitEnd(); } else if (decodeValue instanceof EncodedArray) { DexAnnotationVisitor aaw = aw.visitArray(name); writeAnnotationArrayValue(aaw, (EncodedArray) decodeValue); aaw.visitEnd(); } else if (decodeValue instanceof Object[]) { Object[] values = (Object[]) decodeValue; EncodedArray aarray = new EncodedArray(); for (Object avalue : values) { aarray.values.add(EncodedValue.wrap(mFw.cp.wrapEncodedItem(avalue))); } DexAnnotationVisitor aaw = aw.visitArray(name); writeAnnotationArrayValue(aaw, aarray); aaw.visitEnd(); } else { aw.visit(name, decodeValue); } } }
@Override public DexFieldVisitor visitField(int accessFlags, Field field, Object value) { String fieldName = String.format("f%03d_%s", fCount++, field.getName()); out.s("%s(cv);", fieldName); final ArrayOut f = new ArrayOut(); fieldOuts.add(f); f.s("public static void %s(DexClassVisitor cv) {", fieldName); f.push(); f.s("DexFieldVisitor fv=cv.visitField(%s, %s, %s);", Escape.fieldAcc(accessFlags), Escape.v(field), Escape.v(value)); f.s("if(fv != null) {"); f.push(); return new DexFieldVisitor() { @Override public DexAnnotationVisitor visitAnnotation(String name, Visibility visibility) { return new ASMifierAnnotationV("fv", f, name, visibility); } @Override public void visitEnd() { f.s("fv.visitEnd();"); f.pop(); f.s("}"); f.pop(); f.s("}"); } }; }
private int acceptField(ByteBuffer in, int lastIndex, DexClassVisitor dcv, Map<Integer, Integer> fieldAnnotationPositions, Object value, int config) { int diff = (int) readULeb128i(in); int field_access_flags = (int) readULeb128i(in); int field_id = lastIndex + diff; Field field = getField(field_id); // ////////////////////////////////////////////////////////////// DexFieldVisitor dfv = dcv.visitField(field_access_flags, field, value); if (dfv != null) { if ((config & SKIP_ANNOTATION) == 0) { Integer annotation_offset = fieldAnnotationPositions.get(field_id); if (annotation_offset != null) { try { read_annotation_set_item(annotation_offset, dfv); } catch (Exception e) { throw new DexException(e, "while accept annotation in field:%s.", field.toString()); } } } dfv.visitEnd(); } // ////////////////////////////////////////////////////////////// return field_id; }
@Override public void visitEnum(String name, String desc, String value) { items.add(new Item(name, new Field(desc, value, desc))); } }
@Override public Object visitFlocal(SmaliParser.FlocalContext ctx) { if (dexDebugVisitor != null) { DexLabel dexLabel = new DexLabel(); scv.visitLabel(dexLabel); int reg = m.pareReg(ctx.r.getText()); String name; String type; if (ctx.v1 != null) { Field fld = parseFieldAndUnescape("Lt;", ctx.v1.getText()); name = fld.getName(); type = fld.getType(); } else if (ctx.v2 != null) { String txt = ctx.v2.getText(); int i = findString(txt, 1, txt.length(), '\"'); name = unescapeStr(txt.substring(0, i + 1)); type = unEscapeId(txt.substring(i + 2)); } else { if (ctx.name2 != null) { name = unescapeStr(ctx.name2.getText()); } else { name = unEscapeId(ctx.name1.getText()); } type = unEscapeId(ctx.type.getText()); } String sig = ctx.sig == null ? null : unescapeStr(ctx.sig.getText()); dexDebugVisitor.visitStartLocal(reg, dexLabel, name, type, sig); } return null; }
public static Field parseFieldAndUnescape(String owner, String part) throws RuntimeException { int x = part.indexOf(':'); if (x < 0) { throw new RuntimeException(); } return new Field(owner, unEscapeId(part.substring(0, x)), unEscapeId(part.substring(x + 1))); }
@Override public void visitFieldStmt(Op op, int a, int b, Field field) { switch (op) { case SPUT: case SPUT_BOOLEAN: case SPUT_BYTE: case SPUT_CHAR: case SPUT_OBJECT: case SPUT_SHORT: case SPUT_WIDE: if (field.getOwner().equals(classNode.className)) { String key = field.getName() + ":" + field.getType(); fs.remove(key); DexFieldNode dn = shouldNotBeAssigned.get(key); if (dn != null) { //System.out.println(field.getName() + ":" + field.getType()); dn.cst = null; } } break; default: // ignored break; } } });
private Field getField(int id) { fieldIdIn.position(id * 8); int owner_idx = 0xFFFF & fieldIdIn.getShort(); int type_idx = 0xFFFF & fieldIdIn.getShort(); int name_idx = fieldIdIn.getInt(); return new Field(getType(owner_idx), getString(name_idx), getType(type_idx)); }
public static void acceptAnnotationItem(DexAnnotationVisitor dav, String name, Object o) { if (o instanceof Object[]) { DexAnnotationVisitor arrayVisitor = dav.visitArray(name); if (arrayVisitor != null) { Object[] array = (Object[]) o; for (Object e : array) { acceptAnnotationItem(arrayVisitor, null, e); } arrayVisitor.visitEnd(); } } else if (o instanceof DexAnnotationNode) { DexAnnotationNode ann = (DexAnnotationNode) o; DexAnnotationVisitor av = dav.visitAnnotation(name, ann.type); if (av != null) { for (DexAnnotationNode.Item item : ann.items) { acceptAnnotationItem(av, item.name, item.value); } av.visitEnd(); } } else if (o instanceof Field) { Field f = (Field) o; dav.visitEnum(name, f.getType(), f.getName()); } else { dav.visit(name, o); } }