public static Method parseMethodAndUnescape(String owner, String part) throws RuntimeException { int x = part.indexOf('('); if (x < 0) { throw new RuntimeException(); } int y = part.indexOf(')', x); if (y < 0) { throw new RuntimeException(); } String methodName = unEscapeId(part.substring(0, x)); String[] params = toTypeList(part.substring(x + 1, y)); for (int i = 0; i < params.length; i++) { params[i] = unEscapeId(params[i]); } String ret = unEscapeId(part.substring(y + 1)); return new Method(owner, methodName, params, ret); }
Op getOp(Token t) { return Utils.getOp(t.getText()); }
public static String[] toTypeList(String s) { return listDesc(s).toArray(new String[0]); }
return unescapeStr(value.getText()); case SmaliLexer.BOOLEAN: return "true".equals(value.getText()); case SmaliLexer.BYTE: return parseByte(value.getText()); case SmaliLexer.SHORT: return parseShort(value.getText()); case SmaliLexer.CHAR: return unescapeChar(value.getText()); case SmaliLexer.INT: return parseInt(value.getText()); case SmaliLexer.LONG: return parseLong(value.getText()); return parseFloat(value.getText()); case SmaliLexer.BASE_DOUBLE: case SmaliLexer.DOUBLE_INFINITY: case SmaliLexer.DOUBLE_NAN: return parseDouble(value.getText()); return parseMethodAndUnescape(value.getText()); case SmaliLexer.OBJECT_TYPE: return new DexType(unEscapeId(value.getText())); case SmaliLexer.NULL: return null; case SmaliLexer.FIELD_FULL: return parseFieldAndUnescape(value.getText());
@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; }
static Method parseMethod(String str) { int i = str.indexOf('.'); String owner = str.substring(0, i); int j = str.indexOf('(', i); String name = str.substring(i + 1, j); i = str.indexOf(')', j); String args = str.substring(j + 1, i); String ret = str.substring(i + 1); return new Method(owner, name, Utils.toTypeList(args), ret); }
private static void acceptAnnotations(List<SmaliParser.SAnnotationContext> sAnnotationContexts, DexAnnotationAble dexAnnotationAble) { if (dexAnnotationAble == null) { return; } if (sAnnotationContexts.size() > 0) { for (SmaliParser.SAnnotationContext ctx : sAnnotationContexts) { Visibility visibility = Utils.getAnnVisibility(ctx.visibility.getText()); String type = Utils.unEscapeId(ctx.type.getText()); DexAnnotationVisitor dexAnnotationVisitor = dexAnnotationAble.visitAnnotation(type, visibility); if (dexAnnotationVisitor != null) { List<SmaliParser.SAnnotationKeyNameContext> keys = ctx.sAnnotationKeyName(); if (keys.size() > 0) { List<SmaliParser.SAnnotationValueContext> values = ctx.sAnnotationValue(); for (int i = 0; i < keys.size(); i++) { acceptAnnotation(dexAnnotationVisitor, Utils.unEscapeId(keys.get(i).getText()), values.get(i)); } } dexAnnotationVisitor.visitEnd(); } } } }
public static void acceptMethod(SmaliParser.SMethodContext ctx, String className, DexClassVisitor dexClassVisitor) { Method method; Token methodObj = ctx.methodObj; if (methodObj.getType() == SmaliLexer.METHOD_FULL) { method = Utils.parseMethodAndUnescape(methodObj.getText()); } else {// PART method = Utils.parseMethodAndUnescape(className, methodObj.getText()); } int access = collectAccess(ctx.sAccList()); boolean isStatic = 0 != (access & DexConstants.ACC_STATIC); DexMethodVisitor dexMethodVisitor = dexClassVisitor.visitMethod(access, method); if (dexMethodVisitor != null) { acceptAnnotations(ctx.sAnnotation(), dexMethodVisitor); int ins = Utils.methodIns(method, isStatic); int totalRegisters = findTotalRegisters(ctx, ins); if (totalRegisters < 0) { totalRegisters = ins; } M m = new M(method, totalRegisters, ins, isStatic); acceptParameter(ctx.sParameter(), m, dexMethodVisitor); acceptCode(ctx, m, dexMethodVisitor); dexMethodVisitor.visitEnd(); } }
static private int collectAccess(SmaliParser.SAccListContext ctx) { int access = 0; for (TerminalNode acc : ctx.ACC()) { access |= Utils.getAcc(acc.getSymbol().getText()); } return access; } }
int inRegs = Utils.methodIns(methodNode.method, (methodNode.access & ACC_STATIC) != 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); } }