Mercurial > paraspace
changeset 155:6570b15d12d4 tip
Fix _DEX_ProtoId.__cmp__() with correct logic rules
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Aug 2011 09:27:22 +0800 |
parents | c659b8c7d6cb |
children | |
files | data/suffile.dex paraspace/dexfile.py paraspace/tests/injection_test.py |
diffstat | 3 files changed, 61 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/paraspace/dexfile.py Wed Aug 17 08:36:33 2011 +0800 +++ b/paraspace/dexfile.py Wed Aug 17 09:27:22 2011 +0800 @@ -1160,10 +1160,13 @@ r = cmp(self.returnTypeIdx, other.returnTypeIdx) if r != 0: return r - if not self.parametersOffRef.is_true: - return -1 - if not other.parametersOffRef.is_true: - return 1 + if not (self.parametersOffRef.is_true and + other.parametersOffRef.is_true): + if self.parametersOffRef.is_true: + return 1 + if other.parametersOffRef.is_true: + return -1 + return 0 tlist0 = self.parametersOffRef.value.typeItems.items tlist1 = other.parametersOffRef.value.typeItems.items
--- a/paraspace/tests/injection_test.py Wed Aug 17 08:36:33 2011 +0800 +++ b/paraspace/tests/injection_test.py Wed Aug 17 09:27:22 2011 +0800 @@ -551,6 +551,60 @@ pass pass + +## \brief Test case for protoid out of order. +# +# Dalvik complaints that output of inject_redir() is out-of-order in +# DEXFile.protoIds list. +# \pre +# E/dalvikvm( 294): Out-of-order proto_id arguments +# E/dalvikvm( 294): Trouble with item 6 @ offset 0x2bc +# E/dalvikvm( 294): Cross-item verify of section type 0003 failed +# E/dalvikvm( 294): ERROR: Byte swap + verify failed +# +# The _DEX_ProtoId.__cmp__() does not define the order well. +# It was fixed with correct logic rules. +# +def proto_id_order_verify_1_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, 'suffile.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) + + pairs = map(None, hello_linked.protoIds.items[:-1], + hello_linked.protoIds.items[1:]) + for idx, (protoid0, protoid1) in enumerate(pairs): + try: + assert cmp(protoid1, protoid0) > 0 + except: + print 'ERROR: protoid %d is out of order' % (idx + 1) + raise + pass + pass + + ## \brief Test case for issue of bad offset list in _DEX_AnnotationSetItem. # # Values of _DEX_AnnotationSetItem.annotationOffs is corrupted after