2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <utils/RefBase.h>
24 #include <utils/String8.h>
29 #define OBB_OVERLAY (1 << 0)
30 #define OBB_SALTED (1 << 1)
32 class ObbFile : public RefBase {
39 bool readFrom(const char* filename);
40 bool readFrom(int fd);
41 bool writeTo(const char* filename);
43 bool removeFrom(const char* filename);
44 bool removeFrom(int fd);
46 const char* getFileName() const {
50 const String8 getPackageName() const {
54 void setPackageName(String8 packageName) {
55 mPackageName = packageName;
58 int32_t getVersion() const {
62 void setVersion(int32_t version) {
66 int32_t getFlags() const {
70 void setFlags(int32_t flags) {
74 const unsigned char* getSalt(size_t* length) const {
75 if ((mFlags & OBB_SALTED) == 0) {
80 *length = sizeof(mSalt);
84 bool setSalt(const unsigned char* salt, size_t length) {
85 if (length != sizeof(mSalt)) {
89 memcpy(mSalt, salt, sizeof(mSalt));
95 return (mFlags & OBB_OVERLAY) == OBB_OVERLAY;
98 void setOverlay(bool overlay) {
100 mFlags |= OBB_OVERLAY;
102 mFlags &= ~OBB_OVERLAY;
106 static inline uint32_t get4LE(const unsigned char* buf) {
107 return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
110 static inline void put4LE(unsigned char* buf, uint32_t val) {
112 buf[1] = (val >> 8) & 0xFF;
113 buf[2] = (val >> 16) & 0xFF;
114 buf[3] = (val >> 24) & 0xFF;
118 /* Package name this ObbFile is associated with */
119 String8 mPackageName;
121 /* Package version this ObbFile is associated with */
124 /* Flags for this OBB type. */
127 /* Whether the file is salted. */
130 /* The encryption salt. */
131 unsigned char mSalt[8];
133 const char* mFileName;
139 unsigned char* mReadBuf;
141 bool parseObbFile(int fd);
145 #endif /* OBBFILE_H_ */