-
Notifications
You must be signed in to change notification settings - Fork 68
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
stevemk14ebr
merged 2 commits into
mandiant:master
from
pombredanne:49-skip-printing-functions
Aug 2, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) { | ||
extractMetadata := ExtractMetadata{} | ||
|
||
file, err := objfile.Open(fileName) | ||
|
@@ -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, | ||
}) | ||
} | ||
} | ||
|
||
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
flag.Parse() | ||
|
||
if *about { | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.