本文整理汇总了Golang中debug/macho.NewFile函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewFile函数的具体用法?Golang NewFile怎么用?Golang NewFile使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了NewFile函数的16个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: openMacho
func openMacho(r *os.File) (rawFile, error) {
f, err := macho.NewFile(r)
if err != nil {
return nil, err
}
return &machoFile{f}, nil
}
开发者ID:2thetop,项目名称:go,代码行数:7,代码来源:macho.go
示例2: openDebugFile
func openDebugFile(r io.ReaderAt) (debugFile, error) {
f, err := macho.NewFile(r)
if err != nil {
return nil, err
}
return &file{f}, nil
}
开发者ID:rainycape,项目名称:gondola,代码行数:7,代码来源:debug_darwin.go
示例3: zipExeReaderMacho
// zipExeReaderMacho treats the file as a Mach-O binary
// (Mac OS X / Darwin executable) and attempts to find a zip archive.
func zipExeReaderMacho(rda io.ReaderAt, size int64) (*zip.Reader, error) {
file, err := macho.NewFile(rda)
if err != nil {
return nil, err
}
var max int64
for _, load := range file.Loads {
seg, ok := load.(*macho.Segment)
if ok {
// Check if the segment contains a zip file
if zfile, err := zip.NewReader(seg, int64(seg.Filesz)); err == nil {
return zfile, nil
}
// Otherwise move end of file pointer
end := int64(seg.Offset + seg.Filesz)
if end > max {
max = end
}
}
}
// No zip file within binary, try appended to end
section := io.NewSectionReader(rda, max, size-max)
return zip.NewReader(section, section.Size())
}
开发者ID:Skarlso,项目名称:slick,代码行数:29,代码来源:zipexe.go
示例4: newSectionReader
func newSectionReader(rf io.ReaderAt) (ret sectionReader, err error) {
ret.macho, err = macho.NewFile(rf)
if err != nil {
ret.elf, err = elf.NewFile(rf)
}
return
}
开发者ID:ksurdy,项目名称:completion,代码行数:7,代码来源:info_test.go
示例5: readMachoGoBuildID
// The Go build ID is stored at the beginning of the Mach-O __text segment.
// The caller has already opened filename, to get f, and read a few kB out, in data.
// Sadly, that's not guaranteed to hold the note, because there is an arbitrary amount
// of other junk placed in the file ahead of the main text.
func readMachoGoBuildID(filename string, f *os.File, data []byte) (buildid string, err error) {
// If the data we want has already been read, don't worry about Mach-O parsing.
// This is both an optimization and a hedge against the Mach-O parsing failing
// in the future due to, for example, the name of the __text section changing.
if b, err := readRawGoBuildID(filename, data); b != "" && err == nil {
return b, err
}
mf, err := macho.NewFile(f)
if err != nil {
return "", &os.PathError{Path: filename, Op: "parse", Err: err}
}
sect := mf.Section("__text")
if sect == nil {
// Every binary has a __text section. Something is wrong.
return "", &os.PathError{Path: filename, Op: "parse", Err: fmt.Errorf("cannot find __text section")}
}
// It should be in the first few bytes, but read a lot just in case,
// especially given our past problems on OS X with the build ID moving.
// There shouldn't be much difference between reading 4kB and 32kB:
// the hard part is getting to the data, not transferring it.
n := sect.Size
if n > uint64(BuildIDReadSize) {
n = uint64(BuildIDReadSize)
}
buf := make([]byte, n)
if _, err := f.ReadAt(buf, int64(sect.Offset)); err != nil {
return "", err
}
return readRawGoBuildID(filename, buf)
}
开发者ID:sreis,项目名称:go,代码行数:38,代码来源:note.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng