Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_DEX_FILE_H_ |
| 4 | #define ART_SRC_DEX_FILE_H_ |
| 5 | |
| 6 | #include "src/globals.h" |
| 7 | #include "src/macros.h" |
| 8 | #include "src/object.h" |
| 9 | #include "src/raw_dex_file.h" |
| 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | class DexFile { |
| 14 | public: |
Carl Shapiro | 80d4dde | 2011-06-28 16:24:07 -0700 | [diff] [blame^] | 15 | // Opens a .dex file from the file system. Returns NULL on failure. |
| 16 | static DexFile* OpenFile(const char* filename); |
| 17 | |
| 18 | // Opens a .dex file from a base64 encoded array. Returns NULL on |
| 19 | // failure. |
| 20 | static DexFile* OpenBase64(const char* base64); |
| 21 | |
| 22 | // Opens a .dex file from a RawDexFile. Takes ownership of the |
| 23 | // RawDexFile. |
| 24 | static DexFile* Open(RawDexFile* raw); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 25 | |
| 26 | // Close and deallocate. |
| 27 | ~DexFile(); |
| 28 | |
| 29 | size_t NumTypes() { |
| 30 | return num_classes_; |
| 31 | } |
| 32 | |
| 33 | size_t NumMethods() { |
| 34 | return num_methods_; |
| 35 | } |
| 36 | |
| 37 | Class* LoadClass(const char* descriptor); |
| 38 | |
| 39 | Class* LoadClass(const RawDexFile::ClassDef& class_def); |
| 40 | |
| 41 | private: |
| 42 | DexFile(RawDexFile* raw) : raw_(raw) {}; |
| 43 | |
| 44 | void Init(); |
| 45 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 46 | void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 47 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 48 | void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 49 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 50 | void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 51 | |
| 52 | // Table of contents for interned String objects. |
| 53 | String** strings_; |
| 54 | size_t num_strings_; |
| 55 | |
| 56 | // Table of contents for Class objects. |
| 57 | Class** classes_; |
| 58 | size_t num_classes_; |
| 59 | |
| 60 | // Table of contents for methods. |
| 61 | Method** methods_; |
| 62 | size_t num_methods_; |
| 63 | |
| 64 | // Table of contents for fields. |
| 65 | Field** fields_; |
| 66 | size_t num_fields_; |
| 67 | |
| 68 | // The size of the DEX file, in bytes. |
| 69 | size_t length_; |
| 70 | |
| 71 | // The underlying dex file. |
| 72 | RawDexFile* raw_; |
| 73 | |
| 74 | DISALLOW_COPY_AND_ASSIGN(DexFile); |
| 75 | }; |
| 76 | |
| 77 | } // namespace art |
| 78 | |
| 79 | #endif // ART_SRC_DEX_FILE_H_ |