zhangwenan / smali

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

Ordering of Encoded Values for Annotations #211

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What seems to be the problem?

When creating a new DEX file with annotations containing encoded values, the 
elements do not seem to be ordered according to their name's index in the 
string table which makes dexopt fail:

04-30 22:31:57.487: E/dalvikvm(8110): Out-of-order encoded_annotation name_idx: 
0x6253 then 0x510f
04-30 22:31:57.487: E/dalvikvm(8110): Trouble with item 947 @ offset 0x20210c
04-30 22:31:57.487: E/dalvikvm(8110): Swap of section type 2004 failed
04-30 22:31:57.487: E/dalvikvm(8110): ERROR: Byte swap + verify failed
04-30 22:31:57.657: E/dalvikvm(8110): Optimization failed

The code is rather simple:

for (...) {
  ImmutableAnnotationElement element = new ImmutableAnnotationElement(ae.getName(), value);
  elements.add(element);
}
ImmutableAnnotation ann = new ImmutableAnnotation(v, clazz, elements);

"elements" is a set, so there is no way to influence the order of the elements. 
It does not matter whether we are dealing with class annotations or field 
annotations, the problem always occurs if there is more than one element for 
the annotation.

What is the exact smali/baksmali command that you ran?

see above for code snippet

What version of smali/baksmali are you using? What rom are you working
from?

compiled declib2-2.0.3-dev.jar from source

What is the airspeed velocity of an unladen swallow?

depends on the swallow, there are eager and lazy ones

Please provide any additional information below: error messages, symptoms,
etc.

This seems to be the same issue as 
http://code.google.com/p/smali/issues/detail?id=158 Is this fixed in dexlib2 as 
well?

The code that fails in dexopt can be found here: 
https://code.google.com/p/android-source-browsing/source/browse/libdex/DexSwapVe
rify.cpp?repo=platform--dalvik&name=android-4.2_r1&r=e8e1ddccd616e8226b7cc1e4e9f
db327429249e8 in line 2322

Original issue reported on code.google.com by MrCod...@googlemail.com on 30 Apr 2014 at 9:10

GoogleCodeExporter commented 9 years ago
Fixed in 
https://code.google.com/p/smali/source/detail?r=5280047b4261f5a6619a7a7b64e2666c
06e107f6

Thanks for reporting this! And sorry for the long delay :)

Original comment by jesusfreke@jesusfreke.com on 16 Jul 2014 at 6:03