Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | * Header file of an in-memory representation of DEX files. |
| 17 | */ |
| 18 | |
| 19 | #ifndef ART_DEXLAYOUT_DEX_WRITER_H_ |
| 20 | #define ART_DEXLAYOUT_DEX_WRITER_H_ |
| 21 | |
| 22 | #include "base/unix_file/fd_file.h" |
| 23 | #include "dex_ir.h" |
Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 24 | #include "mem_map.h" |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 25 | #include "os.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | class DexWriter { |
| 30 | public: |
Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 31 | DexWriter(dex_ir::Header* header, MemMap* mem_map) : header_(header), mem_map_(mem_map) { } |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 32 | |
Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 33 | static void Output(dex_ir::Header* header, MemMap* mem_map); |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 34 | |
| 35 | private: |
Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 36 | void WriteMemMap(); |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 37 | |
| 38 | size_t Write(const void* buffer, size_t length, size_t offset); |
| 39 | size_t WriteSleb128(uint32_t value, size_t offset); |
| 40 | size_t WriteUleb128(uint32_t value, size_t offset); |
| 41 | size_t WriteEncodedValue(dex_ir::EncodedValue* encoded_value, size_t offset); |
| 42 | size_t WriteEncodedValueHeader(int8_t value_type, size_t value_arg, size_t offset); |
| 43 | size_t WriteEncodedArray(dex_ir::EncodedValueVector* values, size_t offset); |
| 44 | size_t WriteEncodedAnnotation(dex_ir::EncodedAnnotation* annotation, size_t offset); |
| 45 | size_t WriteEncodedFields(dex_ir::FieldItemVector* fields, size_t offset); |
| 46 | size_t WriteEncodedMethods(dex_ir::MethodItemVector* methods, size_t offset); |
| 47 | |
| 48 | void WriteStrings(); |
| 49 | void WriteTypes(); |
| 50 | void WriteTypeLists(); |
| 51 | void WriteProtos(); |
| 52 | void WriteFields(); |
| 53 | void WriteMethods(); |
| 54 | void WriteEncodedArrays(); |
| 55 | void WriteAnnotations(); |
| 56 | void WriteAnnotationSets(); |
| 57 | void WriteAnnotationSetRefs(); |
| 58 | void WriteAnnotationsDirectories(); |
| 59 | void WriteDebugInfoItems(); |
| 60 | void WriteCodeItems(); |
| 61 | void WriteClasses(); |
| 62 | void WriteMapItem(); |
| 63 | void WriteHeader(); |
| 64 | |
Jeff Hao | ea7c629 | 2016-11-14 18:10:16 -0800 | [diff] [blame] | 65 | dex_ir::Header* const header_; |
| 66 | MemMap* const mem_map_; |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 67 | |
| 68 | DISALLOW_COPY_AND_ASSIGN(DexWriter); |
| 69 | }; |
| 70 | |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 71 | } // namespace art |
| 72 | |
| 73 | #endif // ART_DEXLAYOUT_DEX_WRITER_H_ |