Skip to content

Commit

Permalink
fix: Update SepSegmentCmd to SepCacheSlideCmd for LC_SEP_CACHE_SLIDE
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jun 9, 2024
1 parent 3f0f5c2 commit 5571e3a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 46 deletions.
45 changes: 36 additions & 9 deletions cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -2252,27 +2252,54 @@ type AtomInfo struct {
}

/*******************************************************************************
* LC_SEP_SEGMENT
* LC_SEP_CACHE_SLIDE
*******************************************************************************/

type SepSegment struct {
LinkEditData
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_SYMTAB
* LC_SEP_UNKNOWN_2
*******************************************************************************/

type SepSymtab struct {
Symtab
type SepUnknown2 struct {
LinkEditData
}

/*******************************************************************************
* LC_SEP_SYMSEG
* LC_SEP_UNKNOWN_3
*******************************************************************************/

type SepSymseg struct {
SymSeg
type SepUnknown3 struct {
LinkEditData
}

/*******************************************************************************
Expand Down
29 changes: 13 additions & 16 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,42 +1257,39 @@ 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_SEGMENT:
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_SEGMENT: %v", err)
return nil, fmt.Errorf("failed to read LC_SEP_CACHE_SLIDE: %v", err)
}
l := new(SepSegment)
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_SYMTAB:
var hdr types.SepSymtabCmd
case types.LC_SEP_UNKNOWN_2:
var led types.SepUnknown2Cmd
b := bytes.NewReader(cmddat)
if err := binary.Read(b, bo, &hdr); err != nil {
return nil, fmt.Errorf("failed to read LC_SEP_SYMTAB: %v", err)
if err := binary.Read(b, bo, &led); err != nil {
return nil, fmt.Errorf("failed to read LC_SEP_UNKNOWN_2: %v", err)
}
l := new(SepSymtab)
l := new(SepUnknown2)
l.LoadBytes = cmddat
l.LoadCmd = cmd
l.Len = siz
l.Nsyms = uint32(hdr.Nsyms)
l.Symoff = uint32(hdr.Symoff)
l.Stroff = uint32(hdr.Stroff)
l.Strsize = uint32(hdr.Strsize)
l.Offset = led.Offset
l.Size = led.Size
f.Loads = append(f.Loads, l)
case types.LC_SEP_SYMSEG:
var led types.SymsegCmd
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(SepSymseg)
l := new(SepUnknown3)
l.LoadBytes = cmddat
l.LoadCmd = cmd
l.Len = siz
Expand Down
10 changes: 6 additions & 4 deletions types/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const (
/*
* sep load commands
*/
LC_SEP_SEGMENT LoadCmd = (LC_SEGMENT | LC_SEP)
LC_SEP_SYMTAB LoadCmd = (LC_SYMTAB | LC_SEP)
LC_SEP_SYMSEG LoadCmd = (LC_SYMSEG | LC_SEP)
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 @@ -1190,7 +1190,9 @@ type FilesetEntryCmd struct {
Reserved uint32 // reserved
}

type SepSegmentCmd LinkEditDataCmd // LC_SEP_SEG
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
Expand Down
34 changes: 17 additions & 17 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 5571e3a

Please sign in to comment.