blob: 51c0a5aad4bdf10c0a9e3edb0e9a59ff18ec75a0 [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// 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
11namespace art {
12
13class DexFile {
14 public:
Carl Shapiro80d4dde2011-06-28 16:24:07 -070015 // 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 Shapiro1fb86202011-06-27 17:43:13 -070025
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 Shapiro3ee755d2011-06-28 12:11:04 -070046 void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass);
Carl Shapiro1fb86202011-06-27 17:43:13 -070047
Carl Shapiro3ee755d2011-06-28 12:11:04 -070048 void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst);
Carl Shapiro1fb86202011-06-27 17:43:13 -070049
Carl Shapiro3ee755d2011-06-28 12:11:04 -070050 void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst);
Carl Shapiro1fb86202011-06-27 17:43:13 -070051
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_