hosijyun / smali

Automatically exported from code.google.com/p/smali
0 stars 0 forks source link

Why the dex file changed? #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a little question. When I used baksmali to decompile the dex and then 
used smali recompile it (didn't do any modification on the smali). Then I found 
the new dex changed a lot than the original one. I compared them used 
UltraCompare and found their dex files are totally different, although the new 
dex file can work very well.

Please tell me why? Thank you!

Original issue reported on code.google.com by zhengmin...@gmail.com on 11 Oct 2011 at 4:19

GoogleCodeExporter commented 9 years ago
The data that the dex file represents should be exactly the same as the 
original dex file. However, the actual binary representation may be different. 
This is due to a couple of different factors, that, when taken together, 
compound each other to cause significant differences in the dex file.

A dex file is made up of a number of different sections, which contain items of 
a particular type. Some sections are indexed sections, in which the items have 
a consistent size are referred to by an index, and in which the order of the 
items is completely specified. In addition, there are a number of sections 
where the item size is variable, and items within the section are referred to 
by an absolute offset from the start of the file.

One possible difference is that the non-indexed sections may be in any order. 
In addition, the items in these sections may also be in any order typically.

And then, to exacerbate the problem, wherever an item is referenced by an 
absolute offset from the start of the file, this offset is encoded with a 
variable size encoding. So the length of equivalent items in the 2 dex files 
might be different, depending on the number of bytes required to encode the 
absolute offsets that are used in that item.

Original comment by jesusfreke@jesusfreke.com on 11 Oct 2011 at 5:44