-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ac5c276
Showing
8 changed files
with
1,352 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: 🎉 Release Binary | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install upx | ||
run: sudo apt install upx -y | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
|
||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v4 | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- main: cmd | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- windows | ||
- linux | ||
goarch: | ||
- amd64 | ||
|
||
ignore: | ||
- goos: windows | ||
goarch: 'arm64' | ||
|
||
binary: 'detecode' | ||
|
||
flags: | ||
- '-trimpath' | ||
ldflags: | ||
- '-s -w' | ||
- '-X main.version={{ .Version }}' | ||
- '-X main.commit={{ .ShortCommit }}' | ||
hooks: | ||
post: "upx --lzma {{ .Path }}" | ||
|
||
changelog: | ||
filters: | ||
exclude: | ||
- '^doc:' | ||
- typo | ||
- (?i)foo | ||
- '^ref' | ||
- '^style' | ||
groups: | ||
- title: Features | ||
regexp: "^.*feat[(\\w)]*:+.*$" | ||
order: 0 | ||
- title: 'Bug fixes' | ||
regexp: "^.*fix[(\\w)]*:+.*$" | ||
order: 1 | ||
- title: Others | ||
order: 999 | ||
|
||
archives: | ||
- format: binary | ||
|
||
checksum: | ||
algorithm: md5 |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fatih/color" | ||
"github.com/wux1an/detecode" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
var Version = "v0.0.0" | ||
var ShortCommit = "123456" | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Printf(color.CyanString("usage:")+" %s <path-to-scan>\n", filepath.Base(os.Args[0])) | ||
fmt.Printf(color.CyanString("version:")+" %s(%s)\n", Version, ShortCommit) | ||
fmt.Printf(color.New(color.Italic, color.Underline, color.FgCyan, color.Bold).Sprintf("see: github.com/wux1an/detecode\n")) | ||
os.Exit(0) | ||
} | ||
|
||
detecode.StartScan(os.Args[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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package detecode | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fatih/color" | ||
"github.com/schollz/progressbar/v3" | ||
"math" | ||
"path/filepath" | ||
"strings" | ||
"sync" | ||
"time" | ||
) | ||
|
||
func StartScan(root string) { | ||
var detector = NewDetector(root) | ||
count, _ := detector.FileCount() | ||
fmt.Printf("[+] total %d files\n", count) | ||
|
||
var wg sync.WaitGroup | ||
var timer = time.Now() | ||
|
||
var bar = progressbar.NewOptions(count, | ||
progressbar.OptionEnableColorCodes(true), | ||
progressbar.OptionSetWidth(15), | ||
progressbar.OptionSetDescription("[cyan] Detecting... [reset]"), | ||
progressbar.OptionShowCount(), | ||
progressbar.OptionSetTheme(progressbar.Theme{ | ||
Saucer: "[green]=[reset]", | ||
SaucerHead: "[green]>[reset]", | ||
SaucerPadding: " ", | ||
BarStart: "[", | ||
BarEnd: "]", | ||
})) | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
detector.Start() | ||
}() | ||
|
||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
|
||
pwd, _ := filepath.Abs(".") | ||
|
||
c := color.New() | ||
for record := range detector.Results() { | ||
bar.Add(1) | ||
bar.Describe("[cyan] Detecting " + less(detector.CurrentFile()) + " [reset]") | ||
for _, s := range record.Findings { | ||
bar.Clear() | ||
rel, err := filepath.Rel(pwd, record.FilePath) | ||
if err != nil { | ||
rel = record.FilePath | ||
} | ||
|
||
var width = 10 | ||
var start = strings.Index(s.Line, s.Secret) | ||
var prefixIndex = int(math.Max(float64(start-1-width), 0)) | ||
var suffixIndex = int(math.Min(float64(start+len(s.Secret)+width), float64(len(s.Line)))) | ||
c.Println(color.CyanString("[+] %s:%-3d", less(rel), s.StartLine) + | ||
color.YellowString(" %s", s.Description) + " " + | ||
color.GreenString(s.Line[prefixIndex:start]) + color.HiGreenString(s.Secret) + color.GreenString(s.Line[start+len(s.Secret):suffixIndex])) | ||
} | ||
} | ||
}() | ||
|
||
wg.Add(1) | ||
go func() { | ||
wg.Done() | ||
|
||
for err := range detector.ChError() { | ||
fmt.Println("[x]", err) | ||
} | ||
}() | ||
|
||
wg.Wait() | ||
|
||
bar.Clear() | ||
|
||
fmt.Printf("\n[+] finished, cost: %v\n", time.Duration(int(time.Now().Sub(timer).Seconds()))*time.Second) | ||
} | ||
|
||
func less(str string) string { | ||
maxPathWidth := 50 | ||
|
||
if len(str) <= maxPathWidth { | ||
return str | ||
} | ||
|
||
return str[:maxPathWidth/2-2] + "...." + str[len(str)-(maxPathWidth/2-2):] | ||
} |
Oops, something went wrong.