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_GE(offset, dex::Header::kV40Size); in CopySection()
244 dex::u1* Writer::CreateImage(Allocator* allocator, size_t* new_image_size) { in CreateImage()
263 dex::u4 offset = 0; in CreateImage()
278 const dex::u4 data_offset = offset; in CreateImage()
304 const dex::u4 image_size = offset; in CreateImage()
305 dex::u1* image = static_cast<dex::u1*>(allocator->Allocate(image_size)); in CreateImage()
315 dex::Header* header = reinterpret_cast<dex::Header*>(image + 0); in CreateImage()
322 header->endian_tag = dex::kEndianConstant; in CreateImage()
369 header->checksum = dex::ComputeChecksum(header); in CreateImage()
376 dex::u4 Writer::CreateStringDataSection(dex::u4 section_offset) { in CreateStringDataSection()
385 dex::u4 offset = section.AddItem(); in CreateStringDataSection()
390 dex::u4 size = section.Seal(4); in CreateStringDataSection()
396 static void AddMapItem(const T& section, std::vector<dex::MapItem>& items) { in AddMapItem()
398 SLICER_CHECK_GE(section.SectionOffset(), dex::Header::kV40Size); in AddMapItem()
399 dex::MapItem map_item = {}; in AddMapItem()
408 dex::u4 Writer::CreateMapSection(dex::u4 section_offset) { in CreateMapSection()
413 std::vector<dex::MapItem> map_items; in CreateMapSection()
415 dex::MapItem headerItem = {}; in CreateMapSection()
416 headerItem.type = dex::kHeaderItem; in CreateMapSection()
441 [](const dex::MapItem& a, const dex::MapItem& b) { in CreateMapSection()
446 section.Push<dex::u4>(map_items.size()); in CreateMapSection()
452 dex::u4 Writer::CreateAnnItemSection(dex::u4 section_offset) { in CreateAnnItemSection()
456 if (ir_node->visibility != dex::kVisibilityEncoded) { in CreateAnnItemSection()
458 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnItemSection()
468 dex::u4 Writer::CreateAnnSetsSection(dex::u4 section_offset) { in CreateAnnSetsSection()
472 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetsSection()
481 dex::u4 Writer::CreateAnnSetRefListsSection(dex::u4 section_offset) { in CreateAnnSetRefListsSection()
485 dex::u4& offset = node_offset_[ir_node.get()]; in CreateAnnSetRefListsSection()
494 dex::u4 Writer::CreateTypeListsSection(dex::u4 section_offset) { in CreateTypeListsSection()
498 dex::u4& offset = node_offset_[ir_type_list.get()]; in CreateTypeListsSection()
507 dex::u4 Writer::CreateCodeItemSection(dex::u4 section_offset) { in CreateCodeItemSection()
511 dex::u4& offset = node_offset_[ir_node.get()]; in CreateCodeItemSection()
516 dex::u4 size = dex_->code.Seal(4); in CreateCodeItemSection()
521 dex::u4 Writer::CreateDebugInfoSection(dex::u4 section_offset) { in CreateDebugInfoSection()
525 dex::u4& offset = node_offset_[ir_node.get()]; in CreateDebugInfoSection()
530 dex::u4 size = dex_->debug_info.Seal(4); in CreateDebugInfoSection()
535 dex::u4 Writer::CreateClassDataSection(dex::u4 section_offset) { in CreateClassDataSection()
545 dex::u4 size = dex_->class_data.Seal(4); in CreateClassDataSection()
550 dex::u4 Writer::CreateAnnDirectoriesSection(dex::u4 section_offset) { in CreateAnnDirectoriesSection()
564 dex::u4 Writer::CreateEncodedArrayItemSection(dex::u4 section_offset) { in CreateEncodedArrayItemSection()
666 dex::u4 Writer::WriteTypeList(const std::vector<ir::Type*>& types) { in WriteTypeList()
672 dex::u4 offset = data.AddItem(4); in WriteTypeList()
673 data.Push<dex::u4>(types.size()); in WriteTypeList()
675 data.Push<dex::u2>(ir_type->index); in WriteTypeList()
681 dex::u4 Writer::WriteAnnotationItem(const ir::Annotation* ir_annotation) { in WriteAnnotationItem()
682 SLICER_CHECK_NE(ir_annotation->visibility, dex::kVisibilityEncoded); in WriteAnnotationItem()
685 dex::u4 offset = data.AddItem(); in WriteAnnotationItem()
686 data.Push<dex::u1>(ir_annotation->visibility); in WriteAnnotationItem()
692 dex::u4 Writer::WriteAnnotationSet(const ir::AnnotationSet* ir_annotation_set) { in WriteAnnotationSet()
698 dex::u4 offset = data.AddItem(4); in WriteAnnotationSet()
699 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSet()
701 data.Push<dex::u4>(FilePointer(ir_annotation)); in WriteAnnotationSet()
707 dex::u4 Writer::WriteAnnotationSetRefList( in WriteAnnotationSetRefList()
714 dex::u4 offset = data.AddItem(4); in WriteAnnotationSetRefList()
715 data.Push<dex::u4>(annotations.size()); in WriteAnnotationSetRefList()
717 data.Push<dex::u4>(FilePointer(ir_annotation_set)); in WriteAnnotationSetRefList()
723 dex::u4 Writer::WriteClassAnnotations(const ir::Class* ir_class) { in WriteClassAnnotations()
730 dex::u4& offset = node_offset_[ir_annotations]; in WriteClassAnnotations()
736 std::vector<dex::FieldAnnotationsItem> dex_field_annotations; in WriteClassAnnotations()
737 std::vector<dex::MethodAnnotationsItem> dex_method_annotations; in WriteClassAnnotations()
738 std::vector<dex::ParameterAnnotationsItem> dex_param_annotations; in WriteClassAnnotations()
741 dex::FieldAnnotationsItem dex_item = {}; in WriteClassAnnotations()
748 dex::MethodAnnotationsItem dex_item = {}; in WriteClassAnnotations()
755 dex::ParameterAnnotationsItem dex_item = {}; in WriteClassAnnotations()
761 dex::u4 class_annotations_offset = in WriteClassAnnotations()
766 dex::AnnotationsDirectoryItem dex_annotations = {}; in WriteClassAnnotations()
784 dex::u4 Writer::WriteDebugInfo(const ir::DebugInfo* ir_debug_info) { in WriteDebugInfo()
788 dex::u4 offset = data.AddItem(); in WriteDebugInfo()
798 const dex::u1* src = ir_debug_info->data.ptr<dex::u1>(); in WriteDebugInfo()
799 dex::u1 opcode = 0; in WriteDebugInfo()
800 while ((opcode = *src++) != dex::DBG_END_SEQUENCE) { in WriteDebugInfo()
801 data.Push<dex::u1>(opcode); in WriteDebugInfo()
804 case dex::DBG_ADVANCE_PC: in WriteDebugInfo()
806 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
809 case dex::DBG_ADVANCE_LINE: in WriteDebugInfo()
811 data.PushSLeb128(dex::ReadSLeb128(&src)); in WriteDebugInfo()
814 case dex::DBG_START_LOCAL: { in WriteDebugInfo()
816 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
818 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
821 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
825 case dex::DBG_START_LOCAL_EXTENDED: { in WriteDebugInfo()
827 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
829 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
832 dex::u4 type_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
835 dex::u4 sig_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
839 case dex::DBG_END_LOCAL: in WriteDebugInfo()
840 case dex::DBG_RESTART_LOCAL: in WriteDebugInfo()
842 data.PushULeb128(dex::ReadULeb128(&src)); in WriteDebugInfo()
845 case dex::DBG_SET_FILE: { in WriteDebugInfo()
846 dex::u4 name_index = dex::ReadULeb128(&src) - 1; in WriteDebugInfo()
851 data.Push<dex::u1>(dex::DBG_END_SEQUENCE); in WriteDebugInfo()
857 void Writer::WriteInstructions(slicer::ArrayView<const dex::u2> instructions) { in WriteInstructions()
861 dex::u2* ptr = dex_->code.ptr<dex::u2>(offset); in WriteInstructions()
862 dex::u2* const end = ptr + instructions.size(); in WriteInstructions()
866 auto opcode = dex::OpcodeFromBytecode(*ptr); in WriteInstructions()
867 dex::u2* idx = &ptr[1]; in WriteInstructions()
868 dex::u2* idx2 = nullptr; in WriteInstructions()
871 switch (dex::GetFormatFromOpcode(opcode)) { in WriteInstructions()
872 case dex::k20bc: in WriteInstructions()
873 case dex::k21c: in WriteInstructions()
874 case dex::k35c: in WriteInstructions()
875 case dex::k3rc: in WriteInstructions()
876 case dex::k22c: in WriteInstructions()
880 case dex::k31c: in WriteInstructions()
884 case dex::k45cc: in WriteInstructions()
885 case dex::k4rcc: in WriteInstructions()
894 switch (dex::GetIndexTypeFromOpcode(opcode)) { in WriteInstructions()
895 case dex::kIndexStringRef: in WriteInstructions()
897 dex::u4 new_index = MapStringIndex(ReadU4(idx)); in WriteInstructions()
898 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
902 dex::u4 new_index = MapStringIndex(*idx); in WriteInstructions()
903 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
904 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
905 *idx = dex::u2(new_index); in WriteInstructions()
909 case dex::kIndexTypeRef: { in WriteInstructions()
911 dex::u4 new_index = MapTypeIndex(*idx); in WriteInstructions()
912 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
913 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
914 *idx = dex::u2(new_index); in WriteInstructions()
917 case dex::kIndexFieldRef: { in WriteInstructions()
919 dex::u4 new_index = MapFieldIndex(*idx); in WriteInstructions()
920 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
921 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
922 *idx = dex::u2(new_index); in WriteInstructions()
925 case dex::kIndexMethodRef: { in WriteInstructions()
927 dex::u4 new_index = MapMethodIndex(*idx); in WriteInstructions()
928 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
929 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
930 *idx = dex::u2(new_index); in WriteInstructions()
933 case dex::kIndexMethodAndProtoRef: { in WriteInstructions()
935 dex::u4 new_index = MapMethodIndex(*idx); in WriteInstructions()
936 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
937 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
938 *idx = dex::u2(new_index); in WriteInstructions()
939 dex::u4 new_index2 = MapProtoIndex(*idx2); in WriteInstructions()
940 SLICER_CHECK_NE(new_index2, dex::kNoIndex); in WriteInstructions()
941 SLICER_CHECK_EQ(dex::u2(new_index2), new_index2); in WriteInstructions()
942 *idx2 = dex::u2(new_index2); in WriteInstructions()
945 case dex::kIndexMethodHandleRef: { in WriteInstructions()
947 dex::u4 new_index = MapMethodHandleIndex(*idx); in WriteInstructions()
948 SLICER_CHECK_NE(new_index, dex::kNoIndex); in WriteInstructions()
949 SLICER_CHECK_EQ(dex::u2(new_index), new_index); in WriteInstructions()
950 *idx = dex::u2(new_index); in WriteInstructions()
957 auto isize = dex::GetWidthFromBytecode(ptr); in WriteInstructions()
970 auto original_list = irCode->catch_handlers.ptr<dex::u1>(); in WriteTryBlocks()
972 std::map<dex::u2, dex::u2> handlers_offset_map; in WriteTryBlocks()
974 dex::u4 handlers_count = dex::ReadULeb128(&ptr); in WriteTryBlocks()
977 for (dex::u4 handler_index = 0; handler_index < handlers_count; ++handler_index) { in WriteTryBlocks()
982 int catch_count = dex::ReadSLeb128(&ptr); in WriteTryBlocks()
987 dex::u4 type_index = dex::ReadULeb128(&ptr); in WriteTryBlocks()
991 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
996 handlers_list.PushULeb128(dex::ReadULeb128(&ptr)); in WriteTryBlocks()
1004 dex::u4 tries_offset = data.size(); in WriteTryBlocks()
1009 for (dex::TryBlock& dex_try : slicer::ArrayView<dex::TryBlock>( in WriteTryBlocks()
1010 data.ptr<dex::TryBlock>(tries_offset), irCode->try_blocks.size())) { in WriteTryBlocks()
1011 dex::u2 new_Handler_offset = handlers_offset_map[dex_try.handler_off]; in WriteTryBlocks()
1018 dex::u4 Writer::WriteCode(const ir::Code* irCode) { in WriteCode()
1021 dex::Code dex_code = {}; in WriteCode()
1030 dex::u4 offset = data.AddItem(4); in WriteCode()
1031 data.Push(&dex_code, offsetof(dex::Code, insns)); in WriteCode()
1042 dex::u4* base_index) { in WriteEncodedField()
1043 dex::u4 index_delta = ir_encoded_field->decl->index; in WriteEncodedField()
1044 SLICER_CHECK_NE(index_delta, dex::kNoIndex); in WriteEncodedField()
1045 if (*base_index != dex::kNoIndex) { in WriteEncodedField()
1058 dex::u4* base_index) { in WriteEncodedMethod()
1059 dex::u4 index_delta = ir_encoded_method->decl->index; in WriteEncodedMethod()
1060 SLICER_CHECK_NE(index_delta, dex::kNoIndex); in WriteEncodedMethod()
1061 if (*base_index != dex::kNoIndex) { in WriteEncodedMethod()
1067 dex::u4 code_offset = FilePointer(ir_encoded_method->code); in WriteEncodedMethod()
1076 dex::u4 Writer::WriteClassData(const ir::Class* ir_class) { in WriteClassData()
1083 dex::u4 offset = data.AddItem(); in WriteClassData()
1090 dex::u4 base_index = dex::kNoIndex; in WriteClassData()
1095 base_index = dex::kNoIndex; in WriteClassData()
1100 base_index = dex::kNoIndex; in WriteClassData()
1105 base_index = dex::kNoIndex; in WriteClassData()
1114 dex::u4 Writer::WriteClassStaticValues(const ir::Class* ir_class) { in WriteClassStaticValues()
1119 dex::u4& offset = node_offset_[ir_class->static_init]; in WriteClassStaticValues()
1130 dex::u4 Writer::MapStringIndex(dex::u4 index) const { in MapStringIndex()
1131 if (index != dex::kNoIndex) { in MapStringIndex()
1133 SLICER_CHECK_NE(index, dex::kNoIndex); in MapStringIndex()
1139 dex::u4 Writer::MapTypeIndex(dex::u4 index) const { in MapTypeIndex()
1140 if (index != dex::kNoIndex) { in MapTypeIndex()
1142 SLICER_CHECK_NE(index, dex::kNoIndex); in MapTypeIndex()
1148 dex::u4 Writer::MapFieldIndex(dex::u4 index) const { in MapFieldIndex()
1149 if (index != dex::kNoIndex) { in MapFieldIndex()
1151 SLICER_CHECK_NE(index, dex::kNoIndex); in MapFieldIndex()
1157 dex::u4 Writer::MapMethodIndex(dex::u4 index) const { in MapMethodIndex()
1158 if (index != dex::kNoIndex) { in MapMethodIndex()
1160 SLICER_CHECK_NE(index, dex::kNoIndex); in MapMethodIndex()
1166 dex::u4 Writer::MapMethodHandleIndex(dex::u4 index) const { in MapMethodHandleIndex()
1167 if (index != dex::kNoIndex) { in MapMethodHandleIndex()
1169 SLICER_CHECK_NE(index, dex::kNoIndex); in MapMethodHandleIndex()
1175 dex::u4 Writer::MapProtoIndex(dex::u4 index) const { in MapProtoIndex()
1176 if (index != dex::kNoIndex) { in MapProtoIndex()
1178 SLICER_CHECK_NE(index, dex::kNoIndex); in MapProtoIndex()
1184 dex::u4 Writer::FilePointer(const ir::Node* ir_node) const { in FilePointer()
1190 dex::u4 offset = it->second; in FilePointer()