The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 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 | * Access .dex (Dalvik Executable Format) files. The code here assumes that |
| 18 | * the DEX file has been rewritten (byte-swapped, word-aligned) and that |
| 19 | * the contents can be directly accessed as a collection of C arrays. Please |
| 20 | * see docs/dalvik/dex-format.html for a detailed description. |
| 21 | * |
| 22 | * The structure and field names were chosen to match those in the DEX spec. |
| 23 | * |
| 24 | * It's generally assumed that the DEX file will be stored in shared memory, |
| 25 | * obviating the need to copy code and constant pool entries into newly |
| 26 | * allocated storage. Maintaining local pointers to items in the shared area |
| 27 | * is valid and encouraged. |
| 28 | * |
| 29 | * All memory-mapped structures are 32-bit aligned unless otherwise noted. |
| 30 | */ |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 31 | #ifndef LIBDEX_CMDUTILS_H_ |
| 32 | #define LIBDEX_CMDUTILS_H_ |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 33 | |
| 34 | /* encode the result of unzipping to a file */ |
Carl Shapiro | bfc9799 | 2011-04-27 14:16:08 -0700 | [diff] [blame] | 35 | enum UnzipToFileResult { |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 36 | kUTFRSuccess = 0, |
Andy McFadden | 1113159 | 2009-04-08 00:27:58 -0700 | [diff] [blame] | 37 | kUTFRGenericFailure, |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 38 | kUTFRBadArgs, |
| 39 | kUTFRNotZip, |
| 40 | kUTFRNoClassesDex, |
| 41 | kUTFROutputFileProblem, |
| 42 | kUTFRBadZip, |
Carl Shapiro | bfc9799 | 2011-04-27 14:16:08 -0700 | [diff] [blame] | 43 | }; |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 44 | |
| 45 | /* |
Brian Carlstrom | fbdcfb9 | 2010-05-28 15:42:12 -0700 | [diff] [blame] | 46 | * Map the specified DEX file read-only (possibly after expanding it into a |
| 47 | * temp file from a Jar). Pass in a MemMapping struct to hold the info. |
| 48 | * If the file is an unoptimized DEX file, then byte-swapping and structural |
| 49 | * verification are performed on it before the memory is made read-only. |
| 50 | * |
| 51 | * The temp file is deleted after the map succeeds. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 52 | * |
| 53 | * This is intended for use by tools (e.g. dexdump) that need to get a |
| 54 | * read-only copy of a DEX file that could be in a number of different states. |
| 55 | * |
| 56 | * If "tempFileName" is NULL, a default value is used. The temp file is |
| 57 | * deleted after the map succeeds. |
| 58 | * |
Brian Carlstrom | fbdcfb9 | 2010-05-28 15:42:12 -0700 | [diff] [blame] | 59 | * If "quiet" is set, don't report common errors. |
| 60 | * |
| 61 | * Returns 0 (kUTFRSuccess) on success. |
The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 62 | */ |
| 63 | UnzipToFileResult dexOpenAndMap(const char* fileName, const char* tempFileName, |
| 64 | MemMapping* pMap, bool quiet); |
| 65 | |
| 66 | /* |
| 67 | * Utility function to open a Zip archive, find "classes.dex", and extract |
| 68 | * it to a file. |
| 69 | */ |
| 70 | UnzipToFileResult dexUnzipToFile(const char* zipFileName, |
| 71 | const char* outFileName, bool quiet); |
| 72 | |
Carl Shapiro | 375fb11 | 2011-06-14 20:31:24 -0700 | [diff] [blame] | 73 | #endif // LIBDEX_CMDUTILS_H_ |