166 Commits

Author SHA1 Message Date
kamran ul haq c69cbd66c3 Add function signature reconstruction for Issue #14 (#79)
* Add function signature reconstruction for Issue #14
2026-06-01 14:55:53 -04:00
jtbennett-fe 78c02cc730 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>
v3.3
2026-03-05 16:29:56 -05:00
Stephen Eckels e5bc135355 Add basic 1.25 support #83 2026-02-26 19:03:24 +00:00
kamran ul haq 0ead0ced52 Add lint and test jobs to CI pipeline (#82)
* Add lint and test jobs to CI pipeline

Addresses issue #81 — current CI only checks compilation, no tests run.

- lint (ubuntu-latest): gofmt -l and go vet ./... using default Go
  tooling only, no third-party linters per maintainer guidance

- test (ubuntu-latest): runs build_test_files.sh via Docker to generate
  all 18 Go version binaries (stripped/non-stripped x lin/win/mac x
  32/64-bit), then go test ./... covering TestAllVersions,
  TestWeirdBins, and TestExtractStrings_CompareWithFLOSS

- build (windows-latest): existing release job unchanged

* Fix CI failures: gofmt, missing test binary, and add Go 1.23/1.24

* Add Go 1.23/1.24 to test matrix

- Add Go 1.23 and 1.24 to versions array in both build_test_files.sh
  and main_test.go — all 10 binary variants pass for both versions
2026-02-25 18:13:39 -05:00
kamran ul haq d7f23b7a3e Add -strings flag to extract Go strings from binaries (#77)
* Add -strings flag and ExtractMetadata field

- Add Strings []string to ExtractMetadata struct
- Add -strings command-line flag for string extraction
- Update main_impl and main_impl_tmpfile signatures to accept printStrings parameter
- Add placeholder string extraction logic with TODO marker
- Update printForHuman to display extracted strings section
- Verified flag appears in help and outputs correctly in both JSON and human format

Part of #45

* Implement Go string extraction algorithm

- Create objfile/strings.go with core extraction logic
- Implement FLOSS-based string internment table detection
- Add string candidate scanning (pointer + length pairs)
- Implement findLongestMonotonicRun() for pattern detection
- Add UTF-8 validation and printability filtering
- Minimum string length: 4 characters, 80% printable
- Add helper methods to elfFile: getSections(), is64Bit(), isLittleEndian()
- Update main.go to call file.ExtractStrings() instead of placeholder
- Tested with testproject/testproject: extracts 512 strings successfully
- Extracts real Go strings: type names, runtime symbols, error messages

Based on FLOSS floss/language/go/extract.py algorithm
Part of #45

* Update README with -strings flag documentation

- Add -strings flag to available flags list
- Add Strings field to example JSON output
- Document purpose: extract embedded Go strings from binary

Part of #45

* Add tests validated against FLOSS output

Per maintainer request, added comprehensive test suite:

- strings_floss_test.go: Validates GoReSym against FLOSS reference output
  * 99.2% match rate (648/653 strings match FLOSS)
  * Uses FLOSS output from testproject.exe as ground truth
  * Reference saved in testdata/floss_reference.txt

- strings_test.go: Additional unit tests for:
  * ELF and PE binary string extraction
  * Monotonic run detection algorithm
  * String filtering (printability, minimum length)

- pe.go: Added helper methods (getSections, is64Bit, isLittleEndian)
  to enable string extraction from PE binaries

All tests pass.

* Address PR #77 review comments

- Convert getSections() to iterateSections() using callback pattern to avoid memory pressure
- Add Strings field to GoReSym.proto for external parsers
- Implement iterateSections() for Mach-O format (previously missing)

Changes requested by @stevemk14ebr in review:
1. Memory optimization: Replace array-based section loading with generator pattern
2. Proto definition: Add 'repeated string strings = 13' field
3. Mach-O support: Add missing iterateSections() implementation

* Fix test failures and expand string extraction testing per PR #77 feedback

- Fixed 4 test compilation errors by adding missing printStrings parameter to main_impl() calls
- Added comprehensive TestStringExtraction function with 7 test cases covering Linux/macOS/Windows binaries
- Implemented isPrintable() helper for ASCII validation (range 32-126)

* Align string extraction with FLOSS algorithm per PR #77 review

Rewrite string extraction to match FLOSS (extract.py) logic:
- Sort candidates by address (not length) to fix monotonic run detection
- Add image VA range and max section size filtering for candidates
- Use candidate (pointer, length) pairs for direct extraction from blob
- Replace 80% printable threshold with 100% fully printable check
- Fix PE section addresses to include ImageBase for correct VA comparison

Results: 648 strings extracted from PE test binary, 100% match with FLOSS.

* Run string extraction on test build files

* Extend main test to cover all new versions

* Fix string extraction for old Windows binaries and add length sanity check

1. Add .text to data sections for old Go Windows binaries (1.7-1.10)
   that store strings in the code section instead of .rdata

2. Add maxReasonableStringLength (64KB) to filter out garbage candidates
   with huge lengths that cause incorrect blob boundary detection

3. Update TestIsDataSection to reflect .text being a valid data section

Fixes string extraction failures on:
- Old Windows PE binaries (Go 1.7-1.10): 0 -> 256 strings
- Modern Windows: 574 strings
- macOS: 284 strings

All tests pass including TestWeirdBins on 15 real binaries.

* Fix test failures for Go 1.5/1.6 and Go 1.22 macOS; fix build script typo

1. main_test.go: Skip Strings check for Go 1.5/1.6
   Pre-SSA C-based linker does not produce length-sorted string blobs,
   so findLongestMonotonicRun never reaches the minimum threshold of 10.
   Pattern mirrors the existing interface-parsing guard.

2. objfile/strings.go: Handle prevNull == -1 in findStringBlobRange
   Apple's linker on newer Go/macOS (1.22+) packs sections without leading
   padding, so no null bytes exist before the first string candidate.
   bytes.LastIndex returns -1 in that case; treat it as offset 0 instead
   of bailing out with nil.

3. objfile/macho.go: Add missing is64Bit/isLittleEndian for machoFile
   elfFile and peFile already implement these interface methods; machoFile
   was the only rawFile implementation without them. Detect CPU type
   (CpuAmd64/Arm64 = 64-bit) and byte order from the macho.File struct.

4. build_test_files.sh: Fix $ver typo -> $GO_VER on mkdir line
   The directory was never created before Docker ran, causing Go 1.5
   builds to produce no output. Now all 12 binaries are built for
   every version including 1.5 and 1.6.

---------

Co-authored-by: Stephen Eckels <stevemk14ebr@gmail.com>
v3.2
2026-02-17 10:14:48 -05:00
kamran ul haq a3ebe90f33 Refactor moduledata parsing using field offset tables (Issue #55) (#78)
* Refactor moduledata parsing using field offset tables (Issue #55)

This commit refactors moduledata parsing for Go versions 1.16-1.24 to use
a data-driven approach with field offset tables instead of repetitive
version-specific switch statements.

Changes:
- Add objfile/layouts.go with generic field offset layout system
- Add objfile/layouts_test.go with comprehensive test coverage
- Refactor objfile/objfile.go to use generic parser for Go 1.16-1.24
- Reduce code from ~430 lines of switches to ~60 lines of generic code

Benefits:
- 85% code reduction for supported versions (430 → 62 lines)
- Adding new Go versions requires only ~8 lines of layout data
- Single parsing logic eliminates duplicate code
- Comprehensive test suite ensures correctness

Testing:
- All existing tests pass
- New tests verify layout offsets match struct definitions
- Backward compatibility tests ensure identical output
- Tested against real Go 1.17.2 binary (testproject)

Fixes #55

* Extend moduledata refactoring to Go 1.5-1.15 (Issue #55)

Extends the layout table approach to older Go versions (1.5-1.15),
eliminating 228 lines of repetitive switch statements.

Changes:
- Add layout definitions for Go 1.5-1.6, 1.7, and 1.8-1.15 to layouts.go
- Add validateAndConvertModuleData_Legacy() for Go 1.7-1.15
- Add validateAndConvertModuleData_Legacy_NoTypes() for Go 1.5-1.6
- Refactor objfile.go case "1.2" block (228 lines → 75 lines)
- Add comprehensive tests for legacy versions (17 new test cases)

Benefits:
- 67% code reduction in legacy version handling
- Consistent parsing approach across Go 1.5-1.24 (20 versions)
- Improved maintainability and extensibility
- Single source of truth for moduledata layouts

Testing:
- All existing unit tests pass
- Added TestLayoutOffsets_Legacy_Versions (6 subtests)
- Added TestVersionMapping_Legacy (11 subtests)
- Total: 17 new test cases validating legacy version support

Code Metrics:
- objfile/objfile.go: 1,783 → 1,628 lines (-155 lines)
- objfile/layouts.go: 436 → 564 lines (+128 lines infrastructure)
- objfile/layouts_test.go: 380 → 590 lines (+210 lines tests)
- Net: -155 lines of duplicate code eliminated

Addresses maintainer feedback on PR #78 (moduledata portion).
Type parsing refactoring (Phase 2) to follow in next commit.

* Extend type parsing refactoring to all Go versions (Issue #55)

Refactors type parsing (ParseType_impl) to use the layout table approach,
eliminating 158 lines of repetitive version-specific switch statements.

Changes:
- Add RtypeLayout system to layouts.go for Go 1.5-1.24
- Add parseRtypeGeneric() for generic type parsing
- Add getRtypeFieldOffset() helper function
- Refactor ParseType_impl() to use generic parser (208 lines → 50 lines)
- Add comprehensive tests for Rtype layouts (23 test cases)

Benefits:
- 76% code reduction in type parsing (208 lines → 50 lines)
- Consistent parsing approach for all Go 1.5-1.24 type structures
- Single source of truth for Rtype layouts
- Improved maintainability

Testing:
- All existing tests pass
- Added TestRtypeLayoutOffsets (3 subtests)
- Added TestRtypeVersionMapping (20 subtests)
- Total: 23 new test cases validating Rtype support

Code Metrics:
- objfile/objfile.go: 1,628 → 1,470 lines (-158 lines)
- objfile/layouts.go: 564 → 786 lines (+222 lines infrastructure)
- objfile/layouts_test.go: 590 → 748 lines (+158 lines tests)

Combined with Phase 1:
- Total code reduction: 313 lines from objfile.go
- ModuleData + Type parsing: ~650 lines → ~125 lines (81% reduction)

Completes maintainer feedback on PR #78 (type parsing portion).

* PR #78: Change #1 complete – replace string field metadata with enums; generic parsers updated; tests adjusted; add InterfaceLayout scaffolding
2026-01-13 13:46:33 -05:00
random ccc8e1baf2 add cli support + ida 9 compatibility (#76) 2025-12-01 13:28:24 -05:00
Stephen Eckels 734a93aaf6 Try to fix version in action v3.1.2 2025-08-08 13:50:38 +00:00
Stephen Eckels cdb1ef7ae3 Fix yaml format issue 2025-08-08 13:34:03 +00:00
Stephen Eckels becfccb1e5 Add version to output, embed tag as version in action 2025-08-08 13:30:07 +00:00
Stephen Eckels abe68451f2 Fix release GH workflow
Try to fix GH workflow
v3.1.1
2025-08-07 10:53:07 -04:00
Stephen Eckels 6dd1aeb4d8 Fix argument parsing bug, fix 1.19 and 1.17 moduldata fallthroughs v3.1 2025-08-07 14:33:52 +00:00
Krishna Yarlagadda cb029c6522 Add Go 1.24 support with ABIType parsing (#73)
* Add Go 1.24 support with ABIType parsing

- Add ABIType64/ABIType32 structs for Go 1.20+ type descriptors
- Extend moduledata version switch to support Go 1.21-1.24
- Update readRTypeName to handle Go 1.23-1.24 varint encoding
- Modify ParseType_impl to use ABIType for Go 1.20-1.24
- Add Go 1.21-1.24 support to interface methods and struct fields parsing
- Update pclntab parser version overrides for Go 1.21-1.24
- Document Go 1.24 support in README

Maintains backward compatibility while adding full support for
Go 1.24 binaries and newer runtime type descriptor formats.

* Remove specific Go 1.24 mention from version support section
2025-08-07 09:15:01 -04:00
Stephen Eckels 2a4af8e09c Add logo 2025-06-06 15:18:20 +00:00
Stephen Eckels 0125e4c958 Fix argc bug 2025-02-21 14:56:33 -05:00
Stephen Eckels a6bdd54b6a Fix tests v3.0.2 2025-02-11 19:39:21 -05:00
Stephen Eckels 45d5c9d606 Optimize and omit duplicate pattern matches (#66) (#68)
Co-authored-by: ViRb3 <ViRb3@users.noreply.github.com>
v3.0.1
2024-10-19 14:59:29 -04:00
Stephen Eckels 54a6712945 Remove candidate cache, use go channel for generator of candidates v3.0 2024-10-19 14:21:17 -04:00
Stephen Eckels 534ca84b42 Fix range length calculations and add more regex tests 2024-08-19 16:29:32 +00:00
Stephen Eckels 784db2d9be Add more regex unit tests 2024-08-19 15:43:17 +00:00
ViRb3 d7d9a98b02 More fixes and improvements to pattern matching (#64)
* Support pattern negated byte

* Optimize pattern sub-matches

* Fix one-off pattern mismatch

* Fix test

* Fix test

* Revert "Optimize pattern sub-matches"

This reverts commit 6f4badc4b7.

* Simplify data_end calculation

---------

Co-authored-by: Stephen Eckels <stepheneckels@google.com>
Co-authored-by: Stephen Eckels <stevemk14ebr@gmail.com>
2024-08-19 11:14:16 -04:00
Annie Nie 82e128d8a0 fixed compatibility for ghidrathon and jython (#65) 2024-08-19 09:30:54 -04:00
ViRb3 c25fb120cd Fixes and improvements to pattern matching (#63) 2024-08-16 15:30:15 -04:00
Philippe Ombredanne e3bc1884ad Optionally skip printing the function sections (#60)
* Optionally skip printing the function sections

Add a new -no-functions command line flag to skip printing the
UserFunctions and StdFunctions detailed sections.
This is useful to get a quick summary of what is in a Go binary.
The default is to always print the function sections.

Reference: https://github.com/mandiant/GoReSym/issues/49
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>

* Optionally skip printing the function sections

Use -nofuncs command line flag instead.
Reorder main_impl() function arguments.

Reference: https://github.com/mandiant/GoReSym/issues/49
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>

---------

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2024-08-02 10:26:59 -04:00
brigadier-general 128f46b161 reverting bad commits! -- pclntab.go 2024-06-10 16:06:09 -05:00
brigadier-general fce172d55e adding Gofunc field to LineTable -- pclntab.go 2024-06-10 16:04:33 -05:00
brigadier-general 8df84f7258 adding Gofunc param to NewLineTable() -- pclntab.go 2024-06-10 16:03:40 -05:00
brigadier-general 5398a6a329 Reverting commits 82f4cfd, d0f297e, 0d5caca -- wrong branch 2024-06-10 15:42:17 -05:00
brigadier-general 82f4cfdfbf adding param to PCLineTable 2024-06-10 15:23:18 -05:00
brigadier-general d0f297e470 adding Gofunc field to pclntabcandidate struct 2024-06-10 15:21:28 -05:00
brigadier-general 0d5cacac35 adding Gofunc field input to NewLineTable 2024-06-10 15:19:52 -05:00
Sven Ulke 62070ed5c3 Fixes to make goresym ghidrathon compatible (#57) 2024-05-30 16:42:32 -04:00
Stephen Eckels cc91ae744f Fix workflow v2.7.4 2024-05-07 10:49:58 -04:00
Stephen Eckels 6e65730ad1 Separate Release Workflow by OS 2024-05-07 10:46:32 -04:00
Stephen Eckels 7c37bd7476 Update README.md v2.7.3 2024-04-15 10:01:19 -04:00
Stephen Eckels 80893bd677 Add about and license info 2024-04-15 13:58:43 +00:00
Stephen Eckels 76f8f7c2d3 Fix attempt logic in moduledata scan to ignore erroneous early hits and add them to the ignorelist, resolves #50 v2.7.2 2024-02-23 12:49:00 -05:00
Stephen Eckels 0860a1b1b4 Update README.md 2024-02-08 14:59:59 -05:00
Stephen Eckels 9c9af9a984 Update README.md 2024-02-08 13:52:16 -05:00
Stephen Eckels 5e8c513087 Rollback module go version v2.7.1 2024-02-08 17:52:17 +00:00
Stephen Eckels 7918cd1750 Rollback CI version 2024-02-08 17:50:18 +00:00
Stephen Eckels 9307a5e1e4 Merge some upstream changes v2.7.0 2024-02-08 17:48:22 +00:00
Stephen Eckels a2567ab318 Fix 1.21 and 1.22 moduledata, add basic 1.22 support 2024-02-08 17:19:49 +00:00
Stephen Eckels d75fbb44e7 Merge branch 'master' of https://github.com/mandiant/GoReSym v2.6.4 2023-11-28 14:41:49 -05:00
Stephen Eckels 7c3a6bb8e7 Remove x64 signature on nop, as it's not always present 2023-11-28 14:41:31 -05:00
Stephen Eckels c7be20ecb0 Update README.md 2023-11-27 12:34:18 -05:00
Stephen Eckels e1627a7d31 Update README.md 2023-11-27 12:33:57 -05:00
Stephen Eckels e867149423 Resolve #42 v2.6.3 2023-11-10 11:39:36 -05:00
Stephen Eckels 7e2623758c Widen x64 signature, partial fix for #42 2023-11-10 10:55:08 -05:00
Stephen Eckels fd75e4c4f8 Use higher level type apis 2023-10-13 10:39:03 -04:00