testwhat / SmaliEx

A wrapper to get de-optimized dex from odex/oat/vdex.
529 stars 142 forks source link

[Android API 24] Unusual output during oat2dex conversion and error during dex2jar conversion #37

Closed kasptom closed 8 years ago

kasptom commented 8 years ago

I was trying to extract from the emulator dex files from files in (interchangeably):

I've pulled them from the device and then tried to convert boot directory --> .dex using command, e.g: [...]$ java -jar ../oat2dex.jar boot x86_64

I've got x86_64-odex and x86_64-dex directories but CLI output suggests that it did not succeed in 100%. From one of the dex files in *-odex I wanted to get .jar so I've used dex2jar tool. [...]$ sh ../dex2jar-2.0/d2j-dex2jar.sh -d toconvert.dex > output_dex2jar.txt result:

dex2jar toconvert.dex -> ./toconvert-dex2jar.jar
com.googlecode.d2j.DexException: not support version.
 at com.googlecode.d2j.reader.DexFileReader.<init>(DexFileReader.java:151)
 at com.googlecode.d2j.reader.DexFileReader.<init>(DexFileReader.java:211)
 at com.googlecode.dex2jar.tools.Dex2jarCmd.doCommandLine(Dex2jarCmd.java:104)
 at com.googlecode.dex2jar.tools.BaseCmd.doMain(BaseCmd.java:288)
 at com.googlecode.dex2jar.tools.Dex2jarCmd.main(Dex2jarCmd.java:32)

Above method works for emulators with API 23 but NOT for API 24 I attach output from: java -jar ../oat2dex.jar boot x86_64 command_output.txt

Using release version of oat2dex did not succeed at all, so -like it is written in #19- I've obtained oat2dex from sources.

36

EDIT: Emulator that I've used: emulator_details.txt

imknown commented 8 years ago

All operations are doing under Microsoft Windows 10:

  1. Create the folder named 'TryDeodex'(full address may like D:\TryDeodex),
    then put the self-compiled jar oat2dex.jar into the folder.
    Here is what you said and what I checked out: #36
  2. I copied the folder /system/framework/
    from system.img of Nexus 5X Android 7 DP5 offcial ROM
    to the folder TryDeodex,
    and I think you pulled them from virtual or real device exist filesystem maybe okay too;
  3. Open terminal and cd /D D:\TryDeodex;
  4. I used command as:
    java -jar oat2dex.jar boot system\framework\arm64
    to generate
    system\framework\arm64-odex (full is D:\TryDeodex\system\framework\arm64-odex);
  5. Get the odex file such as xxx.odex, which is extracted from ROM or pulled from virual or real device via adb;
  6. Put the file xxx.odex in the directory of 'D:\TryDeodex' noticed above;
  7. Try the command:
    java -jar oat2dex.jar xxx.odex system\framework\arm64-odex,
    then you will get xxx.dex;
  8. Finally use dex2jar to get xxx.jar file, then try to decompile xxx.jar.
    However, I usually use GUI tools like bytecode-viewer on Github
    to view java source code from xxx.jar directly (bytecode-viewer auto decompiles xxx.jar).

I hope these will help you get the source codes. :ghost:

kasptom commented 8 years ago

Thanks I will try it and give a feedback if it worked :smiley:

kasptom commented 8 years ago

Unfortunately above method does not work for me. After running oat2dex command on Windows 10 I get output that is similar to https://github.com/testwhat/SmaliEx/files/419850/command_output.txt. I found an image by googling "Nexus 5X Android 7 DP5 offcial ROM" but after extracting the archive I had to use also:

I found on the mounted system.ext4.img image the directory: system\framework\arm64 and got from it arm64-odex using the above oat2dex command

I don't have xxx.odex file. To be precise - file that I want to extract is framework-classes2.dex which is in the generated arm64-odex. On API 23 I just have to use:

Has the method changed for API 24 images?

@imknown could You send me the link to the exact ROM that You've been using? Using my image I had problem to open system.img file (I had to convert it as I've described above) What tools do You use to extract and mount system.img from archives?

imknown commented 8 years ago

@kasptom Hi, I use ROM Zhushou to extract google offical system.img on Windows. This tool is easy-to-use and noob-friendly for me. :laughing:

kasptom commented 8 years ago

Thanks. I will have the possibility to try it for about 10 hours because then I will get to the PC with Windows :)

testwhat commented 8 years ago

About dex2jar, try this https://github.com/testwhat/dex2jar/releases/tag/snapshot

kasptom commented 8 years ago

@testwhat thanks - it works better but opening it with jd-gui fails for some classes, e.g TextView.class I've got framework-classes2-dex2jar.jar. Command generates also .zip file with an error report framework-classes2-error.zip zipped framework-classes2-dex2jar

kasptom commented 8 years ago

@testwhat @imknown thanks for your help. I've managed to get to the sources that I wanted :smile: As you suggested - I've used:

bursoft-git commented 8 years ago

I use Batch Apktool for proper deodexing, just put all files to _system folder and type 01 for deodexing Full log and symlinks are stored in log_deodex.txt (symlinks from Rom Helper will support in Batch Apktool 3.6.1) For updating oat2dex.jar just put latest version to BIN folder

4PDA forum http://4pda.ru/forum/index.php?showtopic=557858 Direct download link https://yadi.sk/d/h0kXdksftzdbf