use of org.jf.dexlib2.iface.MethodParameter in project atlas by alibaba.
the class MethodDefinition method writeParameters.
private static void writeParameters(IndentingWriter writer, Method method, List<? extends MethodParameter> parameters, baksmaliOptions options) throws IOException {
boolean isStatic = AccessFlags.STATIC.isSet(method.getAccessFlags());
int registerNumber = isStatic ? 0 : 1;
for (MethodParameter parameter : parameters) {
String parameterType = parameter.getType();
String parameterName = parameter.getName();
Collection<? extends Annotation> annotations = parameter.getAnnotations();
if (parameterName != null || annotations.size() != 0) {
writer.write(".param p");
writer.printSignedIntAsDec(registerNumber);
if (parameterName != null && options.outputDebugInfo) {
writer.write(", ");
ReferenceFormatter.writeStringReference(writer, parameterName);
}
writer.write(" # ");
writer.write(parameterType);
writer.write("\n");
if (annotations.size() > 0) {
writer.indent(4);
String containingClass = null;
if (options.useImplicitReferences) {
containingClass = method.getDefiningClass();
}
AnnotationFormatter.writeTo(writer, annotations, containingClass);
writer.deindent(4);
writer.write(".end param\n");
}
}
registerNumber++;
if (TypeUtils.isWideType(parameterType)) {
registerNumber++;
}
}
}
use of org.jf.dexlib2.iface.MethodParameter 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;
boolean changeOpcode = false;
String methodName = method.getName();
String returnType = method.getReturnType();
MethodImplementation methodImplementation = method.getImplementation();
List<? extends MethodParameter> paramters = method.getParameters();
if (methodName.equals("<init>") || methodName.equals("<cinit>")) {
isInit = true;
}
if (basicType.containsKey(returnType)) {
newType = returnType;
isBasic = true;
} else {
newType = classProcessor.classProcess(DefineUtils.getDalvikClassName(returnType)).className;
}
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.MethodParameter in project atlas by alibaba.
the class MethodImplReIClassDef method reParameters.
@Override
protected Iterable<? extends MethodParameter> reParameters(final List<? extends MethodParameter> paramters) {
final List<ImmutableMethodParameter> list = new ArrayList<ImmutableMethodParameter>();
for (MethodParameter methodParameter : paramters) {
boolean isBasic = false;
if (basicType.containsKey(methodParameter.getType())) {
isBasic = true;
}
list.add(new ImmutableMethodParameter(isBasic ? methodParameter.getType() : DefineUtils.getDefineClassName(classProcessor.classProcess(DefineUtils.getDalvikClassName(methodParameter.getType())).className, methodParameter.getType().startsWith("[")), methodParameter.getAnnotations(), methodParameter.getName()));
}
return new Iterable<ImmutableMethodParameter>() {
@Override
public Iterator<ImmutableMethodParameter> iterator() {
return list.iterator();
}
};
}
use of org.jf.dexlib2.iface.MethodParameter in project smali by JesusFreke.
the class ClassPool method intern.
public void intern(@Nonnull ClassDef classDef) {
PoolClassDef poolClassDef = new PoolClassDef(classDef);
PoolClassDef prev = internedItems.put(poolClassDef.getType(), poolClassDef);
if (prev != null) {
throw new ExceptionWithContext("Class %s has already been interned", poolClassDef.getType());
}
dexPool.typeSection.intern(poolClassDef.getType());
dexPool.typeSection.internNullable(poolClassDef.getSuperclass());
dexPool.typeListSection.intern(poolClassDef.getInterfaces());
dexPool.stringSection.internNullable(poolClassDef.getSourceFile());
HashSet<String> fields = new HashSet<String>();
for (Field field : poolClassDef.getFields()) {
String fieldDescriptor = DexFormatter.INSTANCE.getShortFieldDescriptor(field);
if (!fields.add(fieldDescriptor)) {
throw new ExceptionWithContext("Multiple definitions for field %s->%s", poolClassDef.getType(), fieldDescriptor);
}
dexPool.fieldSection.intern(field);
EncodedValue initialValue = field.getInitialValue();
if (initialValue != null) {
dexPool.internEncodedValue(initialValue);
}
dexPool.annotationSetSection.intern(field.getAnnotations());
ArrayEncodedValue staticInitializers = getStaticInitializers(poolClassDef);
if (staticInitializers != null) {
dexPool.encodedArraySection.intern(staticInitializers);
}
}
HashSet<String> methods = new HashSet<String>();
for (PoolMethod method : poolClassDef.getMethods()) {
String methodDescriptor = DexFormatter.INSTANCE.getShortMethodDescriptor(method);
if (!methods.add(methodDescriptor)) {
throw new ExceptionWithContext("Multiple definitions for method %s->%s", poolClassDef.getType(), methodDescriptor);
}
dexPool.methodSection.intern(method);
internCode(method);
internDebug(method);
dexPool.annotationSetSection.intern(method.getAnnotations());
for (MethodParameter parameter : method.getParameters()) {
dexPool.annotationSetSection.intern(parameter.getAnnotations());
}
}
dexPool.annotationSetSection.intern(poolClassDef.getAnnotations());
}
use of org.jf.dexlib2.iface.MethodParameter in project smali by JesusFreke.
the class RollbackTest method testRollback.
@Test
public void testRollback() throws IOException {
ClassDef class1 = new ImmutableClassDef("Lcls1;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls1;", "field1", "I", AccessFlags.PUBLIC.getValue(), null, null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls1;", "method1", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("I", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, null)));
ClassDef class2 = new ImmutableClassDef("Lcls2;", AccessFlags.PUBLIC.getValue(), "Ljava/lang/Object;", null, null, Lists.newArrayList(new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lannotation2;", null)), Lists.<Field>newArrayList(new ImmutableField("Lcls2;", "field2", "D", AccessFlags.PUBLIC.getValue(), null, null, null)), Lists.<Method>newArrayList(new ImmutableMethod("Lcls2;", "method2", Lists.<MethodParameter>newArrayList(new ImmutableMethodParameter("D", null, null)), "V", AccessFlags.PUBLIC.getValue(), null, null, null)));
DexBackedDexFile dexFile1;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.mark();
dexPool.internClass(class2);
dexPool.reset();
dexPool.writeTo(dataStore);
dexFile1 = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
}
DexBackedDexFile dexFile2;
{
MemoryDataStore dataStore = new MemoryDataStore();
DexPool dexPool = new DexPool(Opcodes.getDefault());
dexPool.internClass(class1);
dexPool.writeTo(dataStore);
dexFile2 = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer());
}
List<MapItem> mapItems1 = dexFile1.getMapItems();
List<MapItem> mapItems2 = dexFile2.getMapItems();
for (int i = 0; i < mapItems1.size(); i++) {
Assert.assertEquals(mapItems1.get(i).getType(), mapItems2.get(i).getType());
Assert.assertEquals(mapItems1.get(i).getItemCount(), mapItems2.get(i).getItemCount());
}
}
Aggregations