blob: 9b66b6eacf41073d6bbc122e888a43c01e884775 [file] [log] [blame]
jeffhao10037c82012-01-23 15:06:23 -08001// 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
10namespace art {
11
12class DexFileVerifier {
13 public:
Ian Rogers30fab402012-01-23 15:43:46 -080014 static bool Verify(DexFile* dex_file, const byte* begin, size_t length);
jeffhao10037c82012-01-23 15:06:23 -080015
16 private:
Ian Rogers30fab402012-01-23 15:43:46 -080017 DexFileVerifier(DexFile* dex_file, const byte* begin, size_t length)
18 : dex_file_(dex_file), begin_(begin), length_(length),
jeffhao10037c82012-01-23 15:06:23 -080019 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_;
Ian Rogers30fab402012-01-23 15:43:46 -080073 const byte* begin_;
jeffhao10037c82012-01-23 15:06:23 -080074 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_