# HG changeset patch # User Thinker K.F. Li # Date 1312897925 -28800 # Node ID f31bfe55d9c234e9c778191ab8f574fe9ce0c320 # Parent b488ca519709cbb4f573aad36988bbe5dedad680 Fix issue of corrupted offset list in _DEX_AnnotationSetItem after injection diff -r b488ca519709 -r f31bfe55d9c2 paraspace/dexfile.py --- a/paraspace/dexfile.py Tue Aug 09 21:28:13 2011 +0800 +++ b/paraspace/dexfile.py Tue Aug 09 21:52:05 2011 +0800 @@ -1297,9 +1297,16 @@ pass +class _DEX_AnnotationSetItem_anno_item(composite): + offset = depend_off('_DEX_AnnotationItem')(uint32) + + child_names = ('offset',) + pass + + class _DEX_AnnotationSetItem(composite): size = uint32 - annotationOffs = array('size', depend_off('_DEX_AnnotationItem')(uint32)) + annotationOffs = array('size', _DEX_AnnotationSetItem_anno_item) child_names = 'size annotationOffs'.split() pass diff -r b488ca519709 -r f31bfe55d9c2 paraspace/tests/injection_test.py --- a/paraspace/tests/injection_test.py Tue Aug 09 21:28:13 2011 +0800 +++ b/paraspace/tests/injection_test.py Tue Aug 09 21:52:05 2011 +0800 @@ -543,3 +543,51 @@ raise pass pass + +## \brief Test case for issue of bad offset list in _DEX_AnnotationSetItem. +# +# Values of _DEX_AnnotationSetItem.annotationOffs is corrupted after +# injection. +# \pre +# E/dalvikvm( 300): No data map entry found @ 0xf31; expected 2004 +# E/dalvikvm( 300): Trouble with item 0 @ offset 0x5c0 +# E/dalvikvm( 300): Cross-item verify of section type 1003 failed +# E/dalvikvm( 300): ERROR: Byte swap + verify failed +# E/dalvikvm( 300): Optimization failed +# +# It must be the issue that back_type of an array can not be a \ref depend. +# +def annotation_set_items_verify_test(): + from paraspace.dex_deptracker import prepare_dep_decls + from paraspace.dex_deptracker import dex_sort_sorted_arrays + from paraspace.injection import inject_redir_no_restore + + _install_dexfile_4_deptracker() + + all_dep_decls = prepare_dep_decls() + + srcdir = os.path.dirname(__file__) + datapath = os.path.join(srcdir, '..', '..', 'data') + + fake_path = os.path.join(datapath, 'fakefile.dex') + hello_path = os.path.join(datapath, 'helloworld.dex') + + fake_dex = dexfile.DEXFile.open(fake_path) + fake_linked = dexfile.DEXFile_linked.build_dependencies(fake_dex, + all_dep_decls) + + hello_dex = dexfile.DEXFile.open(hello_path) + hello_linked = dexfile.DEXFile_linked.build_dependencies(hello_dex, + all_dep_decls) + + inject_redir_no_restore(fake_linked, 'Lcom/codemud/fakefile/fakefile;', + hello_linked, 'Ljava/io/File;', all_dep_decls) + + dex_sort_sorted_arrays(hello_linked) + + for setitem in hello_linked.annotationSetItems.items: + for anno in setitem.annotationOffs.items: + assert anno.offset in hello_linked.annotationItems.items + pass + pass + pass