-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
719 lines (607 loc) · 19.9 KB
/
main.go
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
package main
import (
"bufio"
"embed"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"time"
)
const (
Reset = "\033[0m"
Red = "\033[31m"
Green = "\033[32m"
Yellow = "\033[33m"
Blue = "\033[34m"
Magenta = "\033[35m"
Cyan = "\033[36m"
White = "\033[37m"
)
type FileModification struct {
path string
originalSize int64
modifiedSize int64
stringsRemoved int
}
//go:embed wordlists/default.txt
var defaultWordlist embed.FS
var shellCount int
var verbose bool
const banner = `
` + Red + `
===========================================================================================
` + Cyan + `
_ _ _ _ _____ _ _ _ ______ _ _
| | | | | | | / ___| | | | | | ___(_) | |
| | | | ___ _ __| | __| \ ` + "`" + `--.| |__ ___| | | | |_ _ _ __ __| | ___ _ __
| |/\| |/ _ \| '__| |/ _` + "`" + ` |` + "`" + `--. \ '_ \ / _ \ | | | _| | | '_ \ / _` + "`" + ` |/ _ \ '__|
\ /\ / (_) | | | | (_| /\__/ / | | | __/ | | | | | | | | | (_| | __/ |
\/ \/ \___/|_| |_|\__,_\____/|_| |_|\___|_|_| \_| |_|_| |_|\__,_|\___|_|
` + Reset + `
made with love by ` + Yellow + ` Worldsavior/Arya-f4 ` + Magenta + `^^ ` + Green + ` v.1.2.3.0 Stable Build ` + Reset + `
===========================================================================================
`
const menuText = `
Please choose an option:
1. Normal WebShell Detection
2. Remove String from Files
`
func loadingAnimation(done chan bool) {
chars := []rune{'|', '/', '-', '\\'}
for {
select {
case <-done:
fmt.Print("\rOperation complete! \n")
return
default:
for _, c := range chars {
fmt.Printf("\rProcessing... %c", c)
time.Sleep(100 * time.Millisecond)
}
}
}
}
func removeStringFromFile(filePath string, stringToRemove string) (*FileModification, error) {
// Read the file
content, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
originalSize := int64(len(content))
originalContent := string(content)
// Count how many instances were removed
stringsRemoved := strings.Count(originalContent, stringToRemove)
// Only proceed if we found matches
if stringsRemoved == 0 {
return nil, nil
}
// Convert to string and remove the specified string
newContent := strings.ReplaceAll(originalContent, stringToRemove, "")
// Write back to the file
err = os.WriteFile(filePath, []byte(newContent), 0644)
if err != nil {
return nil, err
}
// Return modification info
return &FileModification{
path: filePath,
originalSize: originalSize,
modifiedSize: int64(len(newContent)),
stringsRemoved: stringsRemoved,
}, nil
}
func removeStringFromDirectory(directory string, stringToRemove string) error {
var modifications []*FileModification
var totalFilesScanned int
var totalFilesModified int
var totalStringsRemoved int
err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Printf("Error accessing file or directory: %v\n", err)
return nil
}
if !info.IsDir() {
totalFilesScanned++
modification, err := removeStringFromFile(path, stringToRemove)
if err != nil {
log.Printf("Error processing file %s: %v\n", path, err)
return nil
}
if modification != nil {
modifications = append(modifications, modification)
totalFilesModified++
totalStringsRemoved += modification.stringsRemoved
}
if verbose {
fmt.Printf("Processed file: %s\n", path)
}
}
return nil
})
// Print summary after processing
fmt.Printf("\n%sString Removal Summary:%s\n", Yellow, Reset)
fmt.Printf("Total files scanned: %d\n", totalFilesScanned)
fmt.Printf("Total files modified: %d\n", totalFilesModified)
fmt.Printf("Total strings removed: %d\n", totalStringsRemoved)
if len(modifications) > 0 {
fmt.Printf("\n%sModified Files:%s\n", Green, Reset)
for _, mod := range modifications {
fmt.Printf("- %s\n", mod.path)
fmt.Printf(" Strings removed: %d\n", mod.stringsRemoved)
fmt.Printf(" Size change: %d bytes -> %d bytes\n", mod.originalSize, mod.modifiedSize)
}
} else {
fmt.Printf("\n%sNo files were modified.%s\n", Blue, Reset)
}
return err
}
// [Previous functions remain the same: loadKeywords, scanFiles, containsKeywords, updateFromRepository]
func printHelp() {
fmt.Print("Usage: worldfind <directory>\n")
fmt.Print("Options:\n")
fmt.Print("1. Normal WebShell Detection where it's only detect webshells in files\n")
fmt.Print(" Output Example : File: C:/directory/file.php\n")
fmt.Print(" Line number: 4\n")
fmt.Print(" Detection type: Keyword Match\n")
fmt.Print(" Matched keyword: gzinflate(base64_decode(")
}
func updateFromRepository(repoURL string) error {
// Detect OS and architecture
osType := runtime.GOOS
archType := runtime.GOARCH
// Construct the download URL based on the OS and architecture
downloadURL := fmt.Sprintf("%s/releases/latest/download/%s_%s", repoURL, osType, archType)
fmt.Printf("Downloading update from: %s\n", downloadURL)
// Create a temp file to download the new binary
tmpFile, err := os.CreateTemp("", "worldshellfinder_*")
if err != nil {
return fmt.Errorf("failed to create temp file: %w", err)
}
defer tmpFile.Close()
// Download the new binary
resp, err := http.Get(downloadURL)
if err != nil {
return fmt.Errorf("failed to download update: %w", err)
}
defer resp.Body.Close()
// Check for successful response
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download update: HTTP %d", resp.StatusCode)
}
// Write the downloaded binary to the temp file
_, err = io.Copy(tmpFile, resp.Body)
if err != nil {
return fmt.Errorf("failed to write update to file: %w", err)
}
// Get the path of the current running binary
executablePath, err := os.Executable()
if err != nil {
return fmt.Errorf("failed to get current executable path: %w", err)
}
// Replace the current binary with the new one
err = os.Rename(tmpFile.Name(), executablePath)
if err != nil {
return fmt.Errorf("failed to replace current binary: %w", err)
}
// Make the new binary executable
err = os.Chmod(executablePath, 0755)
if err != nil {
return fmt.Errorf("failed to make new binary executable: %w", err)
}
fmt.Println("Update complete! Restarting the application...")
// Restart the application
cmd := exec.Command(executablePath)
cmd.Start() // Start the new process
os.Exit(0) // Exit the current process
return nil
}
func loadKeywords(wordlistPath string) ([]string, error) {
var keywords []string
// Load default embedded wordlist first
file, err := defaultWordlist.Open("wordlists/default.txt")
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
keyword := strings.TrimSpace(scanner.Text())
if keyword != "" {
keywords = append(keywords, keyword)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
// If an external wordlist is provided, append its keywords to the default list
if wordlistPath != "" {
file, err := os.Open(wordlistPath)
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
keyword := strings.TrimSpace(scanner.Text())
if keyword != "" {
keywords = append(keywords, keyword)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
}
return keywords, nil
}
type ShellDetection struct {
path string
keyword string
lineNumber int
isRegexMatch bool
matchedLine string
}
func containsKeywords(filename string, keywords []string, regexes []*regexp.Regexp) (*ShellDetection, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
buf := make([]byte, 1024*1024) // 1MB buffer
scanner.Buffer(buf, 20*1024*1024) // Set max token size to 20MB
lineNumber := 0
for scanner.Scan() {
lineNumber++
line := scanner.Text()
// Check keywords
for _, keyword := range keywords {
if strings.Contains(line, keyword) {
return &ShellDetection{
path: filename,
keyword: keyword,
lineNumber: lineNumber,
isRegexMatch: false,
matchedLine: line,
}, nil
}
}
// Check regex patterns
for _, rx := range regexes {
if rx.MatchString(line) {
return &ShellDetection{
path: filename,
keyword: "regex_pattern",
lineNumber: lineNumber,
isRegexMatch: true,
matchedLine: line,
}, nil
}
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return nil, nil
}
func scanFiles(directory string, keywords []string, regexes []*regexp.Regexp) {
var detections []*ShellDetection
var totalFilesScanned int
err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Printf("Error accessing file or directory: %v\n", err)
return nil
}
if !info.IsDir() {
totalFilesScanned++
if verbose {
fmt.Printf("\rScanning: %s", path)
}
detection, err := containsKeywords(path, keywords, regexes)
if err != nil {
log.Printf("\nError reading file: %v\n", err)
return nil
}
if detection != nil {
detections = append(detections, detection)
shellCount++
}
}
return nil
})
if err != nil {
log.Fatalf("\nError scanning files: %v\n", err)
}
// Clear the scanning line if in verbose mode
if verbose {
fmt.Print("\r")
}
// Print summary
fmt.Printf("\n%sWebShell Detection Summary:%s\n", Yellow, Reset)
fmt.Printf("Total files scanned: %d\n", totalFilesScanned)
fmt.Printf("Total potential webshells found: %d\n", shellCount)
if len(detections) > 0 {
fmt.Printf("\n%sPotential WebShells Found:%s\n", Red, Reset)
for _, detect := range detections {
fmt.Printf("\n- File: %s\n", detect.path)
fmt.Printf(" Line number: %d\n", detect.lineNumber)
if detect.isRegexMatch {
fmt.Printf(" Detection type: %sRegex Pattern Match%s\n", Magenta, Reset)
} else {
fmt.Printf(" Detection type: %sKeyword Match%s\n", Blue, Reset)
fmt.Printf(" Matched keyword: %s\n", detect.keyword)
}
if verbose {
// Show the matched line with some context
fmt.Printf(" Matched line: %s\n", strings.TrimSpace(detect.matchedLine))
}
}
} else {
fmt.Printf("\n%sNo potential webshells were found.%s\n", Green, Reset)
}
}
func writeDetectionsToFile(filepath string, detections []*ShellDetection, totalFilesScanned int) error {
file, err := os.Create(filepath)
if err != nil {
return err
}
defer file.Close()
writer := bufio.NewWriter(file)
// Write header
fmt.Fprintf(writer, "WebShell Detection Report\n")
fmt.Fprintf(writer, "Generated: %s\n", time.Now().Format("2006-01-02 15:04:05"))
fmt.Fprintf(writer, "Total files scanned: %d\n", totalFilesScanned)
fmt.Fprintf(writer, "Total potential webshells found: %d\n\n", len(detections))
// Write each detection
for i, detect := range detections {
fmt.Fprintf(writer, "Detection #%d:\n", i+1)
fmt.Fprintf(writer, "- File: %s\n", detect.path)
fmt.Fprintf(writer, "- Line number: %d\n", detect.lineNumber)
if detect.isRegexMatch {
fmt.Fprintf(writer, "- Detection type: Regex Pattern Match\n")
} else {
fmt.Fprintf(writer, "- Detection type: Keyword Match\n")
fmt.Fprintf(writer, "- Matched keyword: %s\n", detect.keyword)
}
fmt.Fprintf(writer, "- Matched line: %s\n\n", strings.TrimSpace(detect.matchedLine))
}
return writer.Flush()
}
func writeModificationsToFile(filepath string, modifications []*FileModification, totalFilesScanned int, totalStringsRemoved int) error {
file, err := os.Create(filepath)
if err != nil {
return err
}
defer file.Close()
writer := bufio.NewWriter(file)
// Write header
fmt.Fprintf(writer, "String Removal Report\n")
fmt.Fprintf(writer, "Generated: %s\n", time.Now().Format("2006-01-02 15:04:05"))
fmt.Fprintf(writer, "Total files scanned: %d\n", totalFilesScanned)
fmt.Fprintf(writer, "Total files modified: %d\n", len(modifications))
fmt.Fprintf(writer, "Total strings removed: %d\n\n", totalStringsRemoved)
// Write each modification
for i, mod := range modifications {
fmt.Fprintf(writer, "Modification #%d:\n", i+1)
fmt.Fprintf(writer, "- File: %s\n", mod.path)
fmt.Fprintf(writer, "- Strings removed: %d\n", mod.stringsRemoved)
fmt.Fprintf(writer, "- Original size: %d bytes\n", mod.originalSize)
fmt.Fprintf(writer, "- Modified size: %d bytes\n", mod.modifiedSize)
fmt.Fprintf(writer, "- Size difference: %d bytes\n\n", mod.originalSize-mod.modifiedSize)
}
return writer.Flush()
}
func main() {
// Define flags
helpFlag := flag.Bool("h", false, "display help information")
helpFlagLong := flag.Bool("help", false, "display help information")
// Parse flags
flag.Parse()
// Print banner first
fmt.Print(banner)
// Check for help flags
if *helpFlag || *helpFlagLong {
printHelp()
return
}
args := flag.Args()
// Handle update command
if len(args) > 0 && args[0] == "--update" {
repoURL := "github.com/Arya-f4/worldshellfinder"
err := updateFromRepository(repoURL)
if err != nil {
log.Fatalf("Error While Updating: %v\n", err)
}
fmt.Println("Update done.")
return
}
// Show menu if no specific command-line options
fmt.Print(menuText)
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter your choice (1 or 2): ")
choice, _ := reader.ReadString('\n')
choice = strings.TrimSpace(choice)
// Get directory path
fmt.Print("Enter the directory to scan: ")
directory, _ := reader.ReadString('\n')
directory = strings.TrimSpace(directory)
// Get output file path
fmt.Print("Enter the output file path (press Enter for no file output): ")
outputFile, _ := reader.ReadString('\n')
outputFile = strings.TrimSpace(outputFile)
switch choice {
case "1":
// Normal WebShell Detection
keywords, err := loadKeywords("")
if err != nil {
log.Fatalf("Fail to load Keyword: %v\n", err)
}
regexPatterns := []string{
`(?i)(eval|assert|system|shell_exec|passthru)\s*\(\s*["']?[a-zA-Z0-9+/=]{20,}["']?\s*\)`,
`(?i)(exec|system|popen|proc_open)\s*\(\s*\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[([^\]]+)\]\s*\)`,
`(?i)move_uploaded_file\s*\(.*?,\s*['"]\.\./(.*?)\.php['"]\s*\)`,
`(?i)(passthru|shell_exec|system|exec)\s*\(\s*\$_(?:GET|POST|REQUEST|COOKIE|SERVER)\[.*?\]\s*\)`,
`eval\(\s*\$\w+\s*\(\s*\$\w+\s*\(\s*\$\w+\s*\(\s*\$\w+\s*\(\s*\$\w+\s*\)\s*\)\s*\)\s*\)\s*\)\s*;`,
`(?i)is_dir\s*\(\s*\$\w+\s*\)\s*\?\s*rmdir\s*\(\s*\$\w+\s*\)\s*:\s*unlink\s*\(\s*\$\w+\s*\)\s*;`,
`(?i)if\s*\(\s*is_dir\s*\(\s*\$\w+\s*\)\s*&&\s*is_readable\s*\(\s*\$\w+\s*\)\s*&&\s*!\s*is_link\s*\(\s*\$\w+\s*\)\s*\)\s*{`,
`(?i)__halt_compiler\s*\(\s*\)\s*`,
`(?:isset\s*\(\s*\$_SERVER\s*\[\s*['"]H(?:['"]\s*\.\s*['"])?T(?:['"]\s*\.\s*['"])?T(?:['"]\s*\.\s*['"])?P(?:['"]\s*\.\s*['"])?S['"]\]\s*\)|\$_SERVER\s*\[\s*['"]H(?:['"]\s*\.\s*['"])?T(?:['"]\s*\.\s*['"])?T(?:['"]\s*\.\s*['"])?P(?:['"]\s*\.\s*['"])?S['"]\]\s*===\s*(?:['"]o(?:['"]\s*\.\s*['"])?n['"]|['"]on['"]))\s*(?:\?\s*['"]ht(?:['"]\s*\.\s*['"])?tp(?:['"]\s*\.\s*['"])?s['"]\s*:\s*['"]ht(?:['"]\s*\.\s*['"])?tp['"]|\)\s*\.\s*['"]://['"]\s*\.\s*\$_SERVER\s*\[\s*['"]HT(?:['"]\s*\.\s*['"])?T(?:['"]\s*\.\s*['"])?P(?:['"]\s*\.\s*['"])?_H(?:['"]\s*\.\s*['"])?OS(?:['"]\s*\.\s*['"])?T['"])`,
}
var regexes []*regexp.Regexp
for _, pattern := range regexPatterns {
rx, err := regexp.Compile(pattern)
if err != nil {
log.Fatalf("Failed to compile regex: %v\n", err)
}
regexes = append(regexes, rx)
}
var detections []*ShellDetection
var totalFilesScanned int
done := make(chan bool)
go loadingAnimation(done)
// Walk through directory and collect detections
err = filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Printf("Error accessing file or directory: %v\n", err)
return nil
}
if !info.IsDir() {
totalFilesScanned++
if verbose {
fmt.Printf("\rScanning: %s", path)
}
detection, err := containsKeywords(path, keywords, regexes)
if err != nil {
log.Printf("\nError reading file: %v\n", err)
return nil
}
if detection != nil {
detections = append(detections, detection)
shellCount++
}
}
return nil
})
done <- true
// Print results to console
fmt.Printf("\n%sWebShell Detection Summary:%s\n", Yellow, Reset)
fmt.Printf("Total files scanned: %d\n", totalFilesScanned)
fmt.Printf("Total potential webshells found: %d\n", len(detections))
if len(detections) > 0 {
fmt.Printf("\n%sPotential WebShells Found:%s\n", Red, Reset)
for _, detect := range detections {
fmt.Printf("\n- File: %s\n", detect.path)
fmt.Printf(" Line number: %d\n", detect.lineNumber)
if detect.isRegexMatch {
fmt.Printf(" Detection type: %sRegex Pattern Match%s\n", Magenta, Reset)
} else {
fmt.Printf(" Detection type: %sKeyword Match%s\n", Blue, Reset)
fmt.Printf(" Matched keyword: %s\n", detect.keyword)
}
if verbose {
fmt.Printf(" Matched line: %s\n", strings.TrimSpace(detect.matchedLine))
}
}
} else {
fmt.Printf("\n%sNo potential webshells were found.%s\n", Green, Reset)
}
// Write to file if specified
if outputFile != "" {
err = writeDetectionsToFile(outputFile, detections, totalFilesScanned)
if err != nil {
log.Printf("Error writing to output file: %v\n", err)
} else {
fmt.Printf("\nResults have been saved to: %s\n", outputFile)
}
}
case "2":
fmt.Print("Enter string to remove (press Ctrl+D or Ctrl+Z when done): ")
// Create a buffer with 10MB capacity
largeBuffer := make([]byte, 10*1024*1024) // 10MB buffer
var totalSize int64
maxSize := int64(10 * 1024 * 1024) // 10MB limit
// Create a buffer to store the complete input
var builder strings.Builder
builder.Grow(len(largeBuffer)) // Pre-allocate capacity
// Read input in chunks
for {
n, err := reader.Read(largeBuffer)
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("Error reading input: %v\n", err)
}
// Check total size
totalSize += int64(n)
if totalSize > maxSize {
log.Fatalf("Input exceeds maximum size of 10MB\n")
}
// Write chunk to builder
builder.Write(largeBuffer[:n])
}
stringToRemove := strings.TrimSpace(builder.String())
if stringToRemove == "" {
fmt.Println("Error: Empty string provided")
return
}
// Print size of string being removed
fmt.Printf("String size to remove: %.2f MB\n", float64(len(stringToRemove))/(1024*1024))
var modifications []*FileModification
var totalFilesScanned int
var totalStringsRemoved int
done := make(chan bool)
go loadingAnimation(done)
// Walk through directory
err := filepath.Walk(directory, func(path string, info os.FileInfo, err error) error {
if err != nil {
log.Printf("Error accessing file or directory: %v\n", err)
return nil
}
if !info.IsDir() {
totalFilesScanned++
modification, err := removeStringFromFile(path, stringToRemove)
if err != nil {
log.Printf("Error processing file %s: %v\n", path, err)
return nil
}
if modification != nil {
modifications = append(modifications, modification)
totalStringsRemoved += modification.stringsRemoved
}
if verbose {
fmt.Printf("Processed file: %s\n", path)
}
}
return nil
})
done <- true
if err != nil {
log.Fatalf("Error removing string: %v\n", err)
}
// Print results to console
fmt.Printf("\n%sString Removal Summary:%s\n", Yellow, Reset)
fmt.Printf("Total files scanned: %d\n", totalFilesScanned)
fmt.Printf("Total files modified: %d\n", len(modifications))
fmt.Printf("Total strings removed: %d\n", totalStringsRemoved)
// Write to file if specified
if outputFile != "" {
err = writeModificationsToFile(outputFile, modifications, totalFilesScanned, totalStringsRemoved)
if err != nil {
log.Printf("Error writing to output file: %v\n", err)
} else {
fmt.Printf("\nResults have been saved to: %s\n", outputFile)
}
}
default:
fmt.Println("Invalid choice!")
return
}
}