當前位置: 首頁>>代碼示例>>Golang>>正文


Golang elf.File類代碼示例

本文整理匯總了Golang中debug/elf.File的典型用法代碼示例。如果您正苦於以下問題:Golang File類的具體用法?Golang File怎麽用?Golang File使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了File類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: hasDynTag

func hasDynTag(f *elf.File, tag elf.DynTag) bool {
	ds := f.SectionByType(elf.SHT_DYNAMIC)
	if ds == nil {
		return false
	}
	d, err := ds.Data()
	if err != nil {
		return false
	}
	for len(d) > 0 {
		var t elf.DynTag
		switch f.Class {
		case elf.ELFCLASS32:
			t = elf.DynTag(f.ByteOrder.Uint32(d[0:4]))
			d = d[8:]
		case elf.ELFCLASS64:
			t = elf.DynTag(f.ByteOrder.Uint64(d[0:8]))
			d = d[16:]
		}
		if t == tag {
			return true
		}
	}
	return false
}
開發者ID:danny8002,項目名稱:go,代碼行數:25,代碼來源:shared_test.go

示例2: hasDynTag

func hasDynTag(t *testing.T, f *elf.File, tag elf.DynTag) bool {
	ds := f.SectionByType(elf.SHT_DYNAMIC)
	if ds == nil {
		t.Error("no SHT_DYNAMIC section")
		return false
	}
	d, err := ds.Data()
	if err != nil {
		t.Errorf("can't read SHT_DYNAMIC contents: %v", err)
		return false
	}
	for len(d) > 0 {
		var t elf.DynTag
		switch f.Class {
		case elf.ELFCLASS32:
			t = elf.DynTag(f.ByteOrder.Uint32(d[:4]))
			d = d[8:]
		case elf.ELFCLASS64:
			t = elf.DynTag(f.ByteOrder.Uint64(d[:8]))
			d = d[16:]
		}
		if t == tag {
			return true
		}
	}
	return false
}
開發者ID:hurkgu,項目名稱:go,代碼行數:27,代碼來源:carchive_test.go

示例3: testABIHashNote

// The shared library contains a note containing the ABI hash that is mapped into
// memory and there is a local symbol called go.link.abihashbytes that points 16
// bytes into it.
func testABIHashNote(t *testing.T, f *elf.File, note *note) {
	if note.section.Flags != elf.SHF_ALLOC {
		t.Errorf("abi hash section has flags %v", note.section.Flags)
	}
	if !isOffsetLoaded(f, note.section.Offset) {
		t.Errorf("abihash section not contained in PT_LOAD segment")
	}
	var hashbytes elf.Symbol
	symbols, err := f.Symbols()
	if err != nil {
		t.Errorf("error reading symbols %v", err)
		return
	}
	for _, sym := range symbols {
		if sym.Name == "go.link.abihashbytes" {
			hashbytes = sym
		}
	}
	if hashbytes.Name == "" {
		t.Errorf("no symbol called go.link.abihashbytes")
		return
	}
	if elf.ST_BIND(hashbytes.Info) != elf.STB_LOCAL {
		t.Errorf("%s has incorrect binding %v", hashbytes.Name, elf.ST_BIND(hashbytes.Info))
	}
	if f.Sections[hashbytes.Section] != note.section {
		t.Errorf("%s has incorrect section %v", hashbytes.Name, f.Sections[hashbytes.Section].Name)
	}
	if hashbytes.Value-note.section.Addr != 16 {
		t.Errorf("%s has incorrect offset into section %d", hashbytes.Name, hashbytes.Value-note.section.Addr)
	}
}
開發者ID:danny8002,項目名稱:go,代碼行數:35,代碼來源:shared_test.go

示例4: haveDynTag

func haveDynTag(file *elf.File, tag elf.DynTag) bool {

	if section := file.Section(".dynamic"); section != nil {

		reader := io.NewSectionReader(section, 0, int64(section.Size))
		switch file.Machine {

		case elf.EM_X86_64:
			for {
				var entry elf.Dyn64
				if err := binary.Read(reader, binary.LittleEndian, &entry); err != io.EOF {
					if elf.DynTag(entry.Tag) == tag {
						return true
					}
				} else {
					break
				}
			}

		case elf.EM_386:
			for {
				var entry elf.Dyn32
				if err := binary.Read(reader, binary.LittleEndian, &entry); err != io.EOF {
					if elf.DynTag(entry.Tag) == tag {
						return true
					}
				} else {
					break
				}
			}
		}
	}
	return false
}
開發者ID:postfix,項目名稱:checksec,代碼行數:34,代碼來源:dyntag.go

