use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class MethodDefinition method writeTo.
public void writeTo(IndentingWriter writer) throws IOException {
int parameterRegisterCount = 0;
if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
parameterRegisterCount++;
}
writer.write(".method ");
writeAccessFlags(writer, method.getAccessFlags());
writer.write(method.getName());
writer.write("(");
for (MethodParameter parameter : methodParameters) {
String type = parameter.getType();
writer.write(type);
parameterRegisterCount++;
if (TypeUtils.isWideType(type)) {
parameterRegisterCount++;
}
}
writer.write(")");
writer.write(method.getReturnType());
writer.write('\n');
writer.indent(4);
if (classDef.options.useLocalsDirective) {
writer.write(".locals ");
int registerCount = methodImpl.getRegisterCount() - parameterRegisterCount;
writer.printSignedIntAsDec(registerCount);
} else {
writer.write(".registers ");
writer.printSignedIntAsDec(methodImpl.getRegisterCount());
}
writer.write('\n');
writeParameters(writer, method, methodParameters, classDef.options);
if (registerFormatter == null) {
registerFormatter = new RegisterFormatter(classDef.options, methodImpl.getRegisterCount(), parameterRegisterCount);
}
String containingClass = null;
if (classDef.options.useImplicitReferences) {
containingClass = method.getDefiningClass();
}
//如果是修改的方法,需要添加ReplaceAnnotation
if (DexDiffInfo.modifiedMethods.contains(method)) {
MethodReplaceAnnotation replaceAnnotation = new MethodReplaceAnnotation(method.getDefiningClass(), method.getName());
AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass, replaceAnnotation);
} else {
AnnotationFormatter.writeTo(writer, method.getAnnotations(), containingClass);
}
writer.write('\n');
boolean first = true;
boolean writeCheckCast = false;
List<MethodItem> methodItems = getMethodItems();
for (MethodItem methodItem : methodItems) {
if (first && APatchTool.isApatch) {
first = false;
if (!fullMethod && !(methodItem instanceof EndPrologueMethodItem) && !DexDiffInfo.addedClasses.contains(classDef.getClassDef())) {
if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
writer.write("check-cast p0, " + method.getDefiningClass());
writer.write('\n');
writeCheckCast = true;
}
}
}
if (methodItem.writeTo(writer)) {
writer.write('\n');
}
if (!writeCheckCast && !fullMethod && APatchTool.isApatch && !DexDiffInfo.addedClasses.contains(classDef.getClassDef())) {
if (!AccessFlags.STATIC.isSet(method.getAccessFlags())) {
if (methodItem instanceof EndPrologueMethodItem) {
writer.write("check-cast p0, " + method.getDefiningClass());
writer.write('\n');
writeCheckCast = true;
}
}
}
}
writer.deindent(4);
writer.write(".end method\n");
}
use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class MethodReIClassDef method reMethod.
@Override
public Method reMethod(Method method) {
String newType = null;
boolean isBasic = false;
boolean isInit = false;
String methodName = method.getName();
if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
isInit = true;
}
String returnType = method.getReturnType();
if (basicType.containsKey(returnType)) {
newType = returnType;
isBasic = true;
} else {
newType = classProcessor.classProcess(DefineUtils.getDalvikClassName(returnType)).className;
}
MethodImplementation methodImplementation = method.getImplementation();
List<? extends MethodParameter> paramters = method.getParameters();
String[] argsOringn = new String[paramters.size()];
String[] args = new String[paramters.size()];
for (int i = 0; i < paramters.size(); i++) {
//型参数不混淆
if (basicType.containsKey(paramters.get(i).getType())) {
argsOringn[i] = basicType.get(paramters.get(i).getType());
args[i] = argsOringn[i];
continue;
}
argsOringn[i] = DefineUtils.getDalvikClassName(paramters.get(i).getType());
args[i] = classProcessor.classProcess(DefineUtils.getDalvikClassName(paramters.get(i).getType())).className;
}
String type = method.getReturnType();
return new ImmutableMethod(reType, classProcessor.methodProcess(isInit ? methodName : DefineUtils.getDalvikClassName(method.getDefiningClass()), methodName, isBasic ? basicType.get(returnType) : DefineUtils.getDalvikClassName(returnType), StringUtils.join(argsOringn, ",")).methodName, reParameters(paramters), isBasic ? newType : DefineUtils.getDefineClassName(newType, type.startsWith("[")), method.getAccessFlags(), getAnnotation(method.getAnnotations()), reMethodImpl(methodImplementation));
}
use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class AbIClassDef method reClassDef.
@Override
public ClassDef reClassDef(ClassDef classDef) {
Iterable<? extends Method> methods = classDef.getMethods();
LinkedHashSet<Method> newMethods = new LinkedHashSet<Method>();
Iterable<? extends Field> fields = classDef.getFields();
LinkedHashSet<Field> newFields = new LinkedHashSet<Field>();
Set<? extends Annotation> annotations = classDef.getAnnotations();
Set<String> interfaces = classDef.getInterfaces();
Set<String> newInterfaces = new HashSet<String>();
Set<Annotation> immutableAnnotations = new HashSet<Annotation>();
String type = classDef.getType();
reType = reType(type);
String superClass = classDef.getSuperclass();
for (String inter : interfaces) {
newInterfaces.add(reInterface(inter));
}
String reSuperClass = reSuperClass(superClass);
for (Annotation annotation : annotations) {
if (type.startsWith("Landroid/taobao/atlas/bundleInfo/AtlasBundleInfoManager;")) {
System.out.println("xxxx");
}
immutableAnnotations.add(reAnnotation(annotation));
}
for (Field field : fields) {
newFields.add(reField(field));
}
for (Method method : methods) {
if (method.getName().equals("<cinit>") || method.getName().equals("<init>")) {
newMethods.add(reMethod(method));
continue;
}
// if (method.getName().equals("getArchiveFile")) {
newMethods.add(reMethod(method));
// }
}
return new ImmutableClassDef(reType, classDef.getAccessFlags(), reSuperClass, newInterfaces, classDef.getSourceFile(), immutableAnnotations, newFields, newMethods);
}
use of org.jf.dexlib2.iface.Method in project atlas by alibaba.
the class DexCompareUtils method equalTryBlocks.
/**
* 比较method重的tryBlock块
*
* @param a
* @param b
* @return
*/
private static boolean equalTryBlocks(List<? extends DexBackedTryBlock> a, List<? extends DexBackedTryBlock> b) {
if (a.size() != b.size()) {
return false;
}
DexBackedTryBlock at, bt;
for (int i = 0; i < a.size(); i++) {
at = a.get(i);
bt = b.get(i);
if (!at.equals(bt)) {
return false;
}
}
return true;
}
use of org.jf.dexlib2.iface.Method in project android-classyshark by google.
the class MetaObjectDex method getDeclaredConstructors.
@Override
public ConstructorInfo[] getDeclaredConstructors() {
Iterable<? extends Method> implConstructors = classDef.getMethods();
List<ConstructorInfo> result = new ArrayList<>();
for (Method constructor : implConstructors) {
if (isConstructor(constructor)) {
ConstructorInfo ci = new ConstructorInfo();
ci.parameterTypes = convertParameters(constructor.getParameters());
ci.annotations = convertAnnotations(constructor.getAnnotations());
ci.modifiers = constructor.getAccessFlags();
result.add(ci);
}
}
ConstructorInfo[] array = new ConstructorInfo[result.size()];
return result.toArray(array);
}
Aggregations