Lines Matching refs:dex
32 namespace dex { namespace
36 static dex::u4 OptIndex(const T* ir_node) { in OptIndex()
37 return ir_node != nullptr ? ir_node->index : dex::kNoIndex; in OptIndex()
41 static void WriteEncodedValueHeader(dex::u1 type, int arg, Section& data) { in WriteEncodedValueHeader()
42 assert((type & ~dex::kEncodedValueTypeMask) == 0); in WriteEncodedValueHeader()
44 dex::u1 header = dex::u1(type | (arg << dex::kEncodedValueArgShift)); in WriteEncodedValueHeader()
45 data.Push<dex::u1>(header); in WriteEncodedValueHeader()
50 static void WriteIntValue(dex::u1 type, T value, Section& data) { in WriteIntValue()
51 dex::u1 buff[sizeof(T)] = {}; in WriteIntValue()
52 dex::u1* dst = buff; in WriteIntValue()
76 static void WriteFloatValue(dex::u1 type, T value, Section& data) { in WriteFloatValue()
77 dex::u1 buff[sizeof(T)] = {}; in WriteFloatValue()
78 auto src = reinterpret_cast<const dex::u1*>(&value); in WriteFloatValue()
104 dex::u1 type = ir_value->type; in WriteEncodedValue()
106 case dex::kEncodedByte: in WriteEncodedValue()
110 case dex::kEncodedShort: in WriteEncodedValue()
114 case dex::kEncodedChar: in WriteEncodedValue()
118 case dex::kEncodedInt: in WriteEncodedValue()
122 case dex::kEncodedLong: in WriteEncodedValue()
126 case dex::kEncodedFloat: in WriteEncodedValue()
130 case dex::kEncodedDouble: in WriteEncodedValue()
134 case dex::kEncodedString: in WriteEncodedValue()
135 WriteIntValue<dex::u4>(type, ir_value->u.string_value->index, data); in WriteEncodedValue()
138 case dex::kEncodedType: in WriteEncodedValue()
139 WriteIntValue<dex::u4>(type, ir_value->u.type_value->index, data); in WriteEncodedValue()
142 case dex::kEncodedField: in WriteEncodedValue()
143 WriteIntValue<dex::u4>(type, ir_value->u.field_value->index, data); in WriteEncodedValue()
146 case dex::kEncodedMethod: in WriteEncodedValue()
147 WriteIntValue<dex::u4>(type, ir_value->u.method_value->index, data); in WriteEncodedValue()
150 case dex::kEncodedEnum: in WriteEncodedValue()
151 WriteIntValue<dex::u4>(type, ir_value->u.enum_value->index, data); in WriteEncodedValue()
154 case dex::kEncodedArray: in WriteEncodedValue()
159 case dex::kEncodedAnnotation: in WriteEncodedValue()
164 case dex::kEncodedNull: in WriteEncodedValue()
168 case dex::kEncodedBoolean: { in WriteEncodedValue()
181 case dex::kEncodedByte: in WriteEncodedValue()
182 case dex::kEncodedShort: in WriteEncodedValue()
183 case dex::kEncodedChar: in WriteEncodedValue()
184 case dex::kEncodedInt: in WriteEncodedValue()
185 case dex::kEncodedLong: in WriteEncodedValue()
186 case dex::kEncodedFloat: in WriteEncodedValue()
187 case dex::kEncodedDouble: in WriteEncodedValue()
188 case dex::kEncodedNull: in WriteEncodedValue()
189 case dex::kEncodedBoolean: in WriteEncodedValue()
190 auto ptr = data.ptr<const dex::u1>(offset); in WriteEncodedValue()
220 static void CopySection(const T& section, dex::u1* image, dex::u4 image_size) { in CopySection()
227 dex::u4 offset = section.SectionOffset(); in CopySection()
228 dex::u4 size = section.size(); in CopySection()
229 SLICER_CHECK(offset >= sizeof(dex::Header)); in CopySection()
244 dex::u1* Writer::CreateImage(Allocator* allocator, size_t* new_image_size) { in CreateImage()
257 dex::u4 offset = 0; in CreateImage()
261 offset += sizeof(dex::Header); in CreateImage()
271 const dex::u4 data_offset = offset; in CreateImage()
296 const dex::u4 image_size = offset; in CreateImage()
297 dex::u1* image = static_cast<dex::u1*>(allocator->Allocate(image_size)); in CreateImage()
305 SLICER_CHECK(image_size > sizeof(dex::Header)); in CreateImage()
307 dex::Header* header = reinterpret_cast<dex::Header*>(image + 0); in CreateImage()
313 header->header_size = sizeof(dex::Header); in CreateImage()
314 header->endian_tag = dex::kEndianConstant; in CreateImage()
355 header->checksum = dex::ComputeChecksum(header); in CreateImage()
362 dex::u4 Writer::CreateStringDataSection(dex::u4 section_offset) { in CreateStringDataSection()
371 dex::u4 offset = section.AddItem(); in CreateStringDataSection()
376 dex::u4 size = section.Seal(4); in CreateStringDataSection()
382 static void AddMapItem(const T& section, std::vector<dex::MapItem>& items) { in AddMapItem()
384 SLICER_CHECK(section.SectionOffset() >= sizeof(dex::Header)); in AddMapItem()
385 dex::MapItem map_item = {}; in AddMapItem()
394 dex::u4 Writer::CreateMapSection(dex::u4 section_offset) { in CreateMapSection()
399 std::vector<dex::MapItem> map_items; in CreateMapSection()
401 dex::MapItem headerItem = {}; in CreateMapSection()
402 headerItem.type = dex::kHeaderItem; in CreateMapSection()
426 [](const dex::MapItem& a, const dex::MapItem& b) { in CreateMapSection()
431 section.Push<dex::u4>(map_items.size()); in CreateMapSection()
437 dex::u4 Writer::CreateAnnItemSection(dex::u4 section_offset) { in CreateAnnItemSection()
441 if (ir_node->visibility != dex::kVisibilityEncoded) { in CreateAnnItemSection()
443 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnItemSection()
453 dex::u4 Writer::CreateAnnSetsSection(dex::u4 section_offset) { in CreateAnnSetsSection()
457 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetsSection()
466 dex::u4 Writer::CreateAnnSetRefListsSection(dex::u4 section_offset) { in CreateAnnSetRefListsSection()
470 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetRefListsSection()
479 dex::u4 Writer::CreateTypeListsSection(dex::u4 section_offset) { in CreateTypeListsSection()
483 dex::u4& offset = node_offset_[ir_type_list.get()]; in CreateTypeListsSection()
492 dex::u4 Writer::CreateCodeItemSection(dex::u4 section_offset) { in CreateCodeItemSection()
496 dex::u4& offset = node_offset_[ir_node.get()]; in CreateCodeItemSection()
501 dex::u4 size = dex_->code.Seal(4); in CreateCodeItemSection()
506 dex::u4 Writer::CreateDebugInfoSection(dex::u4 section_offset) { in CreateDebugInfoSection()
510 dex::u4& offset = node_offset_[ir_node.get()]; in CreateDebugInfoSection()
515 dex::u4 size = dex_->debug_info.Seal(4); in CreateDebugInfoSection()
520 dex::u4 Writer::CreateClassDataSection(dex::u4 section_offset) { in CreateClassDataSection()
530 dex::u4 size = dex_->class_data.Seal(4); in CreateClassDataSection()
535 dex::u4 Writer::CreateAnnDirectoriesSection(dex::u4 section_offset) { in CreateAnnDirectoriesSection()
549 dex::u4 Writer::CreateEncodedArrayItemSection(dex::u4 section_offset) { in CreateEncodedArrayItemSection()
631 dex::u4 Writer::WriteTypeList(const std::vector<ir::Type*>& types) { in WriteTypeList()
637 dex::u4 offset = data.AddItem(4); in WriteTypeList()
638 data.Push<dex::u4>(types.size()); in WriteTypeList()
640 data.Push<dex::u2>(ir_type->index); in WriteTypeList()
646 dex::u4 Writer::WriteAnnotationItem(const ir::Annotation* ir_annotation) { in WriteAnnotationItem()
647 SLICER_CHECK(ir_annotation->visibility != dex::kVisibilityEncoded); in WriteAnnotationItem()
650 dex::u4 offset = data.AddItem(); in WriteAnnotationItem()
651 data.Push<dex::u1>(ir_annotation->visibility); in WriteAnnotationItem()
657 dex::u4 Writer::WriteAnnotationSet(const ir::AnnotationSet* ir_annotation_set) { in WriteAnnotationSet()
663 dex::u4 offset = data.AddItem(4); in WriteAnnotationSet()
664 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSet()
666 data.Push<dex::u4>(FilePointer(ir_annotation)); in WriteAnnotationSet()
672 dex::u4 Writer::WriteAnnotationSetRefList( in WriteAnnotationSetRefList()
679 dex::u4 offset = data.AddItem(4); in WriteAnnotationSetRefList()
680 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSetRefList()
682 data.Push<dex::u4>(FilePointer(ir_annotation_set)); in WriteAnnotationSetRefList()
688 dex::u4 Writer::WriteClassAnnotations(const ir::Class* ir_class) { in WriteClassAnnotations()
695 dex::u4& offset = node_offset_[ir_annotations]; in WriteClassAnnotations()
701 std::vector<dex::FieldAnnotationsItem> dex_field_annotations; in WriteClassAnnotations()
702 std::vector<dex::MethodAnnotationsItem> dex_method_annotations; in WriteClassAnnotations()
703 std::vector<dex::ParameterAnnotationsItem> dex_param_annotations; in WriteClassAnnotations()
706 dex::FieldAnnotationsItem dex_item = {}; in WriteClassAnnotations()
713 dex::MethodAnnotationsItem dex_item = {}; in WriteClassAnnotations()
720 dex::ParameterAnnotationsItem dex_item = {}; in WriteClassAnnotations()
726 dex::u4 class_annotations_offset = in WriteClassAnnotations()
731 dex::AnnotationsDirectoryItem dex_annotations = {}; in WriteClassAnnotations()
749 dex::u4 Writer::WriteDebugInfo(const ir::DebugInfo* ir_debug_info) { in WriteDebugInfo()
753 dex::u4 offset = data.AddItem(); in WriteDebugInfo()
763 const dex::u1* src = ir_debug_info->data.ptr<dex::u1>(); in WriteDebugInfo()
764 dex::u1 opcode = 0; in WriteDebugInfo()
765 while ((opcode = *src++) != dex::DBG_END_SEQUENCE) { in WriteDebugInfo()
766 data.Push<dex::u1>(opcode); in WriteDebugInfo()
769 case dex::DBG_ADVANCE_PC: in WriteDebugInfo()
771 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
774 case dex::DBG_ADVANCE_LINE: in WriteDebugInfo()
776 data.PushSLeb128(dex::ReadSLeb128(&src)); in WriteDebugInfo()
779 case dex::DBG_START_LOCAL: { in WriteDebugInfo()
781 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
783 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
786 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
790 case dex::DBG_START_LOCAL_EXTENDED: { in WriteDebugInfo()
792 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
794 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
797 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
800 dex::u4 sig_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
804 case dex::DBG_END_LOCAL: in WriteDebugInfo()
805 case dex::DBG_RESTART_LOCAL: in WriteDebugInfo()
807 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
810 case dex::DBG_SET_FILE: { in WriteDebugInfo()
811 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
816 data.Push<dex::u1>(dex::DBG_END_SEQUENCE); in WriteDebugInfo()
822 void Writer::WriteInstructions(slicer::ArrayView<const dex::u2> instructions) { in WriteInstructions()
826 dex::u2* ptr = dex_->code.ptr<dex::u2>(offset); in WriteInstructions()
827 dex::u2* const end = ptr + instructions.size(); in WriteInstructions()
831 auto opcode = dex::OpcodeFromBytecode(*ptr); in WriteInstructions()
832 dex::u2* idx = &ptr[1]; in WriteInstructions()
835 switch (dex::GetFormatFromOpcode(opcode)) { in WriteInstructions()
836 case dex::k20bc: in WriteInstructions()
837 case dex::k21c: in WriteInstructions()
838 case dex::k35c: in WriteInstructions()
839 case dex::k3rc: in WriteInstructions()
840 case dex::k22c: in WriteInstructions()
844 case dex::k31c: in WriteInstructions()
852 switch (dex::GetIndexTypeFromOpcode(opcode)) { in WriteInstructions()
853 case dex::kIndexStringRef: in WriteInstructions()
855 dex::u4 new_index = MapStringIndex(ReadU4(idx)); in WriteInstructions()
856 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
860 dex::u4 new_index = MapStringIndex(*idx); in WriteInstructions()
861 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
862 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
863 *idx = dex::u2(new_index); in WriteInstructions()
867 case dex::kIndexTypeRef: { in WriteInstructions()
869 dex::u4 new_index = MapTypeIndex(*idx); in WriteInstructions()
870 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
871 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
872 *idx = dex::u2(new_index); in WriteInstructions()
875 case dex::kIndexFieldRef: { in WriteInstructions()
877 dex::u4 new_index = MapFieldIndex(*idx); in WriteInstructions()
878 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
879 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
880 *idx = dex::u2(new_index); in WriteInstructions()
883 case dex::kIndexMethodRef: { in WriteInstructions()
885 dex::u4 new_index = MapMethodIndex(*idx); in WriteInstructions()
886 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
887 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
888 *idx = dex::u2(new_index); in WriteInstructions()
895 auto isize = dex::GetWidthFromBytecode(ptr); in WriteInstructions()
908 auto original_list = irCode->catch_handlers.ptr<dex::u1>(); in WriteTryBlocks()
910 std::map<dex::u2, dex::u2> handlers_offset_map; in WriteTryBlocks()
912 dex::u4 handlers_count = dex::ReadULeb128(&ptr); in WriteTryBlocks()
915 for (dex::u4 handler_index = 0; handler_index < handlers_count; ++handler_index) { in WriteTryBlocks()
920 int catch_count = dex::ReadSLeb128(&ptr); in WriteTryBlocks()
925 dex::u4 type_index = dex::ReadULeb128(&ptr); in WriteTryBlocks()
929 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
934 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
942 dex::u4 tries_offset = data.size(); in WriteTryBlocks()
947 for (dex::TryBlock& dex_try : slicer::ArrayView<dex::TryBlock>( in WriteTryBlocks()
948 data.ptr<dex::TryBlock>(tries_offset), irCode->try_blocks.size())) { in WriteTryBlocks()
949 dex::u2 new_Handler_offset = handlers_offset_map[dex_try.handler_off]; in WriteTryBlocks()
956 dex::u4 Writer::WriteCode(const ir::Code* irCode) { in WriteCode()
959 dex::Code dex_code = {}; in WriteCode()
968 dex::u4 offset = data.AddItem(4); in WriteCode()
969 data.Push(&dex_code, offsetof(dex::Code, insns)); in WriteCode()
980 dex::u4* base_index) { in WriteEncodedField()
981 dex::u4 index_delta = ir_encoded_field->decl->index; in WriteEncodedField()
982 SLICER_CHECK(index_delta != dex::kNoIndex); in WriteEncodedField()
983 if (*base_index != dex::kNoIndex) { in WriteEncodedField()
996 dex::u4* base_index) { in WriteEncodedMethod()
997 dex::u4 index_delta = ir_encoded_method->decl->index; in WriteEncodedMethod()
998 SLICER_CHECK(index_delta != dex::kNoIndex); in WriteEncodedMethod()
999 if (*base_index != dex::kNoIndex) { in WriteEncodedMethod()
1005 dex::u4 code_offset = FilePointer(ir_encoded_method->code); in WriteEncodedMethod()
1014 dex::u4 Writer::WriteClassData(const ir::Class* ir_class) { in WriteClassData()
1021 dex::u4 offset = data.AddItem(); in WriteClassData()
1028 dex::u4 base_index = dex::kNoIndex; in WriteClassData()
1033 base_index = dex::kNoIndex; in WriteClassData()
1038 base_index = dex::kNoIndex; in WriteClassData()
1043 base_index = dex::kNoIndex; in WriteClassData()
1052 dex::u4 Writer::WriteClassStaticValues(const ir::Class* ir_class) { in WriteClassStaticValues()
1057 dex::u4& offset = node_offset_[ir_class->static_init]; in WriteClassStaticValues()
1068 dex::u4 Writer::MapStringIndex(dex::u4 index) const { in MapStringIndex()
1069 if (index != dex::kNoIndex) { in MapStringIndex()
1071 SLICER_CHECK(index != dex::kNoIndex); in MapStringIndex()
1077 dex::u4 Writer::MapTypeIndex(dex::u4 index) const { in MapTypeIndex()
1078 if (index != dex::kNoIndex) { in MapTypeIndex()
1080 SLICER_CHECK(index != dex::kNoIndex); in MapTypeIndex()
1086 dex::u4 Writer::MapFieldIndex(dex::u4 index) const { in MapFieldIndex()
1087 if (index != dex::kNoIndex) { in MapFieldIndex()
1089 SLICER_CHECK(index != dex::kNoIndex); in MapFieldIndex()
1095 dex::u4 Writer::MapMethodIndex(dex::u4 index) const { in MapMethodIndex()
1096 if (index != dex::kNoIndex) { in MapMethodIndex()
1098 SLICER_CHECK(index != dex::kNoIndex); in MapMethodIndex()
1104 dex::u4 Writer::FilePointer(const ir::Node* ir_node) const { in FilePointer()
1110 dex::u4 offset = it->second; in FilePointer()