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 {
30
30
public init ( filePath: String ) throws {
31
31
self . filePath = filePath
32
32
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)
35
34
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 " )
40
39
}
41
40
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 " )
45
43
}
46
44
47
45
let ehdrSize = MemoryLayout< Elf64_Ehdr> . size
You can’t perform that action at this time.
0 commit comments