3

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.

Jasurbek
  • 2,946
  • 3
  • 20
  • 37
李启初
  • 31
  • 1
  • Open it as raw text, and decode the bytes a little bit. You may eventually begin to see that dex byte code is just a tad different from java's .class byte code – Joe Jun 23 '19 at 07:04

1 Answers1

2

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.

JesusFreke
  • 19,784
  • 5
  • 65
  • 68