Questions about using the smali library

Viewed 251

I have a smali file and I want to know how to convert the smali file into an org.jf.dexlib2.iface.ClassDef object via the smali library.

I have an idea now: The dex file of the smali file will be obtained by the baksmali.disassembleDexFile() a method, and a new DexFile object can be generated to obtain the org.jf.dexlib2.iface.ClassDef object, but if the dex is large enough, it is too expensive.

So ask everyone to help me.

1 Answers

If you have the dex file itself, just use DexFileFactory.loadDexFile("/path/to/dex/file.dex", Opcodes.getDefault());, and then iterate over the classes until you find the ClassDef of the class you're interested in.

If you don't have a dex file, just use smali to assemble the smali file to a dex file first.

Related