summaryrefslogtreecommitdiffstats
path: root/runtime/zip_archive.h
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2013-07-12 13:46:57 -0700
committerBrian Carlstrom <bdc@google.com>2013-07-12 17:49:01 -0700
commit7940e44f4517de5e2634a7e07d58d0fb26160513 (patch)
treeac90242d96229a6942f6e24ab137bc1f8f2e0025 /runtime/zip_archive.h
parent5cd9e3b122f276f610980cbaf0d2ad6ed4cd9088 (diff)
downloadart-7940e44f4517de5e2634a7e07d58d0fb26160513.zip
art-7940e44f4517de5e2634a7e07d58d0fb26160513.tar.gz
art-7940e44f4517de5e2634a7e07d58d0fb26160513.tar.bz2
Create separate Android.mk for main build targets
The runtime, compiler, dex2oat, and oatdump now are in seperate trees to prevent dependency creep. They can now be individually built without rebuilding the rest of the art projects. dalvikvm and jdwpspy were already this way. Builds in the art directory should behave as before, building everything including tests. Change-Id: Ic6b1151e5ed0f823c3dd301afd2b13eb2d8feb81
Diffstat (limited to 'runtime/zip_archive.h')
-rw-r--r--runtime/zip_archive.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/runtime/zip_archive.h b/runtime/zip_archive.h
new file mode 100644
index 0000000..ef31486
--- /dev/null
+++ b/runtime/zip_archive.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_SRC_ZIP_ARCHIVE_H_
+#define ART_SRC_ZIP_ARCHIVE_H_
+
+#include <stdint.h>
+#include <zlib.h>
+
+#include "base/logging.h"
+#include "base/stringpiece.h"
+#include "base/unix_file/random_access_file.h"
+#include "globals.h"
+#include "mem_map.h"
+#include "os.h"
+#include "safe_map.h"
+#include "UniquePtr.h"
+
+namespace art {
+
+class ZipArchive;
+class MemMap;
+
+class ZipEntry {
+ public:
+ bool ExtractToFile(File& file);
+ bool ExtractToMemory(uint8_t* begin, size_t size);
+ MemMap* ExtractToMemMap(const char* entry_filename);
+
+ uint32_t GetUncompressedLength();
+ uint32_t GetCrc32();
+
+ private:
+ ZipEntry(const ZipArchive* zip_archive, const byte* ptr) : zip_archive_(zip_archive), ptr_(ptr) {}
+
+ // Zip compression methods
+ enum {
+ kCompressStored = 0, // no compression
+ kCompressDeflated = 8, // standard deflate
+ };
+
+ // kCompressStored, kCompressDeflated, ...
+ uint16_t GetCompressionMethod();
+
+ uint32_t GetCompressedLength();
+
+ // returns -1 on error
+ off_t GetDataOffset();
+
+ const ZipArchive* zip_archive_;
+
+ // pointer to zip entry within central directory
+ const byte* ptr_;
+
+ friend class ZipArchive;
+ DISALLOW_COPY_AND_ASSIGN(ZipEntry);
+};
+
+class ZipArchive {
+ public:
+ // Zip file constants.
+ static const uint32_t kEOCDSignature = 0x06054b50;
+ static const int32_t kEOCDLen = 22;
+ static const int32_t kEOCDNumEntries = 8; // offset to #of entries in file
+ static const int32_t kEOCDSize = 12; // size of the central directory
+ static const int32_t kEOCDFileOffset = 16; // offset to central directory
+
+ static const int32_t kMaxCommentLen = 65535; // longest possible in uint16_t
+ static const int32_t kMaxEOCDSearch = (kMaxCommentLen + kEOCDLen);
+
+ static const uint32_t kLFHSignature = 0x04034b50;
+ static const int32_t kLFHLen = 30; // excluding variable-len fields
+ static const int32_t kLFHNameLen = 26; // offset to filename length
+ static const int32_t kLFHExtraLen = 28; // offset to extra length
+
+ static const uint32_t kCDESignature = 0x02014b50;
+ static const int32_t kCDELen = 46; // excluding variable-len fields
+ static const int32_t kCDEMethod = 10; // offset to compression method
+ static const int32_t kCDEModWhen = 12; // offset to modification timestamp
+ static const int32_t kCDECRC = 16; // offset to entry CRC
+ static const int32_t kCDECompLen = 20; // offset to compressed length
+ static const int32_t kCDEUncompLen = 24; // offset to uncompressed length
+ static const int32_t kCDENameLen = 28; // offset to filename length
+ static const int32_t kCDEExtraLen = 30; // offset to extra length
+ static const int32_t kCDECommentLen = 32; // offset to comment length
+ static const int32_t kCDELocalOffset = 42; // offset to local hdr
+
+ // return new ZipArchive instance on success, NULL on error.
+ static ZipArchive* Open(const std::string& filename);
+ static ZipArchive* OpenFromFd(int fd);
+
+ ZipEntry* Find(const char* name) const;
+
+ ~ZipArchive() {
+ Close();
+ }
+
+ private:
+ explicit ZipArchive(int fd) : fd_(fd), num_entries_(0), dir_offset_(0) {}
+
+ bool MapCentralDirectory();
+ bool Parse();
+ void Close();
+
+ int fd_;
+ uint16_t num_entries_;
+ off_t dir_offset_;
+ UniquePtr<MemMap> dir_map_;
+ typedef SafeMap<StringPiece, const byte*> DirEntries;
+ DirEntries dir_entries_;
+
+ friend class ZipEntry;
+
+ DISALLOW_COPY_AND_ASSIGN(ZipArchive);
+};
+
+} // namespace art
+
+#endif // ART_SRC_ZIP_ARCHIVE_H_