File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed
tools/swift-inspect/Sources/SwiftInspectLinux Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -30,18 +30,16 @@ class ElfFile {
3030 public init ( filePath: String ) throws {
3131 self . filePath = filePath
3232
33- let fileData = try Data ( contentsOf: URL ( fileURLWithPath: filePath) , options: . alwaysMapped)
34- self . fileData = fileData
33+ self . fileData = try Data ( contentsOf: URL ( fileURLWithPath: filePath) , options: . alwaysMapped)
3534
36- let identLen = Int ( EI_NIDENT)
37- let identMagic = String ( bytes : fileData [ 0 ..< identLen ] . prefix ( Int ( SELFMAG ) ) , encoding : . utf8 )
38- guard identMagic == ELFMAG else {
39- throw ELFError . notELF64 ( filePath)
35+ let ident = fileData . prefix ( upTo : Int ( EI_NIDENT) )
36+
37+ guard String ( bytes : ident . prefix ( Int ( SELFMAG ) ) , encoding : . utf8 ) == ELFMAG else {
38+ throw ELFError . notELF64 ( filePath, " \( ident . prefix ( Int ( SELFMAG ) ) ) != ELFMAG " )
4039 }
4140
42- let identClass = fileData [ Int ( EI_CLASS) ]
43- guard identClass == ELFCLASS64 else {
44- throw ELFError . notELF64 ( filePath, " \( identClass) != ELFCLASS64 " )
41+ guard ident [ Int ( EI_CLASS) ] == ELFCLASS64 else {
42+ throw ELFError . notELF64 ( filePath, " \( ident [ Int ( EI_CLASS) ] ) != ELFCLASS64 " )
4543 }
4644
4745 let ehdrSize = MemoryLayout< Elf64_Ehdr> . size
You can’t perform that action at this time.
0 commit comments