Skip to content

Commit 78c02cc

Browse files
add support for Go runtime v1.26 (#85)
* clarify Go runtime version vs GoReSym layout version * Add Go 1.26 support * Cleanup debugging prints * Remove remaining debug print in main.go * Fix redundant nil check in pe.go * Final touches: fix sudo in build script and rename layout convention to 1.22 * Run go fmt * Revert unnecessary moduledata scanning changes in executable parsers * refactor fixes * better variable name for refactor * Fix lots of version issues and bugs in magic prefix check, as well as concurrent lock bug * fmt * Refactor slice, textsec, and more to use offsets. Cleanup dead code in internal.go * fmt --------- Co-authored-by: Stephen Eckels <stevemk14ebr@gmail.com>
1 parent e5bc135 commit 78c02cc

File tree

15 files changed

+501
-2091
lines changed

15 files changed

+501
-2091
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ Dockerfile.test
1919
# Dependency directories (remove the comment below to include it)
2020
# vendor/
2121

22+
# Agent files
23+
.agent/
24+
.agents/

build_test_files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
trap "exit" INT
33
sudo rm -rf $(pwd)/test/build
4-
versions=("1.25" "1.24" "1.23" "1.22" "1.21" "1.20" "1.19" "1.18" "1.17" "1.16" "1.15" "1.14" "1.13" "1.12" "1.11" "1.10" "1.9" "1.8" "1.7" "1.6" "1.5")
4+
versions=("1.26" "1.25" "1.24" "1.23" "1.22" "1.21" "1.20" "1.19" "1.18" "1.17" "1.16" "1.15" "1.14" "1.13" "1.12" "1.11" "1.10" "1.9" "1.8" "1.7" "1.6" "1.5")
55
for v in "${versions[@]}"
66
do
77
GO_TAG=$v

debug/elf/file.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"io"
1717
"os"
1818
"strings"
19+
"sync"
1920

2021
"github.com/mandiant/GoReSym/debug/dwarf"
2122
"github.com/mandiant/GoReSym/saferio"
@@ -61,6 +62,7 @@ type File struct {
6162
gnuVersym []byte
6263

6364
dataAfterSectionCache map[uint64][]byte // secVA -> dataAfterSection
65+
dataAfterSectionMutex sync.Mutex
6466
}
6567

6668
// A SectionHeader represents a single ELF section header.
@@ -689,9 +691,12 @@ func getString(section []byte, start int) (string, bool) {
689691
}
690692

691693
func (f *File) DataAfterSection(target *Section) []byte {
692-
if cached, ok := f.dataAfterSectionCache[uint64(target.Addr)]; ok {
694+
f.dataAfterSectionMutex.Lock()
695+
if cached, ok := f.dataAfterSectionCache[target.Addr]; ok {
696+
f.dataAfterSectionMutex.Unlock()
693697
return cached
694698
}
699+
f.dataAfterSectionMutex.Unlock()
695700

696701
data := []byte{}
697702
found := false
@@ -712,7 +717,9 @@ func (f *File) DataAfterSection(target *Section) []byte {
712717
}
713718
}
714719

715-
f.dataAfterSectionCache[uint64(target.Addr)] = data
720+
f.dataAfterSectionMutex.Lock()
721+
f.dataAfterSectionCache[target.Addr] = data
722+
f.dataAfterSectionMutex.Unlock()
716723
return data
717724
}
718725

debug/gosym/pclntab.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ func (t *LineTable) parsePclnTab(versionOverride string) {
264264
t.Version = possibleVersion
265265

266266
if len(versionOverride) > 0 {
267-
if strings.Contains(versionOverride, "1.25") ||
267+
if strings.Contains(versionOverride, "1.26") ||
268+
strings.Contains(versionOverride, "1.25") ||
268269
strings.Contains(versionOverride, "1.24") ||
269270
strings.Contains(versionOverride, "1.23") ||
270271
strings.Contains(versionOverride, "1.22") ||

debug/macho/file.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"io"
1818
"os"
1919
"strings"
20+
"sync"
2021

2122
"github.com/mandiant/GoReSym/debug/dwarf"
2223
)
@@ -33,6 +34,7 @@ type File struct {
3334

3435
closer io.Closer
3536
dataAfterSectionCache map[uint64][]byte // secVA -> dataAfterSection
37+
dataAfterSectionMutex sync.Mutex
3638
}
3739

3840
// A Load represents any Mach-O load command.
@@ -575,9 +577,12 @@ func (f *File) Segment(name string) *Segment {
575577
}
576578

577579
func (f *File) DataAfterSection(target *Section) []byte {
580+
f.dataAfterSectionMutex.Lock()
578581
if cached, ok := f.dataAfterSectionCache[target.Addr]; ok {
582+
f.dataAfterSectionMutex.Unlock()
579583
return cached
580584
}
585+
f.dataAfterSectionMutex.Unlock()
581586

582587
data := []byte{}
583588
found := false
@@ -597,7 +602,10 @@ func (f *File) DataAfterSection(target *Section) []byte {
597602
}
598603
}
599604
}
605+
606+
f.dataAfterSectionMutex.Lock()
600607
f.dataAfterSectionCache[target.Addr] = data
608+
f.dataAfterSectionMutex.Unlock()
601609
return data
602610
}
603611

