private static List<String> getParameterDescriptors(CharBuffer cb) { List<String> result = new ArrayList<String>(); cb.get(); // Skip the initial '(' while (cb.hasRemaining() && cb.get(cb.position()) != ')') { StringBuilder sb = new StringBuilder(); nextDescriptor(cb, sb); result.add(sb.toString()); } return result; }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder .append("Entry [index=") .append(index) .append(", name=") .append(name) .append(", desc=") .append(desc) .append("]"); return builder.toString(); }
private static void nextDescriptor(CharBuffer cb, StringBuilder sb) { char c = cb.get(); sb.append(c); if (c == 'L') { do { c = cb.get(); sb.append(c); } while (c != ';'); } else if (c == '[') { nextDescriptor(cb, sb); } else { // Must be a primitive } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder .append("ResolvedEntry [modifiers=") .append(modifiers) .append(", declaringClass=") .append(declaringClass) .append(", index=") .append(index) .append(", name=") .append(name) .append(", desc=") .append(desc) .append("]"); return builder.toString(); }
protected static String getLoType( final Type type, String base, int index, Map<String, String> structs) { if (type instanceof StructureType) { StringBuilder sb = new StringBuilder(); StructureType st = (StructureType) type; sb.append("{"); String name = String.format("%s_%04d", base, index); for (int i = 0; i < st.getTypeCount(); i++) { Type t = st.getTypeAt(i); if (i == 0 && t instanceof StructureType) { if (((StructureType) t).getTypeCount() == 0) { // Skip empty structs as first member continue; } } // Only support arrays embedded in structs StringBuilder dims = new StringBuilder(); while (t instanceof ArrayType) { ArrayType at = (ArrayType) t; dims.append('[').append(at.getSize()).append(']'); t = ((ArrayType) t).getElementType(); } sb.append(getLoType(t, name, i, structs)).append(" m" + i).append(dims).append(";"); } sb.append("}"); structs.put(name, sb.toString()); return "struct " + name; } else { return getHiType(type); } }
public static String getDescriptor(List<soot.Type> paramTypes, soot.Type returnType) { StringBuilder sb = new StringBuilder(); sb.append('('); for (soot.Type t : paramTypes) { sb.append(getDescriptor(t)); } sb.append(')'); sb.append(getDescriptor(returnType)); return sb.toString(); }