Corrupted Dex file created using simple reader-writer chain
Hi,
I'm trying to read a dex file and write it back without any modifications.
My code is very simple, as follows:
File dexFile = new File("classes.dex");
ApplicationReader ar = new ApplicationReader(Opcodes.ASM4, dexFile);
ApplicationWriter awr = new ApplicationWriter(ar);
ar.accept(awr, 0);
FileOutputStream fos = new FileOutputStream("classes-mod.dex");
fos.write(awr.toByteArray());
fos.close();
However, the newly created dex file seems to be corrupted. When I run
dexdump, I get the following output:
Processing 'classes-mod.dex'...
E/dalvikvm( 4072): Invalid annotations_directory_item
E/dalvikvm( 4072): Trouble with item 332 @ offset 0x5d090
E/dalvikvm( 4072): Cross-item verify of section type 0006 failed
E/dalvikvm( 4072): ERROR: Byte swap + verify failed
ERROR: Failed structural verification of 'classes-mod.dex'
Also running baksmali produces errors.
Attached is the original dex file.
I also tried creating the ApplicationWriter without passing it the
ApplicationReader in the constructor, but the result was the same.
I apologize in advance - I'm a newbie using asmdex, perhaps I'm doing
something wrong...
Thanks!
Ariel