jeffhao | 10037c8 | 2012-01-23 15:06:23 -0800 | [diff] [blame^] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_DEX_FILE_VERIFIER_H_ |
| 4 | #define ART_SRC_DEX_FILE_VERIFIER_H_ |
| 5 | |
| 6 | #include <map> |
| 7 | |
| 8 | #include "dex_file.h" |
| 9 | |
| 10 | namespace art { |
| 11 | |
| 12 | class DexFileVerifier { |
| 13 | public: |
| 14 | static bool Verify(DexFile* dex_file, const byte* base, size_t length); |
| 15 | |
| 16 | private: |
| 17 | DexFileVerifier(DexFile* dex_file, const byte* base, size_t length) |
| 18 | : dex_file_(dex_file), base_(base), length_(length), |
| 19 | header_(&dex_file->GetHeader()), ptr_(NULL), previous_item_(NULL) { |
| 20 | } |
| 21 | |
| 22 | bool Verify(); |
| 23 | |
| 24 | bool CheckPointerRange(const void* start, const void* end, const char* label) const; |
| 25 | bool CheckListSize(const void* start, uint32_t count, uint32_t element_size, const char* label) const; |
| 26 | bool CheckIndex(uint32_t field, uint32_t limit, const char* label) const; |
| 27 | |
| 28 | bool CheckHeader() const; |
| 29 | bool CheckMap() const; |
| 30 | |
| 31 | uint32_t ReadUnsignedLittleEndian(uint32_t size); |
| 32 | bool CheckAndGetHandlerOffsets(const DexFile::CodeItem* code_item, |
| 33 | uint32_t* handler_offsets, uint32_t handlers_size); |
| 34 | bool CheckClassDataItemField(uint32_t idx, uint32_t access_flags, bool expect_static) const; |
| 35 | bool CheckClassDataItemMethod(uint32_t idx, uint32_t access_flags, uint32_t code_offset, |
| 36 | bool expect_direct) const; |
| 37 | bool CheckPadding(uint32_t offset, uint32_t aligned_offset); |
| 38 | bool CheckEncodedValue(); |
| 39 | bool CheckEncodedArray(); |
| 40 | bool CheckEncodedAnnotation(); |
| 41 | |
| 42 | bool CheckIntraClassDataItem(); |
| 43 | bool CheckIntraCodeItem(); |
| 44 | bool CheckIntraStringDataItem(); |
| 45 | bool CheckIntraDebugInfoItem(); |
| 46 | bool CheckIntraAnnotationItem(); |
| 47 | bool CheckIntraAnnotationsDirectoryItem(); |
| 48 | |
| 49 | bool CheckIntraSectionIterate(uint32_t offset, uint32_t count, uint16_t type); |
| 50 | bool CheckIntraIdSection(uint32_t offset, uint32_t count, uint16_t type); |
| 51 | bool CheckIntraDataSection(uint32_t offset, uint32_t count, uint16_t type); |
| 52 | bool CheckIntraSection(); |
| 53 | |
| 54 | bool CheckOffsetToTypeMap(uint32_t offset, uint16_t type); |
| 55 | uint16_t FindFirstClassDataDefiner(const byte* ptr) const; |
| 56 | uint16_t FindFirstAnnotationsDirectoryDefiner(const byte* ptr) const; |
| 57 | |
| 58 | bool CheckInterStringIdItem(); |
| 59 | bool CheckInterTypeIdItem(); |
| 60 | bool CheckInterProtoIdItem(); |
| 61 | bool CheckInterFieldIdItem(); |
| 62 | bool CheckInterMethodIdItem(); |
| 63 | bool CheckInterClassDefItem(); |
| 64 | bool CheckInterAnnotationSetRefList(); |
| 65 | bool CheckInterAnnotationSetItem(); |
| 66 | bool CheckInterClassDataItem(); |
| 67 | bool CheckInterAnnotationsDirectoryItem(); |
| 68 | |
| 69 | bool CheckInterSectionIterate(uint32_t offset, uint32_t count, uint16_t type); |
| 70 | bool CheckInterSection(); |
| 71 | |
| 72 | DexFile* dex_file_; |
| 73 | const byte* base_; |
| 74 | size_t length_; |
| 75 | const DexFile::Header* header_; |
| 76 | |
| 77 | std::map<uint32_t, uint16_t> offset_to_type_map_; |
| 78 | const byte* ptr_; |
| 79 | const void* previous_item_; |
| 80 | }; |
| 81 | |
| 82 | } // namespace art |
| 83 | |
| 84 | #endif // ART_SRC_DEX_FILE_VERIFIER_H_ |