JesusFreke / smali

smali/baksmali
6.29k stars 1.07k forks source link

"NfcNci.odex" has no dex files #763

Closed lapwat closed 4 years ago

lapwat commented 4 years ago

I am trying to disassemble NfcNci.apk.

I have adb pull in an empty folder the following files/folders from my phone:

I run the command:

java -jar baksmali-2.4.0.jar x -c arm64/boot.oat  -d arm64/ NfcNci.odex -o NfcNci/

Exception in thread "main" org.jf.dexlib2.DexFileFactory$DexFileNotFoundException: Could not locate the embedded dex file /system/app/NfcNci/NfcNci.apk. Is the vdex file missing?
        at org.jf.dexlib2.dexbacked.OatFile$OatDexEntry.getDexFile(OatFile.java:586)
        at org.jf.dexlib2.dexbacked.OatFile$OatDexEntry.getDexFile(OatFile.java:567)
        at org.jf.baksmali.DexInputCommand.loadDexFile(DexInputCommand.java:158)
        at org.jf.baksmali.DisassembleCommand.run(DisassembleCommand.java:162)
        at org.jf.baksmali.Main.main(Main.java:102)
Caused by: org.jf.dexlib2.dexbacked.DexBackedDexFile$NotADexFile: Not a valid dex magic value: 7f 45 4c 46 02 01 01 03
        at org.jf.dexlib2.util.DexUtil.verifyDexHeader(DexUtil.java:93)
        at org.jf.dexlib2.dexbacked.OatFile$OatDexEntry.getDexFile(OatFile.java:583)
        ... 4 more

I adb pull /system/app/NfcNci/oat/arm64/NfcNci.vdex in the same folder and retry the same command:

java -jar baksmali-2.4.0.jar x -c arm64/boot.oat  -d arm64/ NfcNci.odex -o NfcNci/

Exception in thread "main" java.lang.RuntimeException: "NfcNci.odex" has no dex files
        at org.jf.baksmali.DexInputCommand.loadDexFile(DexInputCommand.java:167)
        at org.jf.baksmali.DisassembleCommand.run(DisassembleCommand.java:162)
        at org.jf.baksmali.Main.main(Main.java:102)

How can I get the smali files from NfcNci.apk ? Which files need to be specified in the command ? Which files are not specified in the command but need to be present in the same folder and accurately named ?

Thank you for your time.

JesusFreke commented 4 years ago

In general, smali expects the files to be in the same relative locations as on the device. The easiest way to ensure this is to just adb pull the entire app folder.

lapwat commented 4 years ago

Thank you for this information, I pulled the NfcNci app folder directly and retried with following configuration.

$ tree --filelimit=10
.
├── NfcNci.apk
├── arm64 [84 entries exceeds filelimit, not opening dir]
├── baksmali-2.4.0.jar
├── lib
│   └── arm64
│       └── libnfc_nci_jni.so
└── oat
    └── arm64
        ├── NfcNci.odex
        └── NfcNci.vdex

Running the command gives me the same exceptions:

$  java -jar baksmali-2.4.0.jar x -c arm64/boot.oat  -d arm64/ oat/arm64/NfcNci.odex -o NfcNci/

Exception in thread "main" java.lang.RuntimeException: "oat/arm64/NfcNci.odex" has no dex files
        at org.jf.baksmali.DexInputCommand.loadDexFile(DexInputCommand.java:167)
        at org.jf.baksmali.DisassembleCommand.run(DisassembleCommand.java:162)
        at org.jf.baksmali.Main.main(Main.java:102)

I am trying to reproduce this behavior of apktool which works great without having to specify any odex/vdex files:

$ apktool if framework-res.apk
$ apktool disassemble NfcNci.apk
...
I: Baksmaling classes.dex...
...
# now I have a NfcNci folder with disassembled smali files
lapwat commented 4 years ago

Found out that I confused deodex (x option) and disassemble (d option).

Still confused about apks that include dex file and others that do not.

Thank you for your time.