本文整理汇总了Golang中debug/elf.NewFile函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewFile函数的具体用法?Golang NewFile怎么用?Golang NewFile使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了NewFile函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: 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

示例2: zipExeReaderElf

// zipExeReaderElf treats the file as a ELF binary
// (linux/BSD/etc... executable) and attempts to find a zip archive.
func zipExeReaderElf(rda io.ReaderAt, size int64) (*zip.Reader, error) {
    file, err := elf.NewFile(rda)
    if err != nil {
        return nil, err
    }

    var max int64
    for _, sect := range file.Sections {
        if sect.Type == elf.SHT_NOBITS {
            continue
        }

        // Check if this section has a zip file
        if zfile, err := zip.NewReader(sect, int64(sect.Size)); err == nil {
            return zfile, nil
        }

        // Otherwise move end of file pointer
        end := int64(sect.Offset + sect.Size)
        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,代码行数:30,代码来源:zipexe.go

示例3: elfexec

func elfexec(b []byte) (uintptr, []KexecSegment, error) {
    f, err := elf.NewFile(bytes.NewReader(b))
    if err != nil {
        return 0, nil, err
    }
    scount := 0
    for _, v := range f.Progs {
        if v.Type.String() == "PT_LOAD" {
            scount++
        }
    }
    if scount > KEXEC_SEGMENT_MAX {
        log.Fatalf("Too many segments: got %v, max is %v", scount, KEXEC_SEGMENT_MAX)
    }
    segs := make([]KexecSegment, scount)
    for i, v := range f.Progs {
        if v.Type.String() == "PT_LOAD" {
            f := v.Open()
            b := pages(uintptr(v.Memsz))
            if _, err := f.Read(b[:v.Filesz]); err != nil {
                log.Fatalf("Reading %d bytes of program header %d: %v", v.Filesz, i, err)
            }
            segs[i] = makeseg(b, uintptr(v.Paddr))
        }
    }
    log.Printf("Using ELF image loader")
    return uintptr(f.Entry), segs, nil
    //return uintptr(0x40000), segs, nil
}

开发者ID:rhiguita,项目名称:u-root,代码行数:29,代码来源:kexec.go

示例4: TestRun

func TestRun(t *testing.T) {
    file := "samples/simple/O0/strings"
    f := ioReader(file)
    _elf, err := elf.NewFile(f)
    check(wrap(err))
    maps := loader.GetSegments(_elf)
    symbols := loader.GetSymbols(_elf)
    fmt.Println("done loading")
    emulator := MakeBlanketEmulator(maps)
    fmt.Println("done making blanket emulator")

    for rng, symb := range symbols {
        if symb.Type == ds.FUNC && strings.Contains(symb.Name, "str") {
            bbs := extract_bbs(maps, rng)
            if len(bbs) == 0 {
                continue
            }
            fmt.Printf("found function %v\n", symb.Name)
            fmt.Printf("running for %v \n", bbs)
            err := emulator.FullBlanket(bbs)
            if err != nil {
                log.WithFields(log.Fields{"error": err}).Fatal("Error running Blanket")
            }
            ev := emulator.Config.EventHandler.(*be.EventsToMinHash)
            fmt.Println("hash %v", ev.GetHash(60))
            //          fmt.Println("events %v", ev.Inspect())
        }
    }
}

开发者ID:eqv,项目名称:indika,代码行数:29,代码来源:simple_test.go

示例5: Fuzz

func Fuzz(data []byte) int {
    f, err := elf.NewFile(bytes.NewReader(data))
    if err != nil {
        if f != nil {
            panic("file is not nil on error")
        }
        return 0
    }
    defer f.Close()
    f.DynamicSymbols()
    f.ImportedLibraries()
    f.ImportedSymbols()
    f.Section(".data")
    f.SectionByType(elf.SHT_GNU_VERSYM)
    f.Symbols()
    dw, err := f.DWARF()
    if err != nil {
        if dw != nil {
            panic("dwarf is not nil on error")
        }
        return 1
    }
    dr := dw.Reader()
    for {
        e, _ := dr.Next()
        if e == nil {
            break
        }
    }
    return 2
}

开发者ID:sjn1978,项目名称:go-fuzz,代码行数:31,代码来源:main.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng