Skip to content

Commit

Permalink
add some properties to Segment/Section protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
p-x9 committed Mar 23, 2024
1 parent 40a61a9 commit d0c5d59
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Sources/MachOKit/LoadCommand/Model/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import Foundation
public protocol SectionProtocol: LayoutWrapper {
var sectionName: String { get }
var segmentName: String { get }
var offset: Int { get }
var address: Int { get }
var size: Int { get }
var offset: Int { get }
var flags: SectionFlags { get }

var indirectSymbolIndex: Int? { get }
Expand Down Expand Up @@ -64,14 +65,18 @@ extension Section {
.init(tuple: layout.segname)
}

public var offset: Int {
numericCast(layout.offset)
public var address: Int {
numericCast(layout.addr)
}

public var size: Int {
numericCast(layout.size)
}

public var offset: Int {
numericCast(layout.offset)
}

public var flags: SectionFlags {
.init(rawValue: layout.flags)
}
Expand Down Expand Up @@ -118,14 +123,18 @@ extension Section64 {
.init(tuple: layout.segname)
}

public var offset: Int {
numericCast(layout.offset)
public var address: Int {
numericCast(layout.addr)
}

public var size: Int {
numericCast(layout.size)
}

public var offset: Int {
numericCast(layout.offset)
}

public var flags: SectionFlags {
.init(rawValue: layout.flags)
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/MachOKit/LoadCommand/SegmentCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public protocol SegmentCommandProtocol: LoadCommandWrapper {
var fileSize: Int { get }
var maxProtection: VMProtection { get }
var initialProtection: VMProtection { get }
var numberOfSections: Int { get }
var flags: SegmentCommandFlags { get }

func startPtr(vmaddrSlide: Int) -> UnsafeRawPointer?
Expand Down Expand Up @@ -76,6 +77,10 @@ public struct SegmentCommand: SegmentCommandProtocol {
.init(rawValue: layout.initprot)
}

public var numberOfSections: Int {
numericCast(layout.nsects)
}

public var flags: SegmentCommandFlags {
.init(rawValue: layout.flags)
}
Expand Down Expand Up @@ -121,6 +126,10 @@ public struct SegmentCommand64: SegmentCommandProtocol {
.init(rawValue: layout.initprot)
}

public var numberOfSections: Int {
numericCast(layout.nsects)
}

public var flags: SegmentCommandFlags {
.init(rawValue: layout.flags)
}
Expand Down

0 comments on commit d0c5d59

Please sign in to comment.