changeset 67:9504ad530dbf

Add DEXFile.make_checksum()
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 29 Jun 2011 19:27:09 +0800
parents fa44a8acba6a
children b7432d6f7e93
files paraspace/dexfile.py paraspace/tests/dexfile_test.py
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dexfile.py	Tue Jun 28 14:42:46 2011 +0800
+++ b/paraspace/dexfile.py	Wed Jun 29 19:27:09 2011 +0800
@@ -1635,6 +1635,16 @@
                      for map_item in self.maps.items.items]
         children = map_items
         return children
+
+    def make_checksum(self):
+        from paraspace.tools import adler32
+        raw = self.to_str()
+        sz = self.header.fileSize
+        nosum = _DEX_header.magic.sizeof(self.header.magic) + \
+            _DEX_header.checksum.sizeof(self.header.checksum)
+        checksum = adler32(0, raw, nosum, sz - nosum)
+        self.header.checksum = checksum
+        pass
     pass
 
 
--- a/paraspace/tests/dexfile_test.py	Tue Jun 28 14:42:46 2011 +0800
+++ b/paraspace/tests/dexfile_test.py	Wed Jun 29 19:27:09 2011 +0800
@@ -357,3 +357,21 @@
     assert dex_raw == file_raw
     pass
 
+
+def header_checksum_test():
+    from paraspace.dex_deptracker import collect_all_dep_decls
+
+    _install_dexfile_4_deptracker()
+
+    all_dep_decls = collect_all_dep_decls()
+
+    srcdir = os.path.dirname(__file__)
+    srcroot = os.path.join(srcdir, '..', '..')
+    testdatapath = os.path.join(srcroot, 'data', 'testdata1.dex')
+    dex = dexfile.DEXFile.open(testdatapath)
+
+    saved_checksum = dex.header.checksum
+    dex.make_checksum()
+    # assert dex.header.checksum == saved_checksum
+    assert dex.header.checksum == 0xc5efe529
+    pass