示例5: dump_symbols

func dump_symbols(file *elf.File) {
	fmt.Printf("Symbols:\n")
	symbols, _ := file.Symbols()
	for _, e := range symbols {
		if !strings.EqualFold(e.Name, "") {
			fmt.Printf("\t%s\n", e.Name)
		}
	}
}
開發者ID:n4ss,項目名稱:GoPlay,代碼行數:9,代碼來源:main.go

示例6: producer

func producer(debugfile *elf.File, dwzfile *elf.File, debug_package string, debug_file string) []string {
	var output []string

	// iterate over all CUs present in debugfile
	d, e := debugfile.DWARF() // increases memory usage by 2x to 3x!

	if e != nil {
		log.Println(e, debug_package, debug_file)
		return output
	}

	reader := d.Reader()
	for {
		entry, err := reader.Next()
		if err != nil {
			log.Println(err, debug_file, debug_package)
			break
		}

		if entry == nil {
			break
		}

		if entry.Tag == dwarf.TagCompileUnit {
			for _, f := range entry.Field {
				if f.Attr == dwarf.AttrName {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					case dwarf.OffsetStrpAlt:
						output = append(output, (string)(f.Val.(dwarf.OffsetStrpAlt)))
					case dwarf.OffsetRefAlt:
						log.Panic("DW_FORM_GNU_ref_alt handling missing for dwarf.AttrName ;(")
					default:
						panic("form unhandled for dwarf.AttrName, expect the unexpected ;(")
					}
				} else if f.Attr == dwarf.AttrProducer {
					switch f.Val.(type) {
					case string:
						output = append(output, f.Val.(string))
					case dwarf.OffsetStrpAlt:
						output = append(output, dwzparser(dwzfile, (int64)(f.Val.(dwarf.OffsetStrpAlt)), debug_package, debug_file))
					case dwarf.OffsetRefAlt:
						log.Panic("DW_FORM_GNU_ref_alt handling missing for dwarf.AttrProducer ;(")
					default:
						panic("form unhandled for dwarf.AttrProducer, expect the unexpected ;(")
					}

				}
			}
		}
	}

	// log.Println(output)
	return output
}
開發者ID:postfix,項目名稱:flags-scanner,代碼行數:56,代碼來源:worker.go

示例7: getSectionData

