From 3d8e8e25431d2feadf06e2061c316c1edc9c59ed Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Mon, 29 Jul 2024 20:18:05 +0200 Subject: [PATCH] Detect FreeBSD linuxemu with syscall.Uname --- Makefile | 4 +-- system.go | 2 ++ system_unix.go => system_darwin.go | 7 +++-- system_linux.go | 49 ++++++++++++++++++++++++++++++ system_windows.go | 3 ++ 5 files changed, 60 insertions(+), 5 deletions(-) rename system_unix.go => system_darwin.go (64%) create mode 100644 system_linux.go diff --git a/Makefile b/Makefile index 10433bd..d477a42 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -SOURCES=Makefile main.go main_release.go main_debug.go config.go config_release.go config_template.go system.go system_windows.go system_unix.go +SOURCES=Makefile main.go main_release.go main_debug.go config.go config_release.go config_template.go system.go system_windows.go system_linux.go system_darwin.go GARBLE_BIN = $(shell go env GOPATH)/bin/garble GARBLE_CMD = $(GARBLE_BIN) -literals -tiny @@ -14,7 +14,7 @@ test: socks5-ssh-proxy test-release: socks5-ssh-proxy.release ./socks5-ssh-proxy.release socks5-ssh-proxy: $(SOURCES) - go build -o $@ + GOOS=linux GOARCH=amd64 go build -tags release,linux -o $@ socks5-ssh-proxy.release: resources $(SOURCES) $(GARBLE_BIN) GOOS=darwin GOARCH=amd64 $(GARBLE_CMD) build -tags release -o $@ upx $@ diff --git a/system.go b/system.go index cba3b79..9202676 100644 --- a/system.go +++ b/system.go @@ -156,6 +156,8 @@ func systemIgnoreAllSignals() { } func systemOSDetect() { + systemGetUname() + wineVersion := systemGetWINEVersion() log.Println("WINE version", wineVersion) log.Println("IsUserRoot", systemIsUserRoot()) diff --git a/system_unix.go b/system_darwin.go similarity index 64% rename from system_unix.go rename to system_darwin.go index dbdd769..2374007 100644 --- a/system_unix.go +++ b/system_darwin.go @@ -1,13 +1,14 @@ -//go:build !windows -// +build !windows +//go:build darwin +// +build darwin -// package main func systemGetWINEVersion() string { return "" } +func systemGetUname() { +} func systemIsUserRoot() bool { return false diff --git a/system_linux.go b/system_linux.go new file mode 100644 index 0000000..5e4deb0 --- /dev/null +++ b/system_linux.go @@ -0,0 +1,49 @@ +//go:build linux +// +build linux + +package main + +import ( + "log" + "syscall" + "strings" +) + +func systemGetWINEVersion() string { + return "" +} + +func systemGetUname() { + var uts syscall.Utsname + + err := syscall.Uname(&uts) + if err != nil { + log.Println("Error getting system information:", err) + return + } + + // Convert the byte arrays to strings + sysname := int8SliceToString(uts.Sysname[:]) + release := int8SliceToString(uts.Release[:]) + version := int8SliceToString(uts.Version[:]) + + // Check for FreeBSD Linux emulation specific indicators + log.Println("syscall.Uname:", "(sysname)", sysname, "(release)", release, "(version)", version) + if strings.Contains(sysname, "Linux") && strings.Contains(version, "FreeBSD") { + log.Println("Running under FreeBSD linuxemu") + } +} + +// int8SliceToString converts a slice of int8 to a string. +func int8SliceToString(int8Slice []int8) string { + // Create a byte slice with the same length as the int8 slice + byteSlice := make([]byte, len(int8Slice)) + for i, v := range int8Slice { + byteSlice[i] = byte(v) + } + return string(byteSlice) +} + +func systemIsUserRoot() bool { + return false +} diff --git a/system_windows.go b/system_windows.go index e7cce7c..f730b67 100644 --- a/system_windows.go +++ b/system_windows.go @@ -26,6 +26,9 @@ func systemGetWINEVersion() string { return wineVersion } +func systemGetUname() { +} + func systemIsUserRoot() bool { root := true