Open woxin123 opened 3 months ago
i have the same problem do you finded any solation?
Could you add a minimal example of how you're using the DexWriter api where this issue reproduces?
@melcz I can reproduce but creating a minimal reproducible setup in my case is difficult. In short, it should be reproducible when reading and writing the DEX files of YouTube. You may install it on an emulator which does not have Google services after debug signing it.
Suppressed: java.io.IOException: Failed to open dex files from
/data/app/~~c9nURA4iZl9uCXlGO1vVkw==/com.google.android.youtube-s_uOp52RcMZhFI2YJnjZ7Q==/base.apk because:
Failure to verify dex file '/data/app/~~c9nURA4iZl9uCXlGO1vVkw==/com.google.android.youtube-
s_uOp52RcMZhFI2YJnjZ7Q==/base.apk': Bad index for debug_info_item parameter_name: b45b0c2 >= a1da
@melcz Rewrite debugItems can reproduce this issue.
val dexFile = DexFileFactory.loadDexFile(dex, Opcodes.forApi(21))
val reWriter = DexRewriter(object : RewriterModule() {
override fun getClassDefRewriter(rewriters: Rewriters): Rewriter<ClassDef> =
Rewriter<ClassDef> { classDef ->
val directMethods = mutableListOf<ImmutableMethod>()
val virtualMethods = mutableListOf<ImmutableMethod>()
classDef.directMethods.forEach { method ->
val immutableMethod = ImmutableMethod(
method.definingClass,
method.name,
method.parameters,
method.returnType,
method.accessFlags,
method.annotations,
method.hiddenApiRestrictions,
optiMethodDebugItem(method)
)
directMethods.add(immutableMethod)
}
classDef.virtualMethods.forEach { method ->
val immutableMethod = ImmutableMethod(
method.definingClass,
method.name,
method.parameters,
method.returnType,
method.accessFlags,
method.annotations,
method.hiddenApiRestrictions,
optiMethodDebugItem(method)
)
virtualMethods.add(immutableMethod)
}
return@Rewriter ImmutableClassDef(
classDef.type,
classDef.accessFlags,
classDef.superclass,
classDef.interfaces,
null,
classDef.annotations,
classDef.staticFields,
classDef.instanceFields,
directMethods,
virtualMethods
)
}
})
val newDexFile = reWriter.dexFileRewriter.rewrite(dexFile)
DexFileFactory.writeDexFile(dex.absolutePath, newDexFile)
private fun optiMethodDebugItem(
method: Method,
debugItemInsSizeStatic: MutableList<Int>,
dump: DebugItemDump,
): ImmutableMethodImplementation? {
val implementation = method.implementation ?: return nul
return ImmutableMethodImplementation(
implementation.registerCount,
implementation.instructions,
implementation.tryBlocks,
getNewDebugItem(method)
)
}
private fun getNewDebugItem(
method: Method,
): List<DebugItem>? {
// ...
return method.implementation?.debugItems?.toList()
}
Could you add a minimal example of how you're using the DexWriter api where this issue reproduces?
i use dex pool , but i fixed the problem
Please test with a build off the rewriter branch: https://github.com/google/smali/tree/rewriter
reason is:
The parameterNames type is is TransformedIterator.
It can be used only once.