blob: b3bb7d22426d5a0b958ab0c79aa9d24ff5c6befe [file] [log] [blame]
Carl Shapiro1fb86202011-06-27 17:43:13 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
Brian Carlstrom578bbdc2011-07-21 14:07:47 -07003#include "dex_file.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07004
5#include <fcntl.h>
Brian Carlstromb0460ea2011-07-29 10:08:05 -07006#include <map>
7#include <stdio.h>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -07008#include <string.h>
Brian Carlstromb0460ea2011-07-29 10:08:05 -07009#include <sys/file.h>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070010#include <sys/mman.h>
11#include <sys/stat.h>
12#include <sys/types.h>
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070013
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070014#include "globals.h"
15#include "logging.h"
16#include "object.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070017#include "scoped_ptr.h"
Brian Carlstromb0460ea2011-07-29 10:08:05 -070018#include "stringprintf.h"
19#include "thread.h"
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070020#include "utils.h"
Brian Carlstromb0460ea2011-07-29 10:08:05 -070021#include "zip_archive.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070022
23namespace art {
24
Brian Carlstromf615a612011-07-23 12:50:34 -070025const byte DexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' };
26const byte DexFile::kDexMagicVersion[] = { '0', '3', '5', '\0' };
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070027
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070028DexFile::ClassPathEntry DexFile::FindInClassPath(const StringPiece& descriptor,
29 ClassPath& class_path) {
30 for (size_t i = 0; i != class_path.size(); ++i) {
31 const DexFile* dex_file = class_path[i];
32 const DexFile::ClassDef* dex_class_def = dex_file->FindClassDef(descriptor);
33 if (dex_class_def != NULL) {
34 return ClassPathEntry(dex_file, dex_class_def);
35 }
36 }
Brian Carlstrom7e93b502011-08-04 14:16:22 -070037 // TODO remove reinterpret_cast when issue with -std=gnu++0x host issue resolved
38 return ClassPathEntry(reinterpret_cast<const DexFile*>(NULL),
39 reinterpret_cast<const DexFile::ClassDef*>(NULL));
Brian Carlstrom74eb46a2011-08-02 20:10:14 -070040}
41
Brian Carlstromf615a612011-07-23 12:50:34 -070042DexFile::Closer::~Closer() {}
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070043
Brian Carlstromf615a612011-07-23 12:50:34 -070044DexFile::MmapCloser::MmapCloser(void* addr, size_t length) : addr_(addr), length_(length) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070045 CHECK(addr != NULL);
46}
Brian Carlstromf615a612011-07-23 12:50:34 -070047DexFile::MmapCloser::~MmapCloser() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070048 if (munmap(addr_, length_) == -1) {
49 PLOG(INFO) << "munmap failed";
50 }
51}
52
Brian Carlstromf615a612011-07-23 12:50:34 -070053DexFile::PtrCloser::PtrCloser(byte* addr) : addr_(addr) {}
54DexFile::PtrCloser::~PtrCloser() { delete[] addr_; }
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070055
Brian Carlstromb0460ea2011-07-29 10:08:05 -070056DexFile* DexFile::OpenFile(const std::string& filename) {
57 int fd = open(filename.c_str(), O_RDONLY); // TODO: scoped_fd
Brian Carlstrom7e49dca2011-07-22 18:07:34 -070058 if (fd == -1) {
59 PLOG(ERROR) << "open(\"" << filename << "\", O_RDONLY) failed";
60 return NULL;
61 }
62 struct stat sbuf;
63 memset(&sbuf, 0, sizeof(sbuf));
64 if (fstat(fd, &sbuf) == -1) {
65 PLOG(ERROR) << "fstat \"" << filename << "\" failed";
66 close(fd);
67 return NULL;
68 }
69 size_t length = sbuf.st_size;
70 void* addr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0);
71 if (addr == MAP_FAILED) {
72 PLOG(ERROR) << "mmap \"" << filename << "\" failed";
73 close(fd);
74 return NULL;
75 }
76 close(fd);
77 byte* dex_file = reinterpret_cast<byte*>(addr);
78 Closer* closer = new MmapCloser(addr, length);
79 return Open(dex_file, length, closer);
80}
81
Brian Carlstromb0460ea2011-07-29 10:08:05 -070082static const char* kClassesDex = "classes.dex";
83
84class LockedFd {
85 public:
86 static LockedFd* CreateAndLock(std::string& name, mode_t mode) {
87 int fd = open(name.c_str(), O_CREAT | O_RDWR, mode);
88 if (fd == -1) {
Brian Carlstrom0024d6c2011-08-09 08:26:12 -070089 PLOG(ERROR) << "Can't open file '" << name << "'";
Brian Carlstromb0460ea2011-07-29 10:08:05 -070090 return NULL;
91 }
92 fchmod(fd, mode);
93
94 LOG(INFO) << "locking file " << name << " (fd=" << fd << ")";
95 int result = flock(fd, LOCK_EX | LOCK_NB);
96 if (result == -1) {
97 LOG(WARNING) << "sleeping while locking file " << name;
98 result = flock(fd, LOCK_EX);
99 }
100 if (result == -1 ) {
Brian Carlstrom0024d6c2011-08-09 08:26:12 -0700101 PLOG(ERROR) << "Can't lock file '" << name << "'";
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700102 close(fd);
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700103 return NULL;
104 }
105 return new LockedFd(fd);
106 }
107
108 int GetFd() const {
109 return fd_;
110 }
111
112 ~LockedFd() {
113 if (fd_ != -1) {
114 int result = flock(fd_, LOCK_UN);
115 if (result == -1) {
116 PLOG(WARNING) << "flock(" << fd_ << ", LOCK_UN) failed";
117 }
118 close(fd_);
119 }
120 }
121
122 private:
123 LockedFd(int fd) : fd_(fd) {}
124
125 int fd_;
126};
127
128class TmpFile {
129 public:
130 TmpFile(const std::string name) : name_(name) {}
131 ~TmpFile() {
132 unlink(name_.c_str());
133 }
134 private:
135 const std::string name_;
136};
137
138// Open classes.dex from within a .zip, .jar, .apk, ...
139DexFile* DexFile::OpenZip(const std::string& filename) {
140
141 // First, look for a ".dex" alongside the jar file. It will have
142 // the same name/path except for the extension.
143
144 // Example filename = dir/foo.jar
145 std::string adjacent_dex_filename(filename);
146 size_t found = adjacent_dex_filename.find_last_of(".");
147 if (found == std::string::npos) {
148 LOG(WARNING) << "No . in filename" << filename;
149 }
150 adjacent_dex_filename.replace(adjacent_dex_filename.begin() + found,
151 adjacent_dex_filename.end(),
152 ".dex");
153 // Example adjacent_dex_filename = dir/foo.dex
154 DexFile* adjacent_dex_file = DexFile::OpenFile(adjacent_dex_filename);
155 if (adjacent_dex_file != NULL) {
156 // We don't verify anything in this case, because we aren't in
157 // the cache and typically the file is in the readonly /system
158 // area, so if something is wrong, there is nothing we can do.
159 return adjacent_dex_file;
160 }
161
162 char resolved[PATH_MAX];
163 char* absolute_path = realpath(filename.c_str(), resolved);
164 if (absolute_path == NULL) {
165 LOG(WARNING) << "Could not create absolute path for " << filename
166 << " when looking for classes.dex";
167 return NULL;
168 }
169 std::string cache_file(absolute_path+1); // skip leading slash
170 std::replace(cache_file.begin(), cache_file.end(), '/', '@');
171 cache_file.push_back('@');
172 cache_file.append(kClassesDex);
173 // Example cache_file = parent@dir@foo.jar@classes.dex
174
175 const char* data_root = getenv("ANDROID_DATA");
176 if (data_root == NULL) {
177 data_root = "/data";
178 }
179
180 std::string cache_path_tmp = StringPrintf("%s/art-cache/%s", data_root, cache_file.c_str());
181 // Example cache_path_tmp = /data/art-cache/parent@dir@foo.jar@classes.dex
182
183 scoped_ptr<ZipArchive> zip_archive(ZipArchive::Open(filename));
184 if (zip_archive == NULL) {
185 LOG(WARNING) << "Could not open " << filename << " when looking for classes.dex";
186 return NULL;
187 }
188 scoped_ptr<ZipEntry> zip_entry(zip_archive->Find(kClassesDex));
189 if (zip_entry == NULL) {
190 LOG(WARNING) << "Could not find classes.dex within " << filename;
191 return NULL;
192 }
193
194 std::string cache_path = StringPrintf("%s.%08x", cache_path_tmp.c_str(), zip_entry->GetCrc32());
195 // Example cache_path = /data/art-cache/parent@dir@foo.jar@classes.dex.1a2b3c4d
196
197 while (true) {
198 DexFile* cached_dex_file = DexFile::OpenFile(cache_path);
199 if (cached_dex_file != NULL) {
200 return cached_dex_file;
201 }
202
203 // Try to open the temporary cache file, grabbing an exclusive
204 // lock. If somebody else is working on it, we'll block here until
205 // they complete. Because we're waiting on an external resource,
206 // we go into native mode.
207 Thread* current_thread = Thread::Current();
208 Thread::State old = current_thread->GetState();
209 current_thread->SetState(Thread::kNative);
210 scoped_ptr<LockedFd> fd(LockedFd::CreateAndLock(cache_path_tmp, 0644));
211 current_thread->SetState(old);
212 if (fd == NULL) {
213 return NULL;
214 }
215
216 // Check to see if the fd we opened and locked matches the file in
217 // the filesystem. If they don't, then somebody else unlinked
218 // ours and created a new file, and we need to use that one
219 // instead. (If we caught them between the unlink and the create,
220 // we'll get an ENOENT from the file stat.)
221 struct stat fd_stat;
222 int fd_stat_result = fstat(fd->GetFd(), &fd_stat);
223 if (fd_stat_result == -1) {
224 PLOG(ERROR) << "Can't stat open file '" << cache_path_tmp << "'";
225 return NULL;
226 }
227 struct stat file_stat;
228 int file_stat_result = stat(cache_path_tmp.c_str(), &file_stat);
229 if (file_stat_result == -1 ||
230 fd_stat.st_dev != file_stat.st_dev || fd_stat.st_ino != file_stat.st_ino) {
231 LOG(WARNING) << "our open cache file is stale; sleeping and retrying";
232 usleep(250 * 1000); // if something is hosed, don't peg machine
233 continue;
234 }
235
236 // We have the correct file open and locked. Extract classes.dex
237 TmpFile tmp_file(cache_path_tmp);
238 bool success = zip_entry->Extract(fd->GetFd());
239 if (!success) {
240 return NULL;
241 }
242
243 // TODO restat and check length against zip_entry->GetUncompressedLength()?
244
245 // Compute checksum and compare to zip. If things look okay, rename from tmp.
246 off_t lseek_result = lseek(fd->GetFd(), 0, SEEK_SET);
247 if (lseek_result == -1) {
248 return NULL;
249 }
250 const size_t kBufSize = 32768;
251 scoped_ptr<uint8_t> buf(new uint8_t[kBufSize]);
252 if (buf == NULL) {
253 return NULL;
254 }
255 uint32_t computed_crc = crc32(0L, Z_NULL, 0);
256 while (true) {
257 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd->GetFd(), buf.get(), kBufSize));
Brian Carlstrom0024d6c2011-08-09 08:26:12 -0700258 if (bytes_read == -1) {
259 PLOG(ERROR) << "Problem computing CRC of '" << cache_path_tmp << "'";
260 return NULL;
261 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700262 if (bytes_read == 0) {
263 break;
264 }
265 computed_crc = crc32(computed_crc, buf.get(), bytes_read);
266 }
267 if (computed_crc != zip_entry->GetCrc32()) {
268 return NULL;
269 }
270 int rename_result = rename(cache_path_tmp.c_str(), cache_path.c_str());
271 if (rename_result == -1) {
Brian Carlstrom0024d6c2011-08-09 08:26:12 -0700272 PLOG(ERROR) << "Can't install dex cache file '" << cache_path << "'"
273 << " from '" << cache_path_tmp << "'";
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700274 unlink(cache_path.c_str());
275 }
276 }
277 // NOTREACHED
278}
279
Brian Carlstromf615a612011-07-23 12:50:34 -0700280DexFile* DexFile::OpenPtr(byte* ptr, size_t length) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700281 CHECK(ptr != NULL);
Brian Carlstromf615a612011-07-23 12:50:34 -0700282 DexFile::Closer* closer = new PtrCloser(ptr);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700283 return Open(ptr, length, closer);
284}
285
Brian Carlstromf615a612011-07-23 12:50:34 -0700286DexFile* DexFile::Open(const byte* dex_bytes, size_t length,
287 Closer* closer) {
288 scoped_ptr<DexFile> dex_file(new DexFile(dex_bytes, length, closer));
289 if (!dex_file->Init()) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700290 return NULL;
291 } else {
Brian Carlstromf615a612011-07-23 12:50:34 -0700292 return dex_file.release();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700293 }
294}
295
Brian Carlstromf615a612011-07-23 12:50:34 -0700296DexFile::~DexFile() {}
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700297
Brian Carlstromf615a612011-07-23 12:50:34 -0700298bool DexFile::Init() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700299 InitMembers();
300 if (!IsMagicValid()) {
301 return false;
302 }
303 InitIndex();
304 return true;
305}
306
Brian Carlstromf615a612011-07-23 12:50:34 -0700307void DexFile::InitMembers() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700308 const byte* b = base_;
309 header_ = reinterpret_cast<const Header*>(b);
310 const Header* h = header_;
311 string_ids_ = reinterpret_cast<const StringId*>(b + h->string_ids_off_);
312 type_ids_ = reinterpret_cast<const TypeId*>(b + h->type_ids_off_);
313 field_ids_ = reinterpret_cast<const FieldId*>(b + h->field_ids_off_);
314 method_ids_ = reinterpret_cast<const MethodId*>(b + h->method_ids_off_);
315 proto_ids_ = reinterpret_cast<const ProtoId*>(b + h->proto_ids_off_);
316 class_defs_ = reinterpret_cast<const ClassDef*>(b + h->class_defs_off_);
317}
318
Brian Carlstromf615a612011-07-23 12:50:34 -0700319bool DexFile::IsMagicValid() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700320 return CheckMagic(header_->magic_);
321}
322
Brian Carlstromf615a612011-07-23 12:50:34 -0700323bool DexFile::CheckMagic(const byte* magic) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700324 CHECK(magic != NULL);
325 if (memcmp(magic, kDexMagic, sizeof(kDexMagic)) != 0) {
326 LOG(WARNING) << "Unrecognized magic number:"
327 << " " << magic[0]
328 << " " << magic[1]
329 << " " << magic[2]
330 << " " << magic[3];
331 return false;
332 }
333 const byte* version = &magic[sizeof(kDexMagic)];
334 if (memcmp(version, kDexMagicVersion, sizeof(kDexMagicVersion)) != 0) {
335 LOG(WARNING) << "Unrecognized version number:"
336 << " " << version[0]
337 << " " << version[1]
338 << " " << version[2]
339 << " " << version[3];
340 return false;
341 }
342 return true;
343}
344
Brian Carlstromf615a612011-07-23 12:50:34 -0700345void DexFile::InitIndex() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700346 CHECK_EQ(index_.size(), 0U);
347 for (size_t i = 0; i < NumClassDefs(); ++i) {
348 const ClassDef& class_def = GetClassDef(i);
349 const char* descriptor = GetClassDescriptor(class_def);
350 index_[descriptor] = &class_def;
351 }
352}
353
Brian Carlstromf615a612011-07-23 12:50:34 -0700354const DexFile::ClassDef* DexFile::FindClassDef(const StringPiece& descriptor) const {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700355 CHECK(descriptor != NULL);
356 Index::const_iterator it = index_.find(descriptor);
357 if (it == index_.end()) {
358 return NULL;
359 } else {
360 return it->second;
361 }
362}
363
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700364// Materializes the method descriptor for a method prototype. Method
365// descriptors are not stored directly in the dex file. Instead, one
366// must assemble the descriptor from references in the prototype.
367char* DexFile::CreateMethodDescriptor(uint32_t proto_idx,
368 int32_t* unicode_length) const {
369 CHECK(unicode_length != NULL);
370 const ProtoId& proto_id = GetProtoId(proto_idx);
371 std::string descriptor;
372 descriptor.push_back('(');
373 const TypeList* type_list = GetProtoParameters(proto_id);
374 size_t parameter_length = 0;
375 if (type_list != NULL) {
376 // A non-zero number of arguments. Append the type names.
377 for (size_t i = 0; i < type_list->Size(); ++i) {
378 const TypeItem& type_item = type_list->GetTypeItem(i);
379 uint32_t type_idx = type_item.type_idx_;
380 int32_t type_length;
381 const char* name = dexStringByTypeIdx(type_idx, &type_length);
382 parameter_length += type_length;
383 descriptor.append(name);
384 }
385 }
386 descriptor.push_back(')');
387 uint32_t return_type_idx = proto_id.return_type_idx_;
388 int32_t return_type_length;
389 const char* name = dexStringByTypeIdx(return_type_idx, &return_type_length);
390 descriptor.append(name);
391 // TODO: should this just return a std::string?
392 scoped_ptr<char> c_string(new char[descriptor.size() + 1]);
393 strcpy(c_string.get(), descriptor.c_str());
394 *unicode_length = parameter_length + return_type_length + 2; // 2 for ( and )
395 return c_string.release();
396}
397
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700398// Read a signed integer. "zwidth" is the zero-based byte count.
399static int32_t ReadSignedInt(const byte* ptr, int zwidth)
400{
401 int32_t val = 0;
402 for (int i = zwidth; i >= 0; --i) {
403 val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24);
404 }
405 val >>= (3 - zwidth) * 8;
406 return val;
407}
408
409// Read an unsigned integer. "zwidth" is the zero-based byte count,
410// "fill_on_right" indicates which side we want to zero-fill from.
411static uint32_t ReadUnsignedInt(const byte* ptr, int zwidth,
412 bool fill_on_right) {
413 uint32_t val = 0;
414 if (!fill_on_right) {
415 for (int i = zwidth; i >= 0; --i) {
416 val = (val >> 8) | (((uint32_t)*ptr++) << 24);
417 }
418 val >>= (3 - zwidth) * 8;
419 } else {
420 for (int i = zwidth; i >= 0; --i) {
421 val = (val >> 8) | (((uint32_t)*ptr++) << 24);
422 }
423 }
424 return val;
425}
426
427// Read a signed long. "zwidth" is the zero-based byte count.
428static int64_t ReadSignedLong(const byte* ptr, int zwidth) {
429 int64_t val = 0;
430 for (int i = zwidth; i >= 0; --i) {
431 val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56);
432 }
433 val >>= (7 - zwidth) * 8;
434 return val;
435}
436
437// Read an unsigned long. "zwidth" is the zero-based byte count,
438// "fill_on_right" indicates which side we want to zero-fill from.
439static uint64_t ReadUnsignedLong(const byte* ptr, int zwidth,
440 bool fill_on_right) {
441 uint64_t val = 0;
442 if (!fill_on_right) {
443 for (int i = zwidth; i >= 0; --i) {
444 val = (val >> 8) | (((uint64_t)*ptr++) << 56);
445 }
446 val >>= (7 - zwidth) * 8;
447 } else {
448 for (int i = zwidth; i >= 0; --i) {
449 val = (val >> 8) | (((uint64_t)*ptr++) << 56);
450 }
451 }
452 return val;
453}
454
Brian Carlstromf615a612011-07-23 12:50:34 -0700455DexFile::ValueType DexFile::ReadEncodedValue(const byte** stream,
456 JValue* value) const {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700457 const byte* ptr = *stream;
458 byte value_type = *ptr++;
459 byte value_arg = value_type >> kEncodedValueArgShift;
460 size_t width = value_arg + 1; // assume and correct later
461 int type = value_type & kEncodedValueTypeMask;
462 switch (type) {
Brian Carlstromf615a612011-07-23 12:50:34 -0700463 case DexFile::kByte: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700464 int32_t b = ReadSignedInt(ptr, value_arg);
465 CHECK(IsInt(8, b));
466 value->i = b;
467 break;
468 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700469 case DexFile::kShort: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700470 int32_t s = ReadSignedInt(ptr, value_arg);
471 CHECK(IsInt(16, s));
472 value->i = s;
473 break;
474 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700475 case DexFile::kChar: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700476 uint32_t c = ReadUnsignedInt(ptr, value_arg, false);
477 CHECK(IsUint(16, c));
478 value->i = c;
479 break;
480 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700481 case DexFile::kInt:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700482 value->i = ReadSignedInt(ptr, value_arg);
483 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700484 case DexFile::kLong:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700485 value->j = ReadSignedLong(ptr, value_arg);
486 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700487 case DexFile::kFloat:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700488 value->i = ReadUnsignedInt(ptr, value_arg, true);
489 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700490 case DexFile::kDouble:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700491 value->j = ReadUnsignedLong(ptr, value_arg, true);
492 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700493 case DexFile::kBoolean:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700494 value->i = (value_arg != 0);
495 width = 0;
496 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700497 case DexFile::kString:
498 case DexFile::kType:
499 case DexFile::kMethod:
500 case DexFile::kEnum:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700501 value->i = ReadUnsignedInt(ptr, value_arg, false);
502 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700503 case DexFile::kField:
504 case DexFile::kArray:
505 case DexFile::kAnnotation:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700506 LOG(FATAL) << "Unimplemented";
507 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700508 case DexFile::kNull:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700509 value->i = 0;
510 width = 0;
511 break;
512 default:
513 LOG(FATAL) << "Unreached";
514 }
515 ptr += width;
516 *stream = ptr;
517 return static_cast<ValueType>(type);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700518}
519
Carl Shapiro1fb86202011-06-27 17:43:13 -0700520} // namespace art