Undo dex2dex compilation before invoking LoadHook
We need to undo any dex_to_dex compilation that might have taken place
before passing a dex file to any registered ClassFileLoadHooks to
ensure that no internal opcodes are present in any methods.
Test: ./test.py --host -j40
Bug: 36653594
Change-Id: Ia42c77312e685d69f6b3ea764fad01710b10ab45
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index 35e9d5d..85100ae 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -23,6 +23,7 @@
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <zlib.h>
#include <memory>
#include <sstream>
@@ -67,6 +68,12 @@
{'0', '3', '8', '\0'}
};
+uint32_t DexFile::CalculateChecksum() const {
+ const uint32_t non_sum = OFFSETOF_MEMBER(DexFile::Header, signature_);
+ const uint8_t* non_sum_ptr = Begin() + non_sum;
+ return adler32(adler32(0L, Z_NULL, 0), non_sum_ptr, Size() - non_sum);
+}
+
struct DexFile::AnnotationValue {
JValue value_;
uint8_t type_;