func getSectionData(f *elf.File, name string) []byte {
	section := f.Section(name)
	if section == nil {
		log.Fatalf("failed getting section %s", name)
	}
	data, err := section.Data()
	if err != nil {
		log.Fatalf("failed getting section %s data: %s", name, err)
	}
	return data
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:11,代碼來源:gosym.go

示例8: GetSymbols

func GetSymbols(e *elf.File) map[ds.Range]*ds.Symbol {
	res := make(map[ds.Range]*ds.Symbol)
	symbols, err := e.Symbols()
	if err != nil {
		log.WithFields(log.Fields{"error": err}).Info("Failed to Parse Symbols")
		return res
	}
	for _, sym := range symbols {
		sym_type := elfSymbolTypeToSymbolType(uint(sym.Info))
		symbol := ds.NewSymbol(sym.Name, sym_type)
		res[ds.NewRange(sym.Value, sym.Value+sym.Size)] = symbol
	}
	return res
}
開發者ID:eqv,項目名稱:indika,代碼行數:14,代碼來源:elf.go

示例9: processGoInformation

func processGoInformation(f *elf.File) {
	gosymtab := getSectionData(f, ".gosymtab")
	gopclntab := getSectionData(f, ".gopclntab")

	lineTable := gosym.NewLineTable(gopclntab, f.Section(".text").Addr)
	table, err := gosym.NewTable(gosymtab, lineTable)
	if err != nil {
		log.Fatalf("failed making table: %s", err)
	}

	printSyms(table.Syms)
	printFuncs(table.Funcs)
	printFiles(table.Files)
}
開發者ID:rrudduck,項目名稱:golang-stuff,代碼行數:14,代碼來源:gosym.go

示例10: parseDebugLineInfo

func (dbp *Process) parseDebugLineInfo(exe *elf.File, wg *sync.WaitGroup) {
	defer wg.Done()

	if sec := exe.Section(".debug_line"); sec != nil {
		debugLine, err := exe.Section(".debug_line").Data()
		if err != nil {
			fmt.Println("could not get .debug_line section", err)
			os.Exit(1)
		}
		dbp.lineInfo = line.Parse(debugLine)
	} else {
		fmt.Println("could not find .debug_line section in binary")
		os.Exit(1)
	}
}
開發者ID:jeffallen,項目名稱:delve,代碼行數:15,代碼來源:proc_linux.go

示例11: parseDebugFrame

func (dbp *Process) parseDebugFrame(exe *elf.File, wg *sync.WaitGroup) {
	defer wg.Done()

	if sec := exe.Section(".debug_frame"); sec != nil {
		debugFrame, err := exe.Section(".debug_frame").Data()
		if err != nil {
			fmt.Println("could not get .debug_frame section", err)
			os.Exit(1)
		}
		dbp.frameEntries = frame.Parse(debugFrame)
	} else {
		fmt.Println("could not find .debug_frame section in binary")
		os.Exit(1)
	}
}
開發者ID:jeffallen,項目名稱:delve,代碼行數:15,代碼來源:proc_linux.go

示例12: dwzparser

func dwzparser(dwzfile *elf.File, offset int64, debug_package string, debug_file string) string {
	if section := dwzfile.Section(".debug_str"); section != nil {
		reader := io.NewSectionReader(section, 0, int64(section.Size))
		reader.Seek(offset, 1)
		bufreader := bufio.NewReader(reader)
		// http://golang.org/pkg/bufio/#Reader.ReadString
		str, err := bufreader.ReadString('\x00')
		if err != nil {
			log.Println(err, debug_package, debug_file)
		}

		return strings.TrimSuffix(str, "\x00")
	}
	panic("dwzparser ran into problems ;(")
}
開發者ID:postfix,項目名稱:flags-scanner,代碼行數:15,代碼來源:worker.go

示例13: canary

func canary(file *elf.File) string {

	if symbols, e := file.Symbols(); e == nil {
		for _, sym := range symbols {
			if bytes.HasPrefix([]byte(sym.Name), []byte(STACK_CHK)) {
				return ENABLED
			}
		}
	}

	if importedSymbols, e := file.ImportedSymbols(); e == nil {
		for _, imp := range importedSymbols {
			if bytes.HasPrefix([]byte(imp.Name), []byte(STACK_CHK)) {
				return ENABLED
			}
		}
	}

	return DISABLED
}
開發者ID:postfix,項目名稱:checksec,代碼行數:20,代碼來源:canary.go

示例14: elfGoSyms

func elfGoSyms(f *elf.File) (*gosym.Table, os.Error) {
	text := f.Section(".text")
	symtab := f.Section(".gosymtab")
	pclntab := f.Section(".gopclntab")
	if text == nil || symtab == nil || pclntab == nil {
		return nil, nil
	}

	symdat, err := symtab.Data()
	if err != nil {
		return nil, err
	}
	pclndat, err := pclntab.Data()
	if err != nil {
		return nil, err
	}

	pcln := gosym.NewLineTable(pclndat, text.Addr)
	tab, err := gosym.NewTable(symdat, pcln)
	if err != nil {
		return nil, err
	}

	return tab, nil
}
開發者ID:IntegerCompany,項目名稱:linaro-android-gcc,代碼行數:25,代碼來源:process.go

示例15: obtainGoSymbols

func (dbp *Process) obtainGoSymbols(exe *elf.File, wg *sync.WaitGroup) {
	defer wg.Done()

	var (
		symdat  []byte
		pclndat []byte
		err     error
	)

	if sec := exe.Section(".gosymtab"); sec != nil {
		symdat, err = sec.Data()
		if err != nil {
			fmt.Println("could not get .gosymtab section", err)
			os.Exit(1)
		}
	}

	if sec := exe.Section(".gopclntab"); sec != nil {
		pclndat, err = sec.Data()
		if err != nil {
			fmt.Println("could not get .gopclntab section", err)
			os.Exit(1)
		}
	}

	pcln := gosym.NewLineTable(pclndat, exe.Section(".text").Addr)
	tab, err := gosym.NewTable(symdat, pcln)
	if err != nil {
		fmt.Println("could not get initialize line table", err)
		os.Exit(1)
	}

	dbp.goSymTable = tab
}
開發者ID:jeffallen,項目名稱:delve,代碼行數:34,代碼來源:proc_linux.go


注:本文中的debug/elf.File類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。