use of org.jf.dexlib2.iface.Method in project smali by JesusFreke.
the class ClassDefinition method writeVirtualMethods.
private void writeVirtualMethods(IndentingWriter writer, Set<String> directMethods) throws IOException {
boolean wroteHeader = false;
Set<String> writtenMethods = new HashSet<String>();
Iterable<? extends Method> virtualMethods;
if (classDef instanceof DexBackedClassDef) {
virtualMethods = ((DexBackedClassDef) classDef).getVirtualMethods(false);
} else {
virtualMethods = classDef.getVirtualMethods();
}
for (Method method : virtualMethods) {
if (!wroteHeader) {
writer.write("\n\n");
writer.write("# virtual methods");
wroteHeader = true;
}
writer.write('\n');
// TODO: check for method validation errors
String methodString = ReferenceUtil.getMethodDescriptor(method, true);
IndentingWriter methodWriter = writer;
if (!writtenMethods.add(methodString)) {
writer.write("# duplicate method ignored\n");
methodWriter = new CommentingIndentingWriter(writer);
} else if (directMethods.contains(methodString)) {
writer.write("# There is both a direct and virtual method with this signature.\n" + "# You will need to rename one of these methods, including all references.\n");
System.err.println(String.format("Duplicate direct+virtual method found: %s->%s", classDef.getType(), methodString));
System.err.println("You will need to rename one of these methods, including all references.");
}
MethodImplementation methodImpl = method.getImplementation();
if (methodImpl == null) {
MethodDefinition.writeEmptyMethodTo(methodWriter, method, options);
} else {
MethodDefinition methodDefinition = new MethodDefinition(this, method, methodImpl);
methodDefinition.writeTo(methodWriter);
}
}
}
use of org.jf.dexlib2.iface.Method in project android-classyshark by google.
the class SyntheticAccessorsInspector method getSyntheticAccessors.
public List<String> getSyntheticAccessors() {
LinkedList<String> result = new LinkedList<>();
Set<? extends ClassDef> allClasses = dxFile.getClasses();
for (ClassDef classDef : allClasses) {
Iterator<? extends Method> allMethodsIter = classDef.getMethods().iterator();
while (allMethodsIter.hasNext()) {
Method element = allMethodsIter.next();
String name = element.getName();
String nClassName = classDef.getType();
if (name.contains("access$")) {
String cleanClassName = DexlibAdapter.getClassStringFromDex(nClassName);
if (!result.contains(cleanClassName)) {
result.add(cleanClassName);
}
}
}
}
return result;
}
use of org.jf.dexlib2.iface.Method in project android-classyshark by google.
the class MetaObjectDex method getDeclaredMethods.
@Override
public MethodInfo[] getDeclaredMethods() {
Iterable<? extends Method> implMethods = classDef.getMethods();
List<MethodInfo> result = new ArrayList<>();
for (Method method : implMethods) {
if (!isConstructor(method)) {
MethodInfo mi = new MethodInfo();
mi.parameterTypes = convertParameters(method.getParameters());
mi.annotations = convertAnnotations(method.getAnnotations());
mi.modifiers = method.getAccessFlags();
mi.name = method.getName();
mi.exceptionTypes = new ExceptionInfo[0];
mi.returnType = DexlibAdapter.getTypeName(method.getReturnType());
result.add(mi);
}
}
MethodInfo[] array = new MethodInfo[result.size()];
return result.toArray(array);
}
use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class DexCompareUtils method equalsInstruction.
/**
* 比较method重的tryBlock块
*
* @param a
* @param b
* @return
*/
private static boolean equalsInstruction(List<Instruction> a, List<Instruction> b) {
if (a.size() != b.size()) {
return false;
}
Instruction at, bt;
for (int i = 0; i < a.size(); i++) {
at = a.get(i);
bt = b.get(i);
if (!at.getOpcode().equals(bt.getOpcode()) || !(at.getCodeUnits() == bt.getCodeUnits())) {
return false;
}
}
return true;
}
use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class DexDiffInfo method writeToFile.
public void writeToFile(String bundleName, File diffFile, File diffJsonFile) throws IOException {
JSONArray jsonArray = new JSONArray();
if (diffJsonFile.exists()) {
String content = FileUtils.readFileToString(diffJsonFile);
jsonArray = JSONArray.parseArray(content);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("bundleName", bundleName);
if (addedMethods.size() > 0) {
List<String> addMethods = new ArrayList<String>();
List<MethodDiffInfoObject> diffInfoObjects = new ArrayList<MethodDiffInfoObject>();
for (DexBackedMethod method : addedMethods) {
addMethods.add("[add new Method:]" + method.getReturnType() + " " + method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ") in Class:" + method.getDefiningClass());
MethodDiffInfoObject diffInfoObject = new MethodDiffInfoObject();
diffInfoObject.setDiffType(DiffType.ADD);
diffInfoObject.setReturnType(method.getReturnType());
diffInfoObject.setMethodDeclaration(method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ")");
diffInfoObject.setInClass(method.getDefiningClass());
diffInfoObjects.add(diffInfoObject);
}
FileUtils.writeLines(diffFile, addMethods, true);
jsonObject.put("addedMethods", diffInfoObjects);
}
if (modifiedMethods.size() > 0) {
List<String> modifyMethods = new ArrayList<String>();
List<MethodDiffInfoObject> diffInfoObjects = new ArrayList<MethodDiffInfoObject>();
for (DexBackedMethod method : modifiedMethods) {
modifyMethods.add("[modify Method:]" + method.getReturnType() + " " + method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ") in Class:" + method.getDefiningClass());
MethodDiffInfoObject diffInfoObject = new MethodDiffInfoObject();
diffInfoObject.setDiffType(DiffType.MODIFY);
diffInfoObject.setReturnType(method.getReturnType());
diffInfoObject.setMethodDeclaration(method.getName() + "(" + Formater.formatStringList(method.getParameterTypes()) + ")");
diffInfoObject.setInClass(method.getDefiningClass());
diffInfoObjects.add(diffInfoObject);
}
FileUtils.writeLines(diffFile, modifyMethods, true);
jsonObject.put("modifiedMethods", diffInfoObjects);
}
jsonArray.add(jsonObject);
FileUtils.writeStringToFile(diffJsonFile, JSON.toJSONString(jsonArray));
}
Aggregations