Skip to content

Commit 9ace840

Browse files
committed
fix: dyld info seg names
1 parent ab4264f commit 9ace840

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

cmd/ipsw/cmd/dyld_info.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ var dyldInfoCmd = &cobra.Command{
177177
if showDylibs {
178178
fmt.Println("Images")
179179
fmt.Println("======")
180-
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.DiscardEmptyColumns)
181180
for idx, img := range f.Images {
182181
if f.FormatVersion.IsDylibsExpectedOnDisk() {
183182
m, err := macho.Open(img.Name)
@@ -189,23 +188,25 @@ var dyldInfoCmd = &cobra.Command{
189188
if err != nil {
190189
return errors.Wrapf(err, "failed to open Fat MachO %s", img.Name)
191190
}
192-
fmt.Fprintf(w, "%4d:\t0x%0X\t(%s)\t%s\n", idx+1, img.Info.Address, fat.Arches[0].DylibID().CurrentVersion, img.Name)
191+
fmt.Printf("%4d: %#0X (%s) %s\n", idx+1, img.Info.Address, fat.Arches[0].DylibID().CurrentVersion, img.Name)
193192
fat.Close()
194193
continue
195194
}
196-
fmt.Fprintf(w, "%4d:\t0x%0X\t(%s)\t%s\n", idx+1, img.Info.Address, m.DylibID().CurrentVersion, img.Name)
195+
fmt.Printf("%4d: %#0X (%s) %s\n", idx+1, img.Info.Address, m.DylibID().CurrentVersion, img.Name)
197196
m.Close()
198197
} else {
199198
m, err := img.GetPartialMacho()
200199
if err != nil {
201200
return errors.Wrap(err, "failed to create MachO")
202201
}
203-
fmt.Fprintf(w, "%4d:\t0x%0X\t%s\t(%s)\n", idx+1, img.Info.Address, img.Name, m.DylibID().CurrentVersion)
202+
if Verbose {
203+
fmt.Printf("%4d: %#0X %s (%s)\n", idx+1, img.Info.Address, img.Name, m.DylibID().CurrentVersion)
204+
} else {
205+
fmt.Printf("%4d: %s (%s)\n", idx+1, img.Name, m.DylibID().CurrentVersion)
206+
}
204207
m.Close()
205208
}
206-
// w.Flush()
207209
}
208-
w.Flush()
209210
}
210211
return nil
211212
},

pkg/dyld/file.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,19 @@ func NewFile(r io.ReaderAt, userConfig ...*Config) (*File, error) {
248248
return nil, err
249249
}
250250
cm := &CacheMappingWithSlideInfo{CacheMappingAndSlideInfo: cxmInfo}
251-
if cxmInfo.InitProt.Execute() {
251+
if cxmInfo.MaxProt.Execute() {
252252
cm.Name = "__TEXT"
253-
} else if cxmInfo.InitProt.Write() && cm.Flags != 1 {
254-
cm.Name = "__DATA"
255-
} else if cxmInfo.InitProt.Write() && cm.Flags == 1 {
256-
cm.Name = "__AUTH"
253+
} else if cxmInfo.MaxProt.Write() {
254+
if cm.Flags.IsAuthData() {
255+
cm.Name = "__AUTH"
256+
} else {
257+
cm.Name = "__DATA"
258+
}
259+
if cm.Flags.IsDirtyData() {
260+
cm.Name += "_DIRTY"
261+
} else if cm.Flags.IsConstData() {
262+
cm.Name += "_CONST"
263+
}
257264
} else if cxmInfo.InitProt.Read() {
258265
cm.Name = "__LINKEDIT"
259266
}

pkg/dyld/types.go

+14
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,25 @@ type CacheMappingInfo struct {
134134
type CacheMappingFlag uint64
135135

136136
const (
137+
DYLD_CACHE_MAPPING_NONE CacheMappingFlag = 0
137138
DYLD_CACHE_MAPPING_AUTH_DATA CacheMappingFlag = 1
138139
DYLD_CACHE_MAPPING_DIRTY_DATA CacheMappingFlag = 2
139140
DYLD_CACHE_MAPPING_CONST_DATA CacheMappingFlag = 4
140141
)
141142

143+
func (f CacheMappingFlag) IsNone() bool {
144+
return f == DYLD_CACHE_MAPPING_NONE
145+
}
146+
func (f CacheMappingFlag) IsAuthData() bool {
147+
return (f & DYLD_CACHE_MAPPING_AUTH_DATA) != 0
148+
}
149+
func (f CacheMappingFlag) IsDirtyData() bool {
150+
return (f & DYLD_CACHE_MAPPING_DIRTY_DATA) != 0
151+
}
152+
func (f CacheMappingFlag) IsConstData() bool {
153+
return (f & DYLD_CACHE_MAPPING_CONST_DATA) != 0
154+
}
155+
142156
type CacheMappingAndSlideInfo struct {
143157
Address uint64
144158
Size uint64

0 commit comments

Comments
 (0)