From f4e863bb1f1456ee8fad0b1fb719e6c421e65023 Mon Sep 17 00:00:00 2001 From: p-x9 <50244599+p-x9@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:18:42 +0900 Subject: [PATCH] Conform to `RandomAccessCollection` protocol --- Sources/MachOKit/MachOFile+CodeSign.swift | 2 +- Sources/MachOKit/MachOFile.swift | 6 +++--- Sources/MachOKit/MachOImage+CodeSign.swift | 2 +- .../Model/Codesign/CodeSignSuperBlob.swift | 8 ++++---- .../DyldCache/DyldCacheLocalSymbolsInfo.swift | 16 ++++++++-------- Sources/MachOKit/Protocol/CodeSignProtocol.swift | 2 +- .../MachOKit/Protocol/MachORepresentable.swift | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/MachOKit/MachOFile+CodeSign.swift b/Sources/MachOKit/MachOFile+CodeSign.swift index 1100a15..fda5c4f 100644 --- a/Sources/MachOKit/MachOFile+CodeSign.swift +++ b/Sources/MachOKit/MachOFile+CodeSign.swift @@ -134,7 +134,7 @@ extension MachOFile.CodeSign { public func blobIndices( of superBlob: CodeSignSuperBlob - ) -> AnySequence { + ) -> AnyRandomAccessCollection { superBlob.blobIndices(in: self) } } diff --git a/Sources/MachOKit/MachOFile.swift b/Sources/MachOKit/MachOFile.swift index a697df2..dde875f 100644 --- a/Sources/MachOKit/MachOFile.swift +++ b/Sources/MachOKit/MachOFile.swift @@ -355,7 +355,7 @@ extension MachOFile { } extension MachOFile { - public var dataInCode: AnySequence? { + public var dataInCode: AnyRandomAccessCollection? { guard let dataInCode = loadCommands.dataInCode, dataInCode.datasize > 0 else { return nil @@ -367,7 +367,7 @@ extension MachOFile { ) if isSwapped { - return AnySequence( + return AnyRandomAccessCollection( entries.lazy.map { DataInCodeEntry( layout: .init( @@ -380,7 +380,7 @@ extension MachOFile { ) } - return AnySequence(entries) + return AnyRandomAccessCollection(entries) } } diff --git a/Sources/MachOKit/MachOImage+CodeSign.swift b/Sources/MachOKit/MachOImage+CodeSign.swift index d881974..79d7034 100644 --- a/Sources/MachOKit/MachOImage+CodeSign.swift +++ b/Sources/MachOKit/MachOImage+CodeSign.swift @@ -165,7 +165,7 @@ extension MachOImage.CodeSign { public func blobIndices( of superBlob: CodeSignSuperBlob - ) -> AnySequence { + ) -> AnyRandomAccessCollection { superBlob.blobIndices(in: self) } } diff --git a/Sources/MachOKit/Model/Codesign/CodeSignSuperBlob.swift b/Sources/MachOKit/Model/Codesign/CodeSignSuperBlob.swift index 48a03b5..0f5e68e 100644 --- a/Sources/MachOKit/Model/Codesign/CodeSignSuperBlob.swift +++ b/Sources/MachOKit/Model/Codesign/CodeSignSuperBlob.swift @@ -32,10 +32,10 @@ extension CodeSignSuperBlob { /// - Returns: indices of this superBlob public func blobIndices( in signature: MachOFile.CodeSign - ) -> AnySequence { + ) -> AnyRandomAccessCollection { let offset = offset + layoutSize - return AnySequence( + return AnyRandomAccessCollection( DataSequence( data: signature.data.advanced(by: offset), numberOfElements: count @@ -50,10 +50,10 @@ extension CodeSignSuperBlob { /// - Returns: indices of this superBlob public func blobIndices( in signature: MachOImage.CodeSign - ) -> AnySequence { + ) -> AnyRandomAccessCollection { let offset = offset + layoutSize - return AnySequence( + return AnyRandomAccessCollection( MemorySequence( basePointer: signature.basePointer .advanced(by: offset) diff --git a/Sources/MachOKit/Model/DyldCache/DyldCacheLocalSymbolsInfo.swift b/Sources/MachOKit/Model/DyldCache/DyldCacheLocalSymbolsInfo.swift index 5b075bf..c59214c 100644 --- a/Sources/MachOKit/Model/DyldCache/DyldCacheLocalSymbolsInfo.swift +++ b/Sources/MachOKit/Model/DyldCache/DyldCacheLocalSymbolsInfo.swift @@ -57,13 +57,13 @@ extension DyldCacheLocalSymbolsInfo { ) } - public func symbols(in cache: DyldCache) -> AnySequence { + public func symbols(in cache: DyldCache) -> AnyRandomAccessCollection { if let symbols64 = symbols64(in: cache) { - return AnySequence(symbols64) + return AnyRandomAccessCollection(symbols64) } else if let symbols32 = symbols32(in: cache) { - return AnySequence(symbols32) + return AnyRandomAccessCollection(symbols32) } else { - return AnySequence([]) + return AnyRandomAccessCollection([]) } } } @@ -96,21 +96,21 @@ extension DyldCacheLocalSymbolsInfo { public func entries( in cache: DyldCache - ) -> AnySequence { + ) -> AnyRandomAccessCollection { if let entries = entries64(in: cache) { - return AnySequence( + return AnyRandomAccessCollection( entries .lazy .map { $0 as DyldCacheLocalSymbolsEntryProtocol } ) } else if let entries = entries32(in: cache) { - return AnySequence( + return AnyRandomAccessCollection( entries .lazy .map { $0 as DyldCacheLocalSymbolsEntryProtocol } ) } else { - return AnySequence([]) + return AnyRandomAccessCollection([]) } } } diff --git a/Sources/MachOKit/Protocol/CodeSignProtocol.swift b/Sources/MachOKit/Protocol/CodeSignProtocol.swift index 37f92b5..da34e96 100644 --- a/Sources/MachOKit/Protocol/CodeSignProtocol.swift +++ b/Sources/MachOKit/Protocol/CodeSignProtocol.swift @@ -39,7 +39,7 @@ public protocol CodeSignProtocol { /// - Returns: indices of superBlob func blobIndices( of superBlob: CodeSignSuperBlob - ) -> AnySequence + ) -> AnyRandomAccessCollection } extension CodeSignProtocol { diff --git a/Sources/MachOKit/Protocol/MachORepresentable.swift b/Sources/MachOKit/Protocol/MachORepresentable.swift index 528865c..02f5536 100644 --- a/Sources/MachOKit/Protocol/MachORepresentable.swift +++ b/Sources/MachOKit/Protocol/MachORepresentable.swift @@ -19,7 +19,7 @@ public protocol MachORepresentable { associatedtype ExportTrieEntries: Sequence associatedtype Strings: Sequence associatedtype FunctionStarts: Sequence - associatedtype DataInCode: Sequence + associatedtype DataInCode: RandomAccessCollection associatedtype DyldChainedFixups: DyldChainedFixupsProtocol associatedtype CodeSign: CodeSignProtocol