Lines Matching refs:dex
27 namespace dex { namespace
29 Reader::Reader(const dex::u1* image, size_t size) : image_(image), size_(size) { in Reader()
31 header_ = ptr<dex::Header>(0); in Reader()
36 dex_ir_->magic = slicer::MemView(header_, sizeof(dex::Header::magic)); in Reader()
39 slicer::ArrayView<const dex::ClassDef> Reader::ClassDefs() const { in ClassDefs()
40 return section<dex::ClassDef>(header_->class_defs_off, in ClassDefs()
44 slicer::ArrayView<const dex::StringId> Reader::StringIds() const { in StringIds()
45 return section<dex::StringId>(header_->string_ids_off, in StringIds()
49 slicer::ArrayView<const dex::TypeId> Reader::TypeIds() const { in TypeIds()
50 return section<dex::TypeId>(header_->type_ids_off, in TypeIds()
54 slicer::ArrayView<const dex::FieldId> Reader::FieldIds() const { in FieldIds()
55 return section<dex::FieldId>(header_->field_ids_off, in FieldIds()
59 slicer::ArrayView<const dex::MethodId> Reader::MethodIds() const { in MethodIds()
60 return section<dex::MethodId>(header_->method_ids_off, in MethodIds()
64 slicer::ArrayView<const dex::ProtoId> Reader::ProtoIds() const { in ProtoIds()
65 return section<dex::ProtoId>(header_->proto_ids_off, in ProtoIds()
69 const dex::MapList* Reader::DexMapList() const { in DexMapList()
70 return dataPtr<dex::MapList>(header_->map_off); in DexMapList()
73 const char* Reader::GetStringMUTF8(dex::u4 index) const { in GetStringMUTF8()
74 if (index == dex::kNoIndex) { in GetStringMUTF8()
77 const dex::u1* strData = GetStringData(index); in GetStringMUTF8()
78 dex::ReadULeb128(&strData); in GetStringMUTF8()
89 void Reader::CreateClassIr(dex::u4 index) { in CreateClassIr()
96 dex::u4 Reader::FindClassIndex(const char* class_descriptor) const { in FindClassIndex()
99 for (dex::u4 i = 0; i < classes.size(); ++i) { in FindClassIndex()
106 return dex::kNoIndex; in FindClassIndex()
121 ir::Class* Reader::GetClass(dex::u4 index) { in GetClass()
122 SLICER_CHECK(index != dex::kNoIndex); in GetClass()
138 ir::Type* Reader::GetType(dex::u4 index) { in GetType()
139 SLICER_CHECK(index != dex::kNoIndex); in GetType()
155 ir::FieldDecl* Reader::GetFieldDecl(dex::u4 index) { in GetFieldDecl()
156 SLICER_CHECK(index != dex::kNoIndex); in GetFieldDecl()
172 ir::MethodDecl* Reader::GetMethodDecl(dex::u4 index) { in GetMethodDecl()
173 SLICER_CHECK(index != dex::kNoIndex); in GetMethodDecl()
189 ir::Proto* Reader::GetProto(dex::u4 index) { in GetProto()
190 SLICER_CHECK(index != dex::kNoIndex); in GetProto()
206 ir::String* Reader::GetString(dex::u4 index) { in GetString()
207 SLICER_CHECK(index != dex::kNoIndex); in GetString()
221 ir::Class* Reader::ParseClass(dex::u4 index) { in ParseClass()
232 if (dex_class_def.superclass_idx != dex::kNoIndex) { in ParseClass()
236 if (dex_class_def.source_file_idx != dex::kNoIndex) { in ParseClass()
241 const dex::u1* class_data = dataPtr<dex::u1>(dex_class_def.class_data_off); in ParseClass()
243 dex::u4 static_fields_count = dex::ReadULeb128(&class_data); in ParseClass()
244 dex::u4 instance_fields_count = dex::ReadULeb128(&class_data); in ParseClass()
245 dex::u4 direct_methods_count = dex::ReadULeb128(&class_data); in ParseClass()
246 dex::u4 virtual_methods_count = dex::ReadULeb128(&class_data); in ParseClass()
248 dex::u4 base_index = dex::kNoIndex; in ParseClass()
249 for (dex::u4 i = 0; i < static_fields_count; ++i) { in ParseClass()
254 base_index = dex::kNoIndex; in ParseClass()
255 for (dex::u4 i = 0; i < instance_fields_count; ++i) { in ParseClass()
260 base_index = dex::kNoIndex; in ParseClass()
261 for (dex::u4 i = 0; i < direct_methods_count; ++i) { in ParseClass()
266 base_index = dex::kNoIndex; in ParseClass()
267 for (dex::u4 i = 0; i < virtual_methods_count; ++i) { in ParseClass()
280 ir::AnnotationsDirectory* Reader::ExtractAnnotations(dex::u4 offset) { in ExtractAnnotations()
292 auto dex_annotations = dataPtr<dex::AnnotationsDirectoryItem>(offset); in ExtractAnnotations()
297 const dex::u1* ptr = reinterpret_cast<const dex::u1*>(dex_annotations + 1); in ExtractAnnotations()
299 for (dex::u4 i = 0; i < dex_annotations->fields_size; ++i) { in ExtractAnnotations()
303 for (dex::u4 i = 0; i < dex_annotations->methods_size; ++i) { in ExtractAnnotations()
307 for (dex::u4 i = 0; i < dex_annotations->parameters_size; ++i) { in ExtractAnnotations()
314 ir::Annotation* Reader::ExtractAnnotationItem(dex::u4 offset) { in ExtractAnnotationItem()
320 auto dexAnnotationItem = dataPtr<dex::AnnotationItem>(offset); in ExtractAnnotationItem()
321 const dex::u1* ptr = dexAnnotationItem->annotation; in ExtractAnnotationItem()
328 ir::AnnotationSet* Reader::ExtractAnnotationSet(dex::u4 offset) { in ExtractAnnotationSet()
340 auto dex_annotation_set = dataPtr<dex::AnnotationSetItem>(offset); in ExtractAnnotationSet()
341 for (dex::u4 i = 0; i < dex_annotation_set->size; ++i) { in ExtractAnnotationSet()
350 ir::AnnotationSetRefList* Reader::ExtractAnnotationSetRefList(dex::u4 offset) { in ExtractAnnotationSetRefList()
353 auto dex_annotation_set_ref_list = dataPtr<dex::AnnotationSetRefList>(offset); in ExtractAnnotationSetRefList()
356 for (dex::u4 i = 0; i < dex_annotation_set_ref_list->size; ++i) { in ExtractAnnotationSetRefList()
357 dex::u4 entry_offset = dex_annotation_set_ref_list->list[i].annotations_off; in ExtractAnnotationSetRefList()
368 ir::FieldAnnotation* Reader::ParseFieldAnnotation(const dex::u1** pptr) { in ParseFieldAnnotation()
369 auto dex_field_annotation = reinterpret_cast<const dex::FieldAnnotationsItem*>(*pptr); in ParseFieldAnnotation()
378 *pptr += sizeof(dex::FieldAnnotationsItem); in ParseFieldAnnotation()
382 ir::MethodAnnotation* Reader::ParseMethodAnnotation(const dex::u1** pptr) { in ParseMethodAnnotation()
384 reinterpret_cast<const dex::MethodAnnotationsItem*>(*pptr); in ParseMethodAnnotation()
393 *pptr += sizeof(dex::MethodAnnotationsItem); in ParseMethodAnnotation()
397 ir::ParamAnnotation* Reader::ParseParamAnnotation(const dex::u1** pptr) { in ParseParamAnnotation()
399 reinterpret_cast<const dex::ParameterAnnotationsItem*>(*pptr); in ParseParamAnnotation()
408 *pptr += sizeof(dex::ParameterAnnotationsItem); in ParseParamAnnotation()
412 ir::EncodedField* Reader::ParseEncodedField(const dex::u1** pptr, dex::u4* base_index) { in ParseEncodedField()
415 auto field_index = dex::ReadULeb128(pptr); in ParseEncodedField()
416 SLICER_CHECK(field_index != dex::kNoIndex); in ParseEncodedField()
417 if (*base_index != dex::kNoIndex) { in ParseEncodedField()
424 ir_encoded_field->access_flags = dex::ReadULeb128(pptr); in ParseEncodedField()
432 static T ParseIntValue(const dex::u1** pptr, size_t size) { in ParseIntValue()
455 static T ParseFloatValue(const dex::u1** pptr, size_t size) { in ParseFloatValue()
461 for (dex::u1* p = reinterpret_cast<dex::u1*>(&value) + start_byte; size > 0; in ParseFloatValue()
468 ir::EncodedValue* Reader::ParseEncodedValue(const dex::u1** pptr) { in ParseEncodedValue()
473 dex::u1 header = *(*pptr)++; in ParseEncodedValue()
474 dex::u1 type = header & dex::kEncodedValueTypeMask; in ParseEncodedValue()
475 dex::u1 arg = header >> dex::kEncodedValueArgShift; in ParseEncodedValue()
480 case dex::kEncodedByte: in ParseEncodedValue()
484 case dex::kEncodedShort: in ParseEncodedValue()
488 case dex::kEncodedChar: in ParseEncodedValue()
492 case dex::kEncodedInt: in ParseEncodedValue()
496 case dex::kEncodedLong: in ParseEncodedValue()
500 case dex::kEncodedFloat: in ParseEncodedValue()
504 case dex::kEncodedDouble: in ParseEncodedValue()
508 case dex::kEncodedString: { in ParseEncodedValue()
509 dex::u4 index = ParseIntValue<dex::u4>(pptr, arg + 1); in ParseEncodedValue()
513 case dex::kEncodedType: { in ParseEncodedValue()
514 dex::u4 index = ParseIntValue<dex::u4>(pptr, arg + 1); in ParseEncodedValue()
518 case dex::kEncodedField: { in ParseEncodedValue()
519 dex::u4 index = ParseIntValue<dex::u4>(pptr, arg + 1); in ParseEncodedValue()
523 case dex::kEncodedMethod: { in ParseEncodedValue()
524 dex::u4 index = ParseIntValue<dex::u4>(pptr, arg + 1); in ParseEncodedValue()
528 case dex::kEncodedEnum: { in ParseEncodedValue()
529 dex::u4 index = ParseIntValue<dex::u4>(pptr, arg + 1); in ParseEncodedValue()
533 case dex::kEncodedArray: in ParseEncodedValue()
538 case dex::kEncodedAnnotation: in ParseEncodedValue()
543 case dex::kEncodedNull: in ParseEncodedValue()
547 case dex::kEncodedBoolean: in ParseEncodedValue()
561 ir::Annotation* Reader::ParseAnnotation(const dex::u1** pptr) { in ParseAnnotation()
564 dex::u4 type_index = dex::ReadULeb128(pptr); in ParseAnnotation()
565 dex::u4 elements_count = dex::ReadULeb128(pptr); in ParseAnnotation()
568 ir_annotation->visibility = dex::kVisibilityEncoded; in ParseAnnotation()
570 for (dex::u4 i = 0; i < elements_count; ++i) { in ParseAnnotation()
573 ir_element->name = GetString(dex::ReadULeb128(pptr)); in ParseAnnotation()
582 ir::EncodedArray* Reader::ParseEncodedArray(const dex::u1** pptr) { in ParseEncodedArray()
585 dex::u4 count = dex::ReadULeb128(pptr); in ParseEncodedArray()
586 for (dex::u4 i = 0; i < count; ++i) { in ParseEncodedArray()
593 ir::EncodedArray* Reader::ExtractEncodedArray(dex::u4 offset) { in ExtractEncodedArray()
601 auto ptr = dataPtr<dex::u1>(offset); in ExtractEncodedArray()
607 ir::DebugInfo* Reader::ExtractDebugInfo(dex::u4 offset) { in ExtractDebugInfo()
613 const dex::u1* ptr = dataPtr<dex::u1>(offset); in ExtractDebugInfo()
615 ir_debug_info->line_start = dex::ReadULeb128(&ptr); in ExtractDebugInfo()
618 dex::u4 param_count = dex::ReadULeb128(&ptr); in ExtractDebugInfo()
619 for (dex::u4 i = 0; i < param_count; ++i) { in ExtractDebugInfo()
620 dex::u4 name_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
622 (name_index == dex::kNoIndex) ? nullptr : GetString(name_index); in ExtractDebugInfo()
633 dex::u1 opcode = 0; in ExtractDebugInfo()
634 while ((opcode = *ptr++) != dex::DBG_END_SEQUENCE) { in ExtractDebugInfo()
636 case dex::DBG_ADVANCE_PC: in ExtractDebugInfo()
638 dex::ReadULeb128(&ptr); in ExtractDebugInfo()
641 case dex::DBG_ADVANCE_LINE: in ExtractDebugInfo()
643 dex::ReadSLeb128(&ptr); in ExtractDebugInfo()
646 case dex::DBG_START_LOCAL: { in ExtractDebugInfo()
648 dex::ReadULeb128(&ptr); in ExtractDebugInfo()
650 dex::u4 name_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
651 if (name_index != dex::kNoIndex) { in ExtractDebugInfo()
655 dex::u4 type_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
656 if (type_index != dex::kNoIndex) { in ExtractDebugInfo()
661 case dex::DBG_START_LOCAL_EXTENDED: { in ExtractDebugInfo()
663 dex::ReadULeb128(&ptr); in ExtractDebugInfo()
665 dex::u4 name_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
666 if (name_index != dex::kNoIndex) { in ExtractDebugInfo()
670 dex::u4 type_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
671 if (type_index != dex::kNoIndex) { in ExtractDebugInfo()
675 dex::u4 sig_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
676 if (sig_index != dex::kNoIndex) { in ExtractDebugInfo()
681 case dex::DBG_END_LOCAL: in ExtractDebugInfo()
682 case dex::DBG_RESTART_LOCAL: in ExtractDebugInfo()
684 dex::ReadULeb128(&ptr); in ExtractDebugInfo()
687 case dex::DBG_SET_FILE: { in ExtractDebugInfo()
688 dex::u4 name_index = dex::ReadULeb128(&ptr) - 1; in ExtractDebugInfo()
689 if (name_index != dex::kNoIndex) { in ExtractDebugInfo()
701 ir::Code* Reader::ExtractCode(dex::u4 offset) { in ExtractCode()
708 auto dex_code = dataPtr<dex::Code>(offset); in ExtractCode()
717 slicer::ArrayView<const dex::u2>(dex_code->insns, dex_code->insns_size); in ExtractCode()
728 dex::u4 aligned_count = (dex_code->insns_size + 1) / 2 * 2; in ExtractCode()
730 reinterpret_cast<const dex::TryBlock*>(dex_code->insns + aligned_count); in ExtractCode()
732 reinterpret_cast<const dex::u1*>(tries + dex_code->tries_size); in ExtractCode()
735 slicer::ArrayView<const dex::TryBlock>(tries, dex_code->tries_size); in ExtractCode()
740 dex::u4 handlers_count = dex::ReadULeb128(&ptr); in ExtractCode()
743 for (dex::u4 handler_index = 0; handler_index < handlers_count; ++handler_index) { in ExtractCode()
744 int catch_count = dex::ReadSLeb128(&ptr); in ExtractCode()
747 dex::u4 type_index = dex::ReadULeb128(&ptr); in ExtractCode()
751 dex::ReadULeb128(&ptr); in ExtractCode()
756 dex::ReadULeb128(&ptr); in ExtractCode()
768 ir::EncodedMethod* Reader::ParseEncodedMethod(const dex::u1** pptr, dex::u4* base_index) { in ParseEncodedMethod()
771 auto method_index = dex::ReadULeb128(pptr); in ParseEncodedMethod()
772 SLICER_CHECK(method_index != dex::kNoIndex); in ParseEncodedMethod()
773 if (*base_index != dex::kNoIndex) { in ParseEncodedMethod()
780 ir_encoded_method->access_flags = dex::ReadULeb128(pptr); in ParseEncodedMethod()
782 dex::u4 code_offset = dex::ReadULeb128(pptr); in ParseEncodedMethod()
791 ir::Type* Reader::ParseType(dex::u4 index) { in ParseType()
801 ir::FieldDecl* Reader::ParseFieldDecl(dex::u4 index) { in ParseFieldDecl()
813 ir::MethodDecl* Reader::ParseMethodDecl(dex::u4 index) { in ParseMethodDecl()
825 ir::TypeList* Reader::ExtractTypeList(dex::u4 offset) { in ExtractTypeList()
835 auto dex_type_list = dataPtr<dex::TypeList>(offset); in ExtractTypeList()
838 for (dex::u4 i = 0; i < dex_type_list->size; ++i) { in ExtractTypeList()
846 ir::Proto* Reader::ParseProto(dex::u4 index) { in ParseProto()
861 ir::String* Reader::ParseString(dex::u4 index) { in ParseString()
866 dex::ReadULeb128(&cstr); in ParseString()
878 void Reader::ParseInstructions(slicer::ArrayView<const dex::u2> code) { in ParseInstructions()
879 const dex::u2* ptr = code.begin(); in ParseInstructions()
881 auto dex_instr = dex::DecodeInstruction(ptr); in ParseInstructions()
883 dex::u4 index = dex::kNoIndex; in ParseInstructions()
884 switch (dex::GetFormatFromOpcode(dex_instr.opcode)) { in ParseInstructions()
885 case dex::k20bc: in ParseInstructions()
886 case dex::k21c: in ParseInstructions()
887 case dex::k31c: in ParseInstructions()
888 case dex::k35c: in ParseInstructions()
889 case dex::k3rc: in ParseInstructions()
893 case dex::k22c: in ParseInstructions()
902 case dex::kIndexStringRef: in ParseInstructions()
906 case dex::kIndexTypeRef: in ParseInstructions()
910 case dex::kIndexFieldRef: in ParseInstructions()
914 case dex::kIndexMethodRef: in ParseInstructions()
922 auto isize = dex::GetWidthFromBytecode(ptr); in ParseInstructions()
931 SLICER_CHECK(size_ > sizeof(dex::Header)); in ValidateHeader()
936 SLICER_CHECK(header_->header_size == sizeof(dex::Header)); in ValidateHeader()
937 SLICER_CHECK(header_->endian_tag == dex::kEndianConstant); in ValidateHeader()
971 auto map_list = ptr<dex::MapList>(header_->map_off); in ValidateHeader()
974 sizeof(dex::u4) + sizeof(dex::MapItem) * map_list->size; in ValidateHeader()