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()
237 dex::u1* Writer::CreateImage(Allocator* allocator, size_t* new_image_size) { in CreateImage()
250 dex::u4 offset = 0; in CreateImage()
254 offset += sizeof(dex::Header); in CreateImage()
264 const dex::u4 data_offset = offset; in CreateImage()
289 const dex::u4 image_size = offset; in CreateImage()
290 dex::u1* image = static_cast<dex::u1*>(allocator->Allocate(image_size)); in CreateImage()
298 SLICER_CHECK(image_size > sizeof(dex::Header)); in CreateImage()
300 dex::Header* header = reinterpret_cast<dex::Header*>(image + 0); in CreateImage()
306 header->header_size = sizeof(dex::Header); in CreateImage()
307 header->endian_tag = dex::kEndianConstant; in CreateImage()
348 header->checksum = dex::ComputeChecksum(header); in CreateImage()
355 dex::u4 Writer::CreateStringDataSection(dex::u4 section_offset) { in CreateStringDataSection()
364 dex::u4 offset = section.AddItem(); in CreateStringDataSection()
369 dex::u4 size = section.Seal(4); in CreateStringDataSection()
375 static void AddMapItem(const T& section, std::vector<dex::MapItem>& items) { in AddMapItem()
377 SLICER_CHECK(section.SectionOffset() >= sizeof(dex::Header)); in AddMapItem()
378 dex::MapItem map_item = {}; in AddMapItem()
387 dex::u4 Writer::CreateMapSection(dex::u4 section_offset) { in CreateMapSection()
392 std::vector<dex::MapItem> map_items; in CreateMapSection()
394 dex::MapItem headerItem = {}; in CreateMapSection()
395 headerItem.type = dex::kHeaderItem; in CreateMapSection()
419 [](const dex::MapItem& a, const dex::MapItem& b) { in CreateMapSection()
424 section.Push<dex::u4>(map_items.size()); in CreateMapSection()
430 dex::u4 Writer::CreateAnnItemSection(dex::u4 section_offset) { in CreateAnnItemSection()
434 if (ir_node->visibility != dex::kVisibilityEncoded) { in CreateAnnItemSection()
436 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnItemSection()
446 dex::u4 Writer::CreateAnnSetsSection(dex::u4 section_offset) { in CreateAnnSetsSection()
450 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetsSection()
459 dex::u4 Writer::CreateAnnSetRefListsSection(dex::u4 section_offset) { in CreateAnnSetRefListsSection()
463 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetRefListsSection()
472 dex::u4 Writer::CreateTypeListsSection(dex::u4 section_offset) { in CreateTypeListsSection()
476 dex::u4& offset = node_offset_[ir_type_list.get()]; in CreateTypeListsSection()
485 dex::u4 Writer::CreateCodeItemSection(dex::u4 section_offset) { in CreateCodeItemSection()
489 dex::u4& offset = node_offset_[ir_node.get()]; in CreateCodeItemSection()
494 dex::u4 size = dex_->code.Seal(4); in CreateCodeItemSection()
499 dex::u4 Writer::CreateDebugInfoSection(dex::u4 section_offset) { in CreateDebugInfoSection()
503 dex::u4& offset = node_offset_[ir_node.get()]; in CreateDebugInfoSection()
508 dex::u4 size = dex_->debug_info.Seal(4); in CreateDebugInfoSection()
513 dex::u4 Writer::CreateClassDataSection(dex::u4 section_offset) { in CreateClassDataSection()
523 dex::u4 size = dex_->class_data.Seal(4); in CreateClassDataSection()
528 dex::u4 Writer::CreateAnnDirectoriesSection(dex::u4 section_offset) { in CreateAnnDirectoriesSection()
542 dex::u4 Writer::CreateEncodedArrayItemSection(dex::u4 section_offset) { in CreateEncodedArrayItemSection()
624 dex::u4 Writer::WriteTypeList(const std::vector<ir::Type*>& types) { in WriteTypeList()
630 dex::u4 offset = data.AddItem(4); in WriteTypeList()
631 data.Push<dex::u4>(types.size()); in WriteTypeList()
633 data.Push<dex::u2>(ir_type->index); in WriteTypeList()
639 dex::u4 Writer::WriteAnnotationItem(const ir::Annotation* ir_annotation) { in WriteAnnotationItem()
640 SLICER_CHECK(ir_annotation->visibility != dex::kVisibilityEncoded); in WriteAnnotationItem()
643 dex::u4 offset = data.AddItem(); in WriteAnnotationItem()
644 data.Push<dex::u1>(ir_annotation->visibility); in WriteAnnotationItem()
650 dex::u4 Writer::WriteAnnotationSet(const ir::AnnotationSet* ir_annotation_set) { in WriteAnnotationSet()
656 dex::u4 offset = data.AddItem(4); in WriteAnnotationSet()
657 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSet()
659 data.Push<dex::u4>(FilePointer(ir_annotation)); in WriteAnnotationSet()
665 dex::u4 Writer::WriteAnnotationSetRefList( in WriteAnnotationSetRefList()
672 dex::u4 offset = data.AddItem(4); in WriteAnnotationSetRefList()
673 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSetRefList()
675 data.Push<dex::u4>(FilePointer(ir_annotation_set)); in WriteAnnotationSetRefList()
681 dex::u4 Writer::WriteClassAnnotations(const ir::Class* ir_class) { in WriteClassAnnotations()
688 dex::u4& offset = node_offset_[ir_annotations]; in WriteClassAnnotations()
694 std::vector<dex::FieldAnnotationsItem> dex_field_annotations; in WriteClassAnnotations()
695 std::vector<dex::MethodAnnotationsItem> dex_method_annotations; in WriteClassAnnotations()
696 std::vector<dex::ParameterAnnotationsItem> dex_param_annotations; in WriteClassAnnotations()
699 dex::FieldAnnotationsItem dex_item = {}; in WriteClassAnnotations()
706 dex::MethodAnnotationsItem dex_item = {}; in WriteClassAnnotations()
713 dex::ParameterAnnotationsItem dex_item = {}; in WriteClassAnnotations()
719 dex::u4 class_annotations_offset = in WriteClassAnnotations()
724 dex::AnnotationsDirectoryItem dex_annotations = {}; in WriteClassAnnotations()
742 dex::u4 Writer::WriteDebugInfo(const ir::DebugInfo* ir_debug_info) { in WriteDebugInfo()
746 dex::u4 offset = data.AddItem(); in WriteDebugInfo()
756 const dex::u1* src = ir_debug_info->data.ptr<dex::u1>(); in WriteDebugInfo()
757 dex::u1 opcode = 0; in WriteDebugInfo()
758 while ((opcode = *src++) != dex::DBG_END_SEQUENCE) { in WriteDebugInfo()
759 data.Push<dex::u1>(opcode); in WriteDebugInfo()
762 case dex::DBG_ADVANCE_PC: in WriteDebugInfo()
764 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
767 case dex::DBG_ADVANCE_LINE: in WriteDebugInfo()
769 data.PushSLeb128(dex::ReadSLeb128(&src)); in WriteDebugInfo()
772 case dex::DBG_START_LOCAL: { in WriteDebugInfo()
774 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
776 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
779 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
783 case dex::DBG_START_LOCAL_EXTENDED: { in WriteDebugInfo()
785 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
787 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
790 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
793 dex::u4 sig_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
797 case dex::DBG_END_LOCAL: in WriteDebugInfo()
798 case dex::DBG_RESTART_LOCAL: in WriteDebugInfo()
800 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
803 case dex::DBG_SET_FILE: { in WriteDebugInfo()
804 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
809 data.Push<dex::u1>(dex::DBG_END_SEQUENCE); in WriteDebugInfo()
815 void Writer::WriteInstructions(slicer::ArrayView<const dex::u2> instructions) { in WriteInstructions()
819 dex::u2* ptr = dex_->code.ptr<dex::u2>(offset); in WriteInstructions()
820 dex::u2* const end = ptr + instructions.size(); in WriteInstructions()
824 auto opcode = dex::OpcodeFromBytecode(*ptr); in WriteInstructions()
826 dex::u2* index16 = nullptr; in WriteInstructions()
827 dex::u4* index32 = nullptr; in WriteInstructions()
829 switch (dex::GetFormatFromOpcode(opcode)) { in WriteInstructions()
830 case dex::kFmt20bc: in WriteInstructions()
831 case dex::kFmt21c: in WriteInstructions()
832 case dex::kFmt35c: in WriteInstructions()
833 case dex::kFmt3rc: in WriteInstructions()
834 case dex::kFmt22c: in WriteInstructions()
838 case dex::kFmt31c: in WriteInstructions()
839 index32 = reinterpret_cast<dex::u4*>(&ptr[1]); in WriteInstructions()
846 switch (dex::GetIndexTypeFromOpcode(opcode)) { in WriteInstructions()
847 case dex::kIndexStringRef: in WriteInstructions()
850 dex::u4 new_index = MapStringIndex(*index32); in WriteInstructions()
851 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
854 dex::u4 new_index = MapStringIndex(*index16); in WriteInstructions()
855 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
856 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
857 *index16 = dex::u2(new_index); in WriteInstructions()
861 case dex::kIndexTypeRef: { in WriteInstructions()
863 dex::u4 new_index = MapTypeIndex(*index16); in WriteInstructions()
864 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
865 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
866 *index16 = dex::u2(new_index); in WriteInstructions()
869 case dex::kIndexFieldRef: { in WriteInstructions()
871 dex::u4 new_index = MapFieldIndex(*index16); in WriteInstructions()
872 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
873 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
874 *index16 = dex::u2(new_index); in WriteInstructions()
877 case dex::kIndexMethodRef: { in WriteInstructions()
879 dex::u4 new_index = MapMethodIndex(*index16); in WriteInstructions()
880 SLICER_CHECK(new_index != dex::kNoIndex); in WriteInstructions()
881 SLICER_CHECK(dex::u2(new_index) == new_index); in WriteInstructions()
882 *index16 = dex::u2(new_index); in WriteInstructions()
889 auto isize = dex::GetWidthFromBytecode(ptr); in WriteInstructions()
902 auto original_list = irCode->catch_handlers.ptr<dex::u1>(); in WriteTryBlocks()
904 std::map<dex::u2, dex::u2> handlers_offset_map; in WriteTryBlocks()
906 dex::u4 handlers_count = dex::ReadULeb128(&ptr); in WriteTryBlocks()
909 for (dex::u4 handler_index = 0; handler_index < handlers_count; ++handler_index) { in WriteTryBlocks()
914 int catch_count = dex::ReadSLeb128(&ptr); in WriteTryBlocks()
919 dex::u4 type_index = dex::ReadULeb128(&ptr); in WriteTryBlocks()
923 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
928 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
936 dex::u4 tries_offset = data.size(); in WriteTryBlocks()
941 for (dex::TryBlock& dex_try : slicer::ArrayView<dex::TryBlock>( in WriteTryBlocks()
942 data.ptr<dex::TryBlock>(tries_offset), irCode->try_blocks.size())) { in WriteTryBlocks()
943 dex::u2 new_Handler_offset = handlers_offset_map[dex_try.handler_off]; in WriteTryBlocks()
950 dex::u4 Writer::WriteCode(const ir::Code* irCode) { in WriteCode()
953 dex::Code dex_code = {}; in WriteCode()
962 dex::u4 offset = data.AddItem(4); in WriteCode()
963 data.Push(&dex_code, offsetof(dex::Code, insns)); in WriteCode()
974 dex::u4* base_index) { in WriteEncodedField()
975 dex::u4 index_delta = ir_encoded_field->decl->index; in WriteEncodedField()
976 SLICER_CHECK(index_delta != dex::kNoIndex); in WriteEncodedField()
977 if (*base_index != dex::kNoIndex) { in WriteEncodedField()
990 dex::u4* base_index) { in WriteEncodedMethod()
991 dex::u4 index_delta = ir_encoded_method->decl->index; in WriteEncodedMethod()
992 SLICER_CHECK(index_delta != dex::kNoIndex); in WriteEncodedMethod()
993 if (*base_index != dex::kNoIndex) { in WriteEncodedMethod()
999 dex::u4 code_offset = FilePointer(ir_encoded_method->code); in WriteEncodedMethod()
1008 dex::u4 Writer::WriteClassData(const ir::Class* ir_class) { in WriteClassData()
1015 dex::u4 offset = data.AddItem(); in WriteClassData()
1022 dex::u4 base_index = dex::kNoIndex; in WriteClassData()
1027 base_index = dex::kNoIndex; in WriteClassData()
1032 base_index = dex::kNoIndex; in WriteClassData()
1037 base_index = dex::kNoIndex; in WriteClassData()
1046 dex::u4 Writer::WriteClassStaticValues(const ir::Class* ir_class) { in WriteClassStaticValues()
1051 dex::u4& offset = node_offset_[ir_class->static_init]; in WriteClassStaticValues()
1062 dex::u4 Writer::MapStringIndex(dex::u4 index) const { in MapStringIndex()
1063 if (index != dex::kNoIndex) { in MapStringIndex()
1065 SLICER_CHECK(index != dex::kNoIndex); in MapStringIndex()
1071 dex::u4 Writer::MapTypeIndex(dex::u4 index) const { in MapTypeIndex()
1072 if (index != dex::kNoIndex) { in MapTypeIndex()
1074 SLICER_CHECK(index != dex::kNoIndex); in MapTypeIndex()
1080 dex::u4 Writer::MapFieldIndex(dex::u4 index) const { in MapFieldIndex()
1081 if (index != dex::kNoIndex) { in MapFieldIndex()
1083 SLICER_CHECK(index != dex::kNoIndex); in MapFieldIndex()
1089 dex::u4 Writer::MapMethodIndex(dex::u4 index) const { in MapMethodIndex()
1090 if (index != dex::kNoIndex) { in MapMethodIndex()
1092 SLICER_CHECK(index != dex::kNoIndex); in MapMethodIndex()
1098 dex::u4 Writer::FilePointer(const ir::Node* ir_node) const { in FilePointer()
1104 dex::u4 offset = it->second; in FilePointer()