-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (80 loc) · 2.07 KB
/
main.go
File metadata and controls
88 lines (80 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Package main provides the gostrings command-line tool for extracting strings
// from Go binaries.
//
// gostrings understands Go's internal string representation and can extract
// strings more accurately than traditional tools like the Unix strings command.
// It supports ELF (Linux), Mach-O (macOS), PE (Windows), Plan 9, XCOFF (AIX), and WebAssembly binary formats.
//
// Usage:
//
// gostrings [options] <binary>
//
// Options:
//
// -n int
// minimum string length (default 4)
// -u
// output only unique strings
// -v
// verbose output showing section information
// -filter
// apply smart content filtering (default true)
//
// Example:
//
// # Extract all strings with minimum length 8
// gostrings -n 8 /path/to/binary
//
// # Extract unique strings with verbose output
// gostrings -u -v /path/to/binary
//
// For library usage, see the gostrings package documentation.
package main
import (
"flag"
"fmt"
"os"
"github.com/HEXXDECIMAL/gostrings/pkg/gostrings"
)
func main() {
minLen := flag.Int("n", 4, "minimum string length")
unique := flag.Bool("u", false, "output only unique strings")
verbose := flag.Bool("v", false, "verbose output")
filter := flag.Bool("filter", true, "apply smart content filtering (disable with -filter=false)")
flag.Parse()
if flag.NArg() < 1 {
fmt.Fprintf(os.Stderr, "Usage: %s [options] <binary>\n", os.Args[0])
flag.PrintDefaults()
os.Exit(1)
}
binaryPath := flag.Arg(0)
opts := gostrings.Options{
MinLength: *minLen,
Unique: *unique,
Verbose: *verbose,
Filter: *filter,
}
sections, err := gostrings.Extract(binaryPath, opts)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
// In verbose mode, show section names with indented strings
if *verbose {
for _, sec := range sections {
if len(sec.Strings) > 0 {
fmt.Printf("%s:\n", sec.Name)
for _, s := range sec.Strings {
fmt.Printf(" %s\n", s)
}
}
}
} else {
// In non-verbose mode, just print strings
for _, sec := range sections {
for _, s := range sec.Strings {
fmt.Println(s)
}
}
}
}