Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(118)

Unified Diff: src/cmd/nm/pe.go

Issue 40600043: code review 40600043: cmd/nm: reimplement in Go (Closed)
Patch Set: diff -r 5130190e81b5 https://code.google.com/p/go/ Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/cmd/nm/nm.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/cmd/nm/pe.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/cmd/nm/pe.go
@@ -0,0 +1,54 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Parsing of PE executables (Microsoft Windows).
+
+package main
+
+import (
+ "debug/pe"
+ "os"
+)
+
+func peSymbols(f *os.File) []Sym {
+ p, err := pe.NewFile(f)
+ if err != nil {
+ errorf("parsing %s: %v", f.Name(), err)
+ return nil
+ }
+
+ var syms []Sym
+ for _, s := range p.Symbols {
+ sym := Sym{Name: s.Name, Addr: uint64(s.Value), Code: '?'}
+ if s.SectionNumber == 0 {
+ sym.Code = 'U'
+ } else if int(s.SectionNumber) <= len(p.Sections) {
+ sect := p.Sections[s.SectionNumber-1]
+ const (
+ text = 0x20
+ data = 0x40
+ bss = 0x80
+ permX = 0x20000000
+ permR = 0x40000000
+ permW = 0x80000000
+ )
+ ch := sect.Characteristics
+ switch {
+ case ch&text != 0:
+ sym.Code = 'T'
+ case ch&data != 0:
+ if ch&permW == 0 {
+ sym.Code = 'R'
+ } else {
+ sym.Code = 'D'
+ }
+ case ch&bss != 0:
+ sym.Code = 'B'
+ }
+ }
+ syms = append(syms, sym)
+ }
+
+ return syms
+}
« no previous file with comments | « src/cmd/nm/nm.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b