1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #ifndef LIBBCC_ZIP_H 18 #define LIBBCC_ZIP_H 19 20 #include <stdint.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 // Represents an opened zip archive. 27 // Only basic ZIP files are supported, in particular the following are not 28 // supported: 29 // - encryption 30 // - streaming 31 // - multi-part ZIP files 32 // - ZIP64 33 struct bcc_zip_archive; 34 35 // Carries information on name, compression method and data corresponding to 36 // a file in a zip archive. 37 struct bcc_zip_entry { 38 // Compression method as defined in pkzip spec. 0 means data is uncompressed. 39 uint16_t compression; 40 41 // Non-null terminated name of the file. 42 const char* name; 43 // Length of the file name. 44 uint16_t name_length; 45 46 // Pointer to the file data. 47 const void* data; 48 // Length of the file data. 49 uint32_t data_length; 50 // Offset of the file data within the archive. 51 uint32_t data_offset; 52 }; 53 54 // Opens a zip archive. Returns NULL in case of an error. 55 struct bcc_zip_archive* bcc_zip_archive_open(const char* path); 56 57 // Closes a zip archive and releases resources. 58 void bcc_zip_archive_close(struct bcc_zip_archive* archive); 59 60 // Looks up data corresponding to a file in given zip archive. 61 int bcc_zip_archive_find_entry(struct bcc_zip_archive* archive, 62 const char* name, struct bcc_zip_entry* out); 63 64 int bcc_zip_archive_find_entry_at_offset(struct bcc_zip_archive* archive, 65 uint32_t offset, 66 struct bcc_zip_entry* out); 67 68 // Opens a zip archives and looks up entry within the archive. 69 // Provided path is interpreted as archive path followed by "!/" 70 // characters and name of the zip entry. This convention is used 71 // by Android tools. 72 struct bcc_zip_archive* bcc_zip_archive_open_and_find( 73 const char* path, struct bcc_zip_entry* out); 74 75 #ifdef __cplusplus 76 } 77 #endif 78 #endif 79