我正在尝试使用ASM ClassRemapper将所有类从已编译的.jar重命名为新名称几乎一切正常,我的应用程序正常运行,直到它与ClassCastException
或AbstractMethodError
崩溃
ClassRemapper adapter = new ClassRemapper(classWriter, new Remapper()
{
@Override
public String mapType(String s)
{
return super.mapType(getNewName(s));
}
@Override
public String mapFieldName(String owner, String name, String descriptor)
{
Type type = Type.getType(descriptor);
descriptor = descriptor.replace(type.getClassName(), getNewName(type.getClassName()));
return super.mapFieldName(getNewName(owner), name, descriptor);
}
@Override
public String map(String internalName)
{
return getNewName(internalName);
}
@Override
public String mapDesc(String descriptor)
{
Type type = Type.getType(descriptor);
descriptor = descriptor.replace(type.getClassName(), getNewName(type.getClassName()));
return super.mapDesc(descriptor);
}
@Override
public String mapMethodDesc(String methodDescriptor)
{
Type methodType = Type.getMethodType(methodDescriptor);
List<Type> types = new LinkedList<>();
for (Type argumentType : methodType.getArgumentTypes())
types.add(Type.getType(argumentType.getDescriptor().replace(argumentType.getClassName(), getNewName(argumentType.getClassName()))));
Type returnType = Type.getReturnType(methodDescriptor);
returnType = Type.getReturnType("()" + returnType.getDescriptor().replace(returnType.getClassName(), getNewName(returnType.getClassName())));
return super.mapMethodDesc(Type.getMethodDescriptor(returnType, types.toArray(new Type[0])));
}
});
我想我在方法中缺少一些东西,但我找不到什么。
getNewName(string)
基本上是map.getOrDefault(string, string);