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

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

示例1: sanity

func sanity() {
    goBinGo := path.Join(config.Gosrcroot, "go/bin/go")
    log.Printf("check %v as the go binary", goBinGo)
    _, err := os.Stat(goBinGo)
    if err == nil {
        config.Go = "go/bin/go"
    }
    // but does the one in go/bin/OS_ARCH exist too?
    archgo := fmt.Sprintf("bin/%s_%s/go", config.Goos, config.Arch)
    linuxBinGo := path.Join(config.Gosrcroot, archgo)
    log.Printf("check %v as the go binary", linuxBinGo)
    _, err = os.Stat(linuxBinGo)
    if err == nil {
        config.Go = archgo
        goBinGo = linuxBinGo
    }
    log.Printf("Using %v as the go command", goBinGo)
    if config.Go == "" {
        log.Fatalf("Can't find a go binary! Is GOROOT set correctly?")
    }
    f, err := elf.Open(goBinGo)
    if err != nil {
        log.Fatalf("%v is not an ELF file; don't know what to do", goBinGo)
    }
    ds := f.SectionByType(elf.SHT_DYNAMIC)
    if ds != nil {
        log.Printf("U-root requires a staticically built go tree at present. %v is dynamic.", goBinGo)
        log.Fatalf("To fix this:\ncd %v/src\nexport CGO_ENABLED=0\nGOARCH=%v ./make.bash", config.Goroot, config.Arch)
    }
}

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

示例2: IsELF

func IsELF(fPath string) error {
    if _, err := elf.Open(fPath); err != nil {
        return err
    }

    return nil
}

开发者ID:hcninja,项目名称:malpic,代码行数:7,代码来源:anal.go

示例3: cmdMode

func cmdMode(cmd string, args []string) error {
    f, err := elf.Open(cmd)
    if err != nil {
        return err
    }
    defer f.Close()

    // Set mem limits
    for _, p := range f.Progs {
        if p.Type != elf.PT_LOAD {
            continue
        }
        if p.Vaddr < startAddr {
            startAddr = p.Vaddr
        }
        if addr := p.Vaddr + p.Memsz; addr > endAddr {
            endAddr = addr
        }
    }

    pt, err := ForkExec(cmd, args)
    if err != nil {
        return err
    }
    if err := pt.Wait(printPC); err != nil {
        return err
    }
    return nil
}

开发者ID:jroimartin,项目名称:diff_tracer,代码行数:29,代码来源:main.go

示例4: getDwarf

func getDwarf(execname string) *dwarf.Data {
    e, err := elf.Open(execname)
    if err == nil {
        defer e.Close()
        d, err := e.DWARF()
        if err == nil {
            return d
        }
    }
    m, err := macho.Open(execname)
    if err == nil {
        defer m.Close()
        d, err := m.DWARF()
        if err == nil {
            return d
        }
    }
    p, err := pe.Open(execname)
    if err == nil {
        defer p.Close()
        d, err := p.DWARF()
        if err == nil {
            return d
        }
    }
    log.Fatal("can't get dwarf info from executable", err)
    return nil
}

开发者ID:lamproae,项目名称:hprof,代码行数:28,代码来源:parser.go

示例5: FindFunc

func FindFunc(fileName string, pc uint64) (s elf.Symbol, err error) {
    file, err := elf.Open(fileName)
    if err != nil {
        return elf.Symbol{}, err
    }

    symbols, err := file.Symbols()
    if err != nil {
        return elf.Symbol{}, err
    }

    funcSymbols := make(Symbols, 0)
    for _, symbol := range symbols {
        if elf.ST_TYPE(symbol.Info) == elf.STT_FUNC {
            funcSymbols = append(funcSymbols, symbol)
        }
    }
    n := len(funcSymbols)
    if n == 0 {
        return elf.Symbol{}, &ErrNoFunctions{}
    }

    sort.Sort(funcSymbols)
    i := sort.Search(n, func(i int) bool { return funcSymbols[i].Value >= pc })
    if i != 0 || funcSymbols[i].Value <= pc {
        if i == n || (funcSymbols[i].Value != pc && i != 0) {
            i--
        }
        return funcSymbols[i], nil
    }

    return elf.Symbol{}, &ErrFunctionNotFound{}
}

开发者ID:postfix,项目名称:findfunc,代码行数:33,代码来源:findfunc.go

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