Skip to content

Commit

Permalink
feat: add SEP load command support #61 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop authored Jun 9, 2024
1 parent d5348c2 commit 7eb5830
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 11 deletions.
51 changes: 51 additions & 0 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,57 @@ type AtomInfo struct {
LinkEditData
}

/*******************************************************************************
* LC_SEP_CACHE_SLIDE
*******************************************************************************/

type SepCacheSlide struct {
LoadBytes
types.SepCacheSlideCmd
}

func (l *SepCacheSlide) LoadSize() uint32 {
return uint32(binary.Size(l.SepCacheSlideCmd))
}
func (l *SepCacheSlide) Write(buf *bytes.Buffer, o binary.ByteOrder) error {
if err := binary.Write(buf, o, l.SepCacheSlideCmd); err != nil {
return fmt.Errorf("failed to write %s to buffer: %v", l.Command(), err)
}
return nil
}
func (l *SepCacheSlide) String() string {
return fmt.Sprintf("slide=0x%09x", (l.Offset&0xFFFFF)-0x8000)
}
func (l *SepCacheSlide) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
LoadCmd string `json:"load_cmd"`
Len uint32 `json:"length"`
Offset uint32 `json:"offset"`
Size uint32 `json:"size"`
}{
LoadCmd: l.Command().String(),
Len: l.Len,
Offset: l.Offset,
Size: l.Size,
})
}

/*******************************************************************************
* LC_SEP_UNKNOWN_2
*******************************************************************************/

type SepUnknown2 struct {
LinkEditData
}

/*******************************************************************************
* LC_SEP_UNKNOWN_3
*******************************************************************************/

type SepUnknown3 struct {
LinkEditData
}

/*******************************************************************************
* COMMON COMMANDS
*******************************************************************************/
Expand Down
39 changes: 39 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,45 @@ func NewFile(r io.ReaderAt, config ...FileConfig) (*File, error) {
l.Offset = led.Offset
l.Size = led.Size
f.Loads = append(f.Loads, l)
case types.LC_SEP_CACHE_SLIDE:
var led types.LinkEditDataCmd
b := bytes.NewReader(cmddat)
if err := binary.Read(b, bo, &led); err != nil {
return nil, fmt.Errorf("failed to read LC_SEP_CACHE_SLIDE: %v", err)
}
l := new(SepCacheSlide)
l.LoadBytes = cmddat
l.LoadCmd = cmd
l.Len = siz
l.Offset = led.Offset
l.Size = led.Size
f.Loads = append(f.Loads, l)
case types.LC_SEP_UNKNOWN_2:
var led types.SepUnknown2Cmd
b := bytes.NewReader(cmddat)
if err := binary.Read(b, bo, &led); err != nil {
return nil, fmt.Errorf("failed to read LC_SEP_UNKNOWN_2: %v", err)
}
l := new(SepUnknown2)
l.LoadBytes = cmddat
l.LoadCmd = cmd
l.Len = siz
l.Offset = led.Offset
l.Size = led.Size
f.Loads = append(f.Loads, l)
case types.LC_SEP_UNKNOWN_3:
var led types.SepUnknown3Cmd
b := bytes.NewReader(cmddat)
if err := binary.Read(b, bo, &led); err != nil {
return nil, fmt.Errorf("failed to read LC_SEP_SYMSEG: %v", err)
}
l := new(SepUnknown3)
l.LoadBytes = cmddat
l.LoadCmd = cmd
l.Len = siz
l.Offset = led.Offset
l.Size = led.Size
f.Loads = append(f.Loads, l)
}
if s != nil {
if int64(s.Offset) < 0 {
Expand Down
27 changes: 27 additions & 0 deletions types/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (c LoadCmd) Command() LoadCmd { return c }

const (
LC_REQ_DYLD LoadCmd = 0x80000000
LC_SEP LoadCmd = 0x8000000
LC_SEGMENT LoadCmd = 0x1 // segment of this file to be mapped
LC_SYMTAB LoadCmd = 0x2 // link-edit stab symbol table info
LC_SYMSEG LoadCmd = 0x3 // link-edit gdb symbol table info (obsolete)
Expand Down Expand Up @@ -74,6 +75,12 @@ const (
LC_DYLD_CHAINED_FIXUPS LoadCmd = (0x34 | LC_REQ_DYLD) // used with linkedit_data_command
LC_FILESET_ENTRY LoadCmd = (0x35 | LC_REQ_DYLD) /* used with fileset_entry_command */
LC_ATOM_INFO LoadCmd = 0x36 /* used with linkedit_data_command */
/*
* sep load commands
*/
LC_SEP_CACHE_SLIDE LoadCmd = (0x1 | LC_SEP)
LC_SEP_UNKNOWN_2 LoadCmd = (0x2 | LC_SEP)
LC_SEP_UNKNOWN_3 LoadCmd = (0x3 | LC_SEP)
)

type SegFlag uint32
Expand Down Expand Up @@ -1182,3 +1189,23 @@ type FilesetEntryCmd struct {
EntryIdOffset uint32 // contained entry id
Reserved uint32 // reserved
}

type SepCacheSlideCmd LinkEditDataCmd // LC_SEP_CACHE_SLIDE
type SepUnknown2Cmd LinkEditDataCmd // LC_SEP_UNKNOWN_2
type SepUnknown3Cmd LinkEditDataCmd // LC_SEP_UNKNOWN_3

type SepSymtabCmd struct {
LoadCmd // LC_SEP_SYMTAB
Len uint32 // sizeof(struct symtab_command)
Symoff uint16 // symbol table offset
Nsyms uint16 // number of symbol table entries
Stroff uint16 // string table offset
Strsize uint16 // string table size in bytes
}

type SepSymsegCmd struct {
LoadCmd /* LC_SEP_SYMSEG */
Len uint32 /* sizeof(struct symseg_command) */
Offset uint32 /* symbol segment offset */
Size uint32 /* symbol segment size in bytes */
}
30 changes: 19 additions & 11 deletions types/commands_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7eb5830

Please sign in to comment.