blob: 3cddd7f240404e9e3dbc47f63f59102fc22ba5a9 [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
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700154 // TODO: stat first, so we don't report a bogus error.
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700155 DexFile* adjacent_dex_file = DexFile::OpenFile(adjacent_dex_filename);
156 if (adjacent_dex_file != NULL) {
157 // We don't verify anything in this case, because we aren't in
158 // the cache and typically the file is in the readonly /system
159 // area, so if something is wrong, there is nothing we can do.
160 return adjacent_dex_file;
161 }
162
163 char resolved[PATH_MAX];
164 char* absolute_path = realpath(filename.c_str(), resolved);
165 if (absolute_path == NULL) {
166 LOG(WARNING) << "Could not create absolute path for " << filename
167 << " when looking for classes.dex";
168 return NULL;
169 }
170 std::string cache_file(absolute_path+1); // skip leading slash
171 std::replace(cache_file.begin(), cache_file.end(), '/', '@');
172 cache_file.push_back('@');
173 cache_file.append(kClassesDex);
174 // Example cache_file = parent@dir@foo.jar@classes.dex
175
176 const char* data_root = getenv("ANDROID_DATA");
177 if (data_root == NULL) {
178 data_root = "/data";
179 }
180
181 std::string cache_path_tmp = StringPrintf("%s/art-cache/%s", data_root, cache_file.c_str());
182 // Example cache_path_tmp = /data/art-cache/parent@dir@foo.jar@classes.dex
183
184 scoped_ptr<ZipArchive> zip_archive(ZipArchive::Open(filename));
185 if (zip_archive == NULL) {
186 LOG(WARNING) << "Could not open " << filename << " when looking for classes.dex";
187 return NULL;
188 }
189 scoped_ptr<ZipEntry> zip_entry(zip_archive->Find(kClassesDex));
190 if (zip_entry == NULL) {
191 LOG(WARNING) << "Could not find classes.dex within " << filename;
192 return NULL;
193 }
194
195 std::string cache_path = StringPrintf("%s.%08x", cache_path_tmp.c_str(), zip_entry->GetCrc32());
196 // Example cache_path = /data/art-cache/parent@dir@foo.jar@classes.dex.1a2b3c4d
197
198 while (true) {
199 DexFile* cached_dex_file = DexFile::OpenFile(cache_path);
200 if (cached_dex_file != NULL) {
201 return cached_dex_file;
202 }
203
204 // Try to open the temporary cache file, grabbing an exclusive
205 // lock. If somebody else is working on it, we'll block here until
206 // they complete. Because we're waiting on an external resource,
207 // we go into native mode.
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700208 // Note that current_thread can be NULL if we're parsing the bootclasspath
209 // during JNI_CreateJavaVM.
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700210 Thread* current_thread = Thread::Current();
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700211 Thread::State old;
212 if (current_thread != NULL) {
213 old = current_thread->GetState();
214 current_thread->SetState(Thread::kNative);
215 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700216 scoped_ptr<LockedFd> fd(LockedFd::CreateAndLock(cache_path_tmp, 0644));
Elliott Hughes40ef99e2011-08-11 17:44:34 -0700217 if (current_thread != NULL) {
218 current_thread->SetState(old);
219 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700220 if (fd == NULL) {
221 return NULL;
222 }
223
224 // Check to see if the fd we opened and locked matches the file in
225 // the filesystem. If they don't, then somebody else unlinked
226 // ours and created a new file, and we need to use that one
227 // instead. (If we caught them between the unlink and the create,
228 // we'll get an ENOENT from the file stat.)
229 struct stat fd_stat;
230 int fd_stat_result = fstat(fd->GetFd(), &fd_stat);
231 if (fd_stat_result == -1) {
232 PLOG(ERROR) << "Can't stat open file '" << cache_path_tmp << "'";
233 return NULL;
234 }
235 struct stat file_stat;
236 int file_stat_result = stat(cache_path_tmp.c_str(), &file_stat);
237 if (file_stat_result == -1 ||
238 fd_stat.st_dev != file_stat.st_dev || fd_stat.st_ino != file_stat.st_ino) {
239 LOG(WARNING) << "our open cache file is stale; sleeping and retrying";
240 usleep(250 * 1000); // if something is hosed, don't peg machine
241 continue;
242 }
243
244 // We have the correct file open and locked. Extract classes.dex
245 TmpFile tmp_file(cache_path_tmp);
246 bool success = zip_entry->Extract(fd->GetFd());
247 if (!success) {
248 return NULL;
249 }
250
251 // TODO restat and check length against zip_entry->GetUncompressedLength()?
252
253 // Compute checksum and compare to zip. If things look okay, rename from tmp.
254 off_t lseek_result = lseek(fd->GetFd(), 0, SEEK_SET);
255 if (lseek_result == -1) {
256 return NULL;
257 }
258 const size_t kBufSize = 32768;
259 scoped_ptr<uint8_t> buf(new uint8_t[kBufSize]);
260 if (buf == NULL) {
261 return NULL;
262 }
263 uint32_t computed_crc = crc32(0L, Z_NULL, 0);
264 while (true) {
265 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd->GetFd(), buf.get(), kBufSize));
Brian Carlstrom0024d6c2011-08-09 08:26:12 -0700266 if (bytes_read == -1) {
267 PLOG(ERROR) << "Problem computing CRC of '" << cache_path_tmp << "'";
268 return NULL;
269 }
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700270 if (bytes_read == 0) {
271 break;
272 }
273 computed_crc = crc32(computed_crc, buf.get(), bytes_read);
274 }
275 if (computed_crc != zip_entry->GetCrc32()) {
276 return NULL;
277 }
278 int rename_result = rename(cache_path_tmp.c_str(), cache_path.c_str());
279 if (rename_result == -1) {
Brian Carlstrom0024d6c2011-08-09 08:26:12 -0700280 PLOG(ERROR) << "Can't install dex cache file '" << cache_path << "'"
281 << " from '" << cache_path_tmp << "'";
Brian Carlstromb0460ea2011-07-29 10:08:05 -0700282 unlink(cache_path.c_str());
283 }
284 }
285 // NOTREACHED
286}
287
Brian Carlstromf615a612011-07-23 12:50:34 -0700288DexFile* DexFile::OpenPtr(byte* ptr, size_t length) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700289 CHECK(ptr != NULL);
Brian Carlstromf615a612011-07-23 12:50:34 -0700290 DexFile::Closer* closer = new PtrCloser(ptr);
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700291 return Open(ptr, length, closer);
292}
293
Brian Carlstromf615a612011-07-23 12:50:34 -0700294DexFile* DexFile::Open(const byte* dex_bytes, size_t length,
295 Closer* closer) {
296 scoped_ptr<DexFile> dex_file(new DexFile(dex_bytes, length, closer));
297 if (!dex_file->Init()) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700298 return NULL;
299 } else {
Brian Carlstromf615a612011-07-23 12:50:34 -0700300 return dex_file.release();
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700301 }
302}
303
Brian Carlstromf615a612011-07-23 12:50:34 -0700304DexFile::~DexFile() {}
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700305
Brian Carlstromf615a612011-07-23 12:50:34 -0700306bool DexFile::Init() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700307 InitMembers();
308 if (!IsMagicValid()) {
309 return false;
310 }
311 InitIndex();
312 return true;
313}
314
Brian Carlstromf615a612011-07-23 12:50:34 -0700315void DexFile::InitMembers() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700316 const byte* b = base_;
317 header_ = reinterpret_cast<const Header*>(b);
318 const Header* h = header_;
319 string_ids_ = reinterpret_cast<const StringId*>(b + h->string_ids_off_);
320 type_ids_ = reinterpret_cast<const TypeId*>(b + h->type_ids_off_);
321 field_ids_ = reinterpret_cast<const FieldId*>(b + h->field_ids_off_);
322 method_ids_ = reinterpret_cast<const MethodId*>(b + h->method_ids_off_);
323 proto_ids_ = reinterpret_cast<const ProtoId*>(b + h->proto_ids_off_);
324 class_defs_ = reinterpret_cast<const ClassDef*>(b + h->class_defs_off_);
325}
326
Brian Carlstromf615a612011-07-23 12:50:34 -0700327bool DexFile::IsMagicValid() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700328 return CheckMagic(header_->magic_);
329}
330
Brian Carlstromf615a612011-07-23 12:50:34 -0700331bool DexFile::CheckMagic(const byte* magic) {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700332 CHECK(magic != NULL);
333 if (memcmp(magic, kDexMagic, sizeof(kDexMagic)) != 0) {
334 LOG(WARNING) << "Unrecognized magic number:"
335 << " " << magic[0]
336 << " " << magic[1]
337 << " " << magic[2]
338 << " " << magic[3];
339 return false;
340 }
341 const byte* version = &magic[sizeof(kDexMagic)];
342 if (memcmp(version, kDexMagicVersion, sizeof(kDexMagicVersion)) != 0) {
343 LOG(WARNING) << "Unrecognized version number:"
344 << " " << version[0]
345 << " " << version[1]
346 << " " << version[2]
347 << " " << version[3];
348 return false;
349 }
350 return true;
351}
352
Brian Carlstromf615a612011-07-23 12:50:34 -0700353void DexFile::InitIndex() {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700354 CHECK_EQ(index_.size(), 0U);
355 for (size_t i = 0; i < NumClassDefs(); ++i) {
356 const ClassDef& class_def = GetClassDef(i);
357 const char* descriptor = GetClassDescriptor(class_def);
358 index_[descriptor] = &class_def;
359 }
360}
361
Brian Carlstromf615a612011-07-23 12:50:34 -0700362const DexFile::ClassDef* DexFile::FindClassDef(const StringPiece& descriptor) const {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700363 CHECK(descriptor != NULL);
364 Index::const_iterator it = index_.find(descriptor);
365 if (it == index_.end()) {
366 return NULL;
367 } else {
368 return it->second;
369 }
370}
371
Carl Shapiro419ec7b2011-08-03 14:48:33 -0700372// Materializes the method descriptor for a method prototype. Method
373// descriptors are not stored directly in the dex file. Instead, one
374// must assemble the descriptor from references in the prototype.
375char* DexFile::CreateMethodDescriptor(uint32_t proto_idx,
376 int32_t* unicode_length) const {
377 CHECK(unicode_length != NULL);
378 const ProtoId& proto_id = GetProtoId(proto_idx);
379 std::string descriptor;
380 descriptor.push_back('(');
381 const TypeList* type_list = GetProtoParameters(proto_id);
382 size_t parameter_length = 0;
383 if (type_list != NULL) {
384 // A non-zero number of arguments. Append the type names.
385 for (size_t i = 0; i < type_list->Size(); ++i) {
386 const TypeItem& type_item = type_list->GetTypeItem(i);
387 uint32_t type_idx = type_item.type_idx_;
388 int32_t type_length;
389 const char* name = dexStringByTypeIdx(type_idx, &type_length);
390 parameter_length += type_length;
391 descriptor.append(name);
392 }
393 }
394 descriptor.push_back(')');
395 uint32_t return_type_idx = proto_id.return_type_idx_;
396 int32_t return_type_length;
397 const char* name = dexStringByTypeIdx(return_type_idx, &return_type_length);
398 descriptor.append(name);
399 // TODO: should this just return a std::string?
400 scoped_ptr<char> c_string(new char[descriptor.size() + 1]);
401 strcpy(c_string.get(), descriptor.c_str());
402 *unicode_length = parameter_length + return_type_length + 2; // 2 for ( and )
403 return c_string.release();
404}
405
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700406// Read a signed integer. "zwidth" is the zero-based byte count.
407static int32_t ReadSignedInt(const byte* ptr, int zwidth)
408{
409 int32_t val = 0;
410 for (int i = zwidth; i >= 0; --i) {
411 val = ((uint32_t)val >> 8) | (((int32_t)*ptr++) << 24);
412 }
413 val >>= (3 - zwidth) * 8;
414 return val;
415}
416
417// Read an unsigned integer. "zwidth" is the zero-based byte count,
418// "fill_on_right" indicates which side we want to zero-fill from.
419static uint32_t ReadUnsignedInt(const byte* ptr, int zwidth,
420 bool fill_on_right) {
421 uint32_t val = 0;
422 if (!fill_on_right) {
423 for (int i = zwidth; i >= 0; --i) {
424 val = (val >> 8) | (((uint32_t)*ptr++) << 24);
425 }
426 val >>= (3 - zwidth) * 8;
427 } else {
428 for (int i = zwidth; i >= 0; --i) {
429 val = (val >> 8) | (((uint32_t)*ptr++) << 24);
430 }
431 }
432 return val;
433}
434
435// Read a signed long. "zwidth" is the zero-based byte count.
436static int64_t ReadSignedLong(const byte* ptr, int zwidth) {
437 int64_t val = 0;
438 for (int i = zwidth; i >= 0; --i) {
439 val = ((uint64_t)val >> 8) | (((int64_t)*ptr++) << 56);
440 }
441 val >>= (7 - zwidth) * 8;
442 return val;
443}
444
445// Read an unsigned long. "zwidth" is the zero-based byte count,
446// "fill_on_right" indicates which side we want to zero-fill from.
447static uint64_t ReadUnsignedLong(const byte* ptr, int zwidth,
448 bool fill_on_right) {
449 uint64_t val = 0;
450 if (!fill_on_right) {
451 for (int i = zwidth; i >= 0; --i) {
452 val = (val >> 8) | (((uint64_t)*ptr++) << 56);
453 }
454 val >>= (7 - zwidth) * 8;
455 } else {
456 for (int i = zwidth; i >= 0; --i) {
457 val = (val >> 8) | (((uint64_t)*ptr++) << 56);
458 }
459 }
460 return val;
461}
462
Brian Carlstromf615a612011-07-23 12:50:34 -0700463DexFile::ValueType DexFile::ReadEncodedValue(const byte** stream,
464 JValue* value) const {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700465 const byte* ptr = *stream;
466 byte value_type = *ptr++;
467 byte value_arg = value_type >> kEncodedValueArgShift;
468 size_t width = value_arg + 1; // assume and correct later
469 int type = value_type & kEncodedValueTypeMask;
470 switch (type) {
Brian Carlstromf615a612011-07-23 12:50:34 -0700471 case DexFile::kByte: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700472 int32_t b = ReadSignedInt(ptr, value_arg);
473 CHECK(IsInt(8, b));
474 value->i = b;
475 break;
476 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700477 case DexFile::kShort: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700478 int32_t s = ReadSignedInt(ptr, value_arg);
479 CHECK(IsInt(16, s));
480 value->i = s;
481 break;
482 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700483 case DexFile::kChar: {
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700484 uint32_t c = ReadUnsignedInt(ptr, value_arg, false);
485 CHECK(IsUint(16, c));
486 value->i = c;
487 break;
488 }
Brian Carlstromf615a612011-07-23 12:50:34 -0700489 case DexFile::kInt:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700490 value->i = ReadSignedInt(ptr, value_arg);
491 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700492 case DexFile::kLong:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700493 value->j = ReadSignedLong(ptr, value_arg);
494 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700495 case DexFile::kFloat:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700496 value->i = ReadUnsignedInt(ptr, value_arg, true);
497 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700498 case DexFile::kDouble:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700499 value->j = ReadUnsignedLong(ptr, value_arg, true);
500 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700501 case DexFile::kBoolean:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700502 value->i = (value_arg != 0);
503 width = 0;
504 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700505 case DexFile::kString:
506 case DexFile::kType:
507 case DexFile::kMethod:
508 case DexFile::kEnum:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700509 value->i = ReadUnsignedInt(ptr, value_arg, false);
510 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700511 case DexFile::kField:
512 case DexFile::kArray:
513 case DexFile::kAnnotation:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700514 LOG(FATAL) << "Unimplemented";
515 break;
Brian Carlstromf615a612011-07-23 12:50:34 -0700516 case DexFile::kNull:
Brian Carlstrom7e49dca2011-07-22 18:07:34 -0700517 value->i = 0;
518 width = 0;
519 break;
520 default:
521 LOG(FATAL) << "Unreached";
522 }
523 ptr += width;
524 *stream = ptr;
525 return static_cast<ValueType>(type);
Carl Shapiro1fb86202011-06-27 17:43:13 -0700526}
527
Carl Shapiro1fb86202011-06-27 17:43:13 -0700528} // namespace art