blob: 3545c0760e50aa1ca5569f89079dfe885297ff19 [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.
Carl Shapiroa506cb02011-06-28 22:53:46 -070020 // TODO: move this into the DexFile unit test
Carl Shapiro80d4dde2011-06-28 16:24:07 -070021 static DexFile* OpenBase64(const char* base64);
22
23 // Opens a .dex file from a RawDexFile. Takes ownership of the
24 // RawDexFile.
25 static DexFile* Open(RawDexFile* raw);
Carl Shapiro1fb86202011-06-27 17:43:13 -070026
27 // Close and deallocate.
28 ~DexFile();
29
30 size_t NumTypes() {
31 return num_classes_;
32 }
33
34 size_t NumMethods() {
35 return num_methods_;
36 }
37
38 Class* LoadClass(const char* descriptor);
39
40 Class* LoadClass(const RawDexFile::ClassDef& class_def);
41
42 private:
43 DexFile(RawDexFile* raw) : raw_(raw) {};
44
45 void Init();
46
Carl Shapiro3ee755d2011-06-28 12:11:04 -070047 void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass);
Carl Shapiro1fb86202011-06-27 17:43:13 -070048
Carl Shapiro3ee755d2011-06-28 12:11:04 -070049 void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst);
Carl Shapiro1fb86202011-06-27 17:43:13 -070050
Carl Shapiro3ee755d2011-06-28 12:11:04 -070051 void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst);
Carl Shapiro1fb86202011-06-27 17:43:13 -070052
53 // Table of contents for interned String objects.
54 String** strings_;
55 size_t num_strings_;
56
57 // Table of contents for Class objects.
58 Class** classes_;
59 size_t num_classes_;
60
61 // Table of contents for methods.
62 Method** methods_;
63 size_t num_methods_;
64
65 // Table of contents for fields.
66 Field** fields_;
67 size_t num_fields_;
68
69 // The size of the DEX file, in bytes.
70 size_t length_;
71
72 // The underlying dex file.
Carl Shapiro7e782482011-06-28 16:30:04 -070073 scoped_ptr<RawDexFile> raw_;
Carl Shapiro1fb86202011-06-27 17:43:13 -070074
75 DISALLOW_COPY_AND_ASSIGN(DexFile);
76};
77
78} // namespace art
79
80#endif // ART_SRC_DEX_FILE_H_