Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally skip printing the function sections #60

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type ExtractMetadata struct {
StdFunctions []FuncMetadata
}

func main_impl_tmpfile(fileBytes []byte, printStdPkgs bool, printFilePaths bool, printTypes bool, manualTypeAddress int, versionOverride string) (metadata ExtractMetadata, err error) {
func main_impl_tmpfile(fileBytes []byte, printStdPkgs bool, printFilePaths bool, printTypes bool, manualTypeAddress int, versionOverride string, noPrintFunctions bool) (metadata ExtractMetadata, err error) {
tmpFile, err := os.CreateTemp(os.TempDir(), "goresym_tmp-")
if err != nil {
return ExtractMetadata{}, fmt.Errorf("failed to create temporary file: %s", err)
Expand All @@ -81,10 +81,10 @@ func main_impl_tmpfile(fileBytes []byte, printStdPkgs bool, printFilePaths bool,
return ExtractMetadata{}, fmt.Errorf("failed to close temporary file: %s", err)
}

return main_impl(tmpFile.Name(), printStdPkgs, printFilePaths, printTypes, manualTypeAddress, versionOverride)
return main_impl(tmpFile.Name(), printStdPkgs, printFilePaths, printTypes, manualTypeAddress, versionOverride, noPrintFunctions)
}

func main_impl(fileName string, printStdPkgs bool, printFilePaths bool, printTypes bool, manualTypeAddress int, versionOverride string) (metadata ExtractMetadata, err error) {
func main_impl(fileName string, printStdPkgs bool, printFilePaths bool, printTypes bool, manualTypeAddress int, versionOverride string, noPrintFunctions bool) (metadata ExtractMetadata, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move noPrintFunctions arg to right after printTypes for consistency with the order of where the rest of the output related args are.

extractMetadata := ExtractMetadata{}

file, err := objfile.Open(fileName)
Expand Down Expand Up @@ -286,23 +286,25 @@ restartParseWithRealTextBase:
}
}

for _, elem := range finalTab.ParsedPclntab.Funcs {
if isStdPackage(elem.PackageName()) {
if printStdPkgs {
extractMetadata.StdFunctions = append(extractMetadata.StdFunctions, FuncMetadata{
if !noPrintFunctions {
for _, elem := range finalTab.ParsedPclntab.Funcs {
if isStdPackage(elem.PackageName()) {
if printStdPkgs {
extractMetadata.StdFunctions = append(extractMetadata.StdFunctions, FuncMetadata{
Start: elem.Entry,
End: elem.End,
PackageName: elem.PackageName(),
FullName: elem.Name,
})
}
} else {
extractMetadata.UserFunctions = append(extractMetadata.UserFunctions, FuncMetadata{
Start: elem.Entry,
End: elem.End,
PackageName: elem.PackageName(),
FullName: elem.Name,
})
}
} else {
extractMetadata.UserFunctions = append(extractMetadata.UserFunctions, FuncMetadata{
Start: elem.Entry,
End: elem.End,
PackageName: elem.PackageName(),
FullName: elem.Name,
})
}
}

Expand Down Expand Up @@ -425,6 +427,7 @@ func main() {
typeAddress := flag.Int("m", 0, "Manually parse the RTYPE at the provided virtual address, disables automated enumeration of moduledata typelinks itablinks")
versionOverride := flag.String("v", "", "Override the automated version detection, ex: 1.17. If this is wrong, parsing may fail or produce nonsense")
humanView := flag.Bool("human", false, "Human view, print information flat rather than json, some information is omitted for clarity")
noPrintFunctions := flag.Bool("no-functions", false, "Do not print user and standard function sections")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the dash here in the arg name. Lets choose something that's a single word, nofuncs works nice and is short.

flag.Parse()

if *about {
Expand All @@ -442,7 +445,7 @@ func main() {
os.Exit(1)
}

metadata, err := main_impl(flag.Arg(0), *printStdPkgs, *printFilePaths, *printTypes, *typeAddress, *versionOverride)
metadata, err := main_impl(flag.Arg(0), *printStdPkgs, *printFilePaths, *printTypes, *typeAddress, *versionOverride, *noPrintFunctions)
if err != nil {
fmt.Println(TextToJson("error", fmt.Sprintf("Failed to parse file: %s", err)))
os.Exit(1)
Expand Down
8 changes: 4 additions & 4 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestAllVersions(t *testing.T) {
}

t.Run(versionPath, func(t *testing.T) {
data, err := main_impl(filePath, true, true, true, 0, "")
data, err := main_impl(filePath, true, true, true, 0, "", true)
if err != nil {
t.Errorf("Go %s failed on %s: %s", v, file, err)
}
Expand Down Expand Up @@ -119,7 +119,7 @@ func testSymbolRecovery(t *testing.T, workingDirectory string, binaryName string
return
}

data, err := main_impl(filePath, true, true, true, 0, "")
data, err := main_impl(filePath, true, true, true, 0, "", true)
if err != nil {
t.Errorf("GoReSym failed: %s", err)
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestWeirdBins(t *testing.T) {
return
}

_, err := main_impl(filePath, true, true, true, 0, "")
_, err := main_impl(filePath, true, true, true, 0, "", true)
if err == nil {
t.Errorf("GoReSym found pclntab in a non-go binary, this is not possible.")
}
Expand All @@ -228,7 +228,7 @@ func TestWeirdBins(t *testing.T) {
return
}

_, err := main_impl(filePath, true, true, true, 0, "")
_, err := main_impl(filePath, true, true, true, 0, "", true)
if err == nil {
t.Errorf("GoReSym found pclntab in a non-go binary, this is not possible.")
}
Expand Down
Loading