| 648 | } |
| 649 | |
| 650 | void ObjCProcessor::LoadProtocols(ObjCReader* reader, Ref<Section> listSection) |
| 651 | { |
| 652 | if (!listSection) |
| 653 | return; |
| 654 | auto size = listSection->GetEnd() - listSection->GetStart(); |
| 655 | if (size == 0) |
| 656 | return; |
| 657 | auto ptrSize = m_data->GetAddressSize(); |
| 658 | |
| 659 | auto listSectionStart = listSection->GetStart(); |
| 660 | auto listSectionEnd = listSection->GetEnd(); |
| 661 | |
| 662 | auto protocolType = Type::NamedType(m_data, m_typeNames.protocol); |
| 663 | auto ptrType = Type::PointerType(m_data->GetDefaultArchitecture(), protocolType); |
| 664 | for (size_t i = listSectionStart; i < listSectionEnd; i += ptrSize) |
| 665 | { |
| 666 | protocol_t protocol; |
| 667 | reader->Seek(i); |
| 668 | auto protocolLocation = ReadPointerAccountingForRelocations(reader); |
| 669 | reader->Seek(protocolLocation); |
| 670 | |
| 671 | try |
| 672 | { |
| 673 | protocol.isa = ReadPointerAccountingForRelocations(reader); |
| 674 | protocol.mangledName = ReadPointerAccountingForRelocations(reader); |
| 675 | protocol.protocols = ReadPointerAccountingForRelocations(reader); |
| 676 | protocol.instanceMethods = ReadPointerAccountingForRelocations(reader); |
| 677 | protocol.classMethods = ReadPointerAccountingForRelocations(reader); |
| 678 | protocol.optionalInstanceMethods = ReadPointerAccountingForRelocations(reader); |
| 679 | protocol.optionalClassMethods = ReadPointerAccountingForRelocations(reader); |
| 680 | protocol.instanceProperties = ReadPointerAccountingForRelocations(reader); |
| 681 | } |
| 682 | catch (...) |
| 683 | { |
| 684 | m_logger->LogError("Failed to read protocol pointed to by 0x%llx", i); |
| 685 | continue; |
| 686 | } |
| 687 | |
| 688 | std::string protocolName; |
| 689 | try |
| 690 | { |
| 691 | reader->Seek(protocol.mangledName); |
| 692 | protocolName = reader->ReadCString(); |
| 693 | DefineObjCSymbol(BNSymbolType::DataSymbol, |
| 694 | Type::ArrayType(Type::IntegerType(1, true), protocolName.size() + 1), "protocolName_" + protocolName, |
| 695 | protocol.mangledName, true); |
| 696 | } |
| 697 | catch (...) |
| 698 | { |
| 699 | m_logger->LogError( |
| 700 | "Failed to read protocol name for protocol at 0x%llx. Using base address as stand-in protocol name", |
| 701 | protocolLocation); |
| 702 | protocolName = std::to_string(protocolLocation); |
| 703 | } |
| 704 | |
| 705 | Protocol protocolClass; |
| 706 | protocolClass.name = protocolName; |
| 707 | DefineObjCSymbol(BNSymbolType::DataSymbol, ptrType, "protocolPtr_" + protocolName, i, true); |
nothing calls this directly
no test coverage detected