debug/pe/file.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"io"
1616
"os"
1717
"strings"
18+
"sync"
1819

1920
"github.com/mandiant/GoReSym/debug/dwarf"
2021
)
@@ -33,6 +34,7 @@ type File struct {
3334

3435
closer io.Closer
3536
dataAfterSectionCache map[uint64][]byte // secVA -> dataAfterSection
37+
dataAfterSectionMutex sync.Mutex
3638
}
3739

3840
// Open opens the named file using os.Open and prepares it for use as a PE binary.
@@ -213,9 +215,12 @@ func (f *File) Section(name string) *Section {
213215
}
214216

215217
func (f *File) DataAfterSection(target *Section) []byte {
218+
f.dataAfterSectionMutex.Lock()
216219
if cached, ok := f.dataAfterSectionCache[uint64(target.VirtualAddress)]; ok {
220+
f.dataAfterSectionMutex.Unlock()
217221
return cached
218222
}
223+
f.dataAfterSectionMutex.Unlock()
219224

220225
data := []byte{}
221226
found := false
@@ -235,7 +240,10 @@ func (f *File) DataAfterSection(target *Section) []byte {
235240
}
236241
}
237242
}
243+
244+
f.dataAfterSectionMutex.Lock()
238245
f.dataAfterSectionCache[uint64(target.VirtualAddress)] = data
246+
f.dataAfterSectionMutex.Unlock()
239247
return data
240248
}
241249

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ restartParseWithRealTextBase:
233233
// if that location works, then we must have given it the correct pclntab VA. At least in theory...
234234
// The resolved offsets within the pclntab might have used the wrong base though! We'll fix that later.
235235
_, tmpModData, err := file.ModuleDataTable(tab.PclntabVA, extractMetadata.Version, extractMetadata.TabMeta.Version, extractMetadata.TabMeta.PointerSize == 8, extractMetadata.TabMeta.Endianess == "LittleEndian")
236+
236237
if err == nil && tmpModData != nil {
237238
// if the search candidate relied on a moduledata va, make sure it lines up with ours now
238239
stomppedMagicMetaConstraintsValid := true

main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
_ "net/http/pprof"
1212
)
1313

14-
var versions = []string{"125", "124", "123", "122", "121", "120", "119", "118", "117", "116", "115", "114", "113", "112", "111", "110", "19", "18", "17", "16", "15"}
14+
var versions = []string{"126", "125", "124", "123", "122", "121", "120", "119", "118", "117", "116", "115", "114", "113", "112", "111", "110", "19", "18", "17", "16", "15"}
1515
var fileNames = []string{"testproject_lin", "testproject_lin_32", "testproject_lin_stripped", "testproject_lin_stripped_32", "testproject_mac", "testproject_mac_stripped", "testproject_win_32.exe", "testproject_win_stripped_32.exe", "testproject_win_stripped.exe", "testproject_win.exe"}
1616

1717
func TestAllVersions(t *testing.T) {

objfile/elf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (f *elfFile) pcln_scan() (candidates <-chan PclntabCandidate, err error) {
133133
send_patched_magic_candidates := func(candidate *PclntabCandidate) {
134134
has_some_valid_magic := false
135135
for _, magic := range append(pclntab_sigs_le, pclntab_sigs_be...) {
136-
if bytes.Equal(candidate.Pclntab, magic) {
136+
if bytes.HasPrefix(candidate.Pclntab, magic) {
137137
has_some_valid_magic = true
138138
break
139139
}

0 commit comments

Comments
 (0)