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" 24 #include "mem_map.h" 25 #include "os.h" 26 27 namespace art { 28 29 class DexWriter { 30 public: DexWriter(dex_ir::Header * header,MemMap * mem_map)31 DexWriter(dex_ir::Header* header, MemMap* mem_map) : header_(header), mem_map_(mem_map) { } 32 33 static void Output(dex_ir::Header* header, MemMap* mem_map); 34 35 private: 36 void WriteMemMap(); 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 WriteCallSites(); 63 void WriteMethodHandles(); 64 void WriteMapItem(); 65 void WriteHeader(); 66 67 dex_ir::Header* const header_; 68 MemMap* const mem_map_; 69 70 DISALLOW_COPY_AND_ASSIGN(DexWriter); 71 }; 72 73 } // namespace art 74 75 #endif // ART_DEXLAYOUT_DEX_WRITER_H_ 76