Skip to content

Commit

Permalink
version: update for Go 1.17 *.abi0 symbols
Browse files Browse the repository at this point in the history
Fixes #21.
  • Loading branch information
rsc committed Mar 9, 2023
1 parent 597212e commit 3a30cee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module rsc.io/goversion

go 1.21
10 changes: 8 additions & 2 deletions version/exe.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ func (x *elfExe) Close() error {
func (x *elfExe) Entry() uint64 { return x.f.Entry }

func (x *elfExe) ReadData(addr, size uint64) ([]byte, error) {
data := make([]byte, size)
for _, prog := range x.f.Progs {
if prog.Vaddr <= addr && addr+size-1 <= prog.Vaddr+prog.Filesz-1 {
fmt.Printf("%#x %#x %#x\n", addr, prog.Vaddr, prog.Vaddr+prog.Filesz)
if prog.Vaddr <= addr && addr <= prog.Vaddr+prog.Filesz-1 {
n := prog.Vaddr + prog.Filesz - addr
if n > size {
n = size
}
data := make([]byte, n)
_, err := prog.ReadAt(data, int64(addr-prog.Vaddr))
if err != nil {
return nil, err
Expand Down Expand Up @@ -254,6 +259,7 @@ func (x *machoExe) Entry() uint64 {
if !ok {
continue
}
// TODO: Other thread states.
bo := x.f.ByteOrder
const x86_THREAD_STATE64 = 4
cmd, siz := macho.LoadCmd(bo.Uint32(b[0:4])), bo.Uint32(b[4:8])
Expand Down
12 changes: 6 additions & 6 deletions version/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ func ReadExe(file string) (Version, error) {
return v, err
}
v.Release = release

}
if strings.Contains(name, "_Cfunc__goboringcrypto_") || name == "crypto/internal/boring/sig.BoringCrypto" {
// Note: Using strings.HasPrefix because Go 1.17+ adds ".abi0" to many of these symbols.
if strings.Contains(name, "_Cfunc__goboringcrypto_") || strings.HasPrefix(name, "crypto/internal/boring/sig.BoringCrypto") {
v.BoringCrypto = true
}
if name == "crypto/internal/boring/sig.FIPSOnly" {
if strings.HasPrefix(name, "crypto/internal/boring/sig.FIPSOnly") {
v.FIPSOnly = true
}
for _, re := range standardCryptoNames {
if re.MatchString(name) {
v.StandardCrypto = true
}
}
if name == "crypto/internal/boring/sig.StandardCrypto" {
if strings.HasPrefix(name, "crypto/internal/boring/sig.StandardCrypto") {
v.StandardCrypto = true
}
}
Expand Down Expand Up @@ -112,8 +112,8 @@ var standardCryptoNames = []*regexp.Regexp{
re(`^crypto/sha1\.\(\*digest\)`),
re(`^crypto/sha256\.\(\*digest\)`),
re(`^crypto/rand\.\(\*devReader\)`),
re(`^crypto/rsa\.encrypt$`),
re(`^crypto/rsa\.decrypt$`),
re(`^crypto/rsa\.encrypt(\.abi.)?$`),
re(`^crypto/rsa\.decrypt(\.abi.)?$`),
}

func readBuildVersion(f exe, addr, size uint64) (string, error) {
Expand Down

0 comments on commit 3a30cee

Please sign in to comment.