diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5fbde78 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,206 @@ +name: Build and Release + +on: + push: + branches: [ main, master ] + tags: [ 'v*' ] + pull_request: + branches: [ main, master ] + +env: + GO_VERSION: '1.23' + APP_NAME: 'golin' + +jobs: + # 代码质量检查 + test: + name: Test and Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: | + # 清理可能损坏的缓存 + go clean -modcache || true + go mod download + + - name: Run tests + run: | + # 运行测试,如果没有测试文件则跳过 + if find . -name "*_test.go" | grep -q .; then + go test -v ./... + else + echo "No test files found, skipping tests" + fi + + - name: Run go vet + run: go vet ./... + + - name: Run go fmt check + run: | + if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then + echo "Code is not formatted properly:" + gofmt -s -l . + exit 1 + fi + + - name: Build check + run: | + # 验证代码可以编译 + go build -v . + + # 构建多平台版本 + build: + name: Build + needs: test + runs-on: ubuntu-latest + strategy: + matrix: + include: + # Windows + - goos: windows + goarch: amd64 + suffix: .exe + - goos: windows + goarch: arm64 + suffix: .exe + # Linux + - goos: linux + goarch: amd64 + suffix: "" + - goos: linux + goarch: arm64 + suffix: "" + # macOS + - goos: darwin + goarch: amd64 + suffix: "" + - goos: darwin + goarch: arm64 + suffix: "" + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Download dependencies + run: | + # 清理可能损坏的缓存 + go clean -modcache || true + go mod download + + - name: Get version + id: version + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + else + VERSION=${GITHUB_SHA::8} + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Building version: $VERSION" + + - name: Build binary + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + run: | + BINARY_NAME="${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }}" + echo "Building $BINARY_NAME" + + # 设置构建标志 + LDFLAGS="-s -w -X main.version=${{ steps.version.outputs.version }}" + + go build -ldflags="$LDFLAGS" -o "$BINARY_NAME" . + + # 验证二进制文件 + if [ "${{ matrix.goos }}" = "linux" ] && [ "${{ matrix.goarch }}" = "amd64" ]; then + file "$BINARY_NAME" + ls -la "$BINARY_NAME" + fi + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} + path: ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.suffix }} + retention-days: 30 + + # 发布版本(标签时正式发布,主分支时预发布) + release: + name: Create Release + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: ./artifacts + + - name: Get version + id: version + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + echo "is_prerelease=false" >> $GITHUB_OUTPUT + else + VERSION="dev-${GITHUB_SHA::8}" + echo "is_prerelease=true" >> $GITHUB_OUTPUT + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Building version: $VERSION" + + - name: Prepare release files + run: | + mkdir -p release + cd artifacts + for dir in */; do + if [ -d "$dir" ]; then + cp "$dir"/* ../release/ 2>/dev/null || true + fi + done + cd ../release + ls -la + + - name: Generate checksums + run: | + cd release + for file in *; do + if [ -f "$file" ] && [ "$file" != "checksums.txt" ]; then + sha256sum "$file" >> checksums.txt + fi + done + echo "Generated checksums:" + cat checksums.txt + + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.version.outputs.version }} + name: ${{ steps.version.outputs.is_prerelease == 'true' && format('Pre-release {0}', steps.version.outputs.version) || format('Release {0}', steps.version.outputs.version) }} + draft: false + prerelease: ${{ steps.version.outputs.is_prerelease == 'true' }} + generate_release_notes: true + body: ${{ steps.version.outputs.is_prerelease == 'true' && '⚠️ 这是一个开发版本,可能不稳定。仅用于测试目的。' || '' }} + files: | + release/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/cmd/keylogger_darwin.go b/cmd/keylogger_darwin.go new file mode 100644 index 0000000..c04312b --- /dev/null +++ b/cmd/keylogger_darwin.go @@ -0,0 +1,22 @@ +//go:build darwin + +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" +) + +// keyloggerCmd represents the keylogger command for macOS +var keyloggerCmd = &cobra.Command{ + Use: "keylogger", + Short: "键盘记录器 (macOS 不支持)", + Long: `键盘记录器功能在 macOS 上不可用`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("键盘记录器功能在 macOS 上不可用") + }, +} + +func init() { + rootCmd.AddCommand(keyloggerCmd) +} diff --git a/cmd/user_users.go b/cmd/user_users.go index 6d7f79a..6f04fd1 100644 --- a/cmd/user_users.go +++ b/cmd/user_users.go @@ -1,4 +1,4 @@ -//go:build windows +//go:build windows && amd64 package cmd diff --git a/cmd/user_users_arm64.go b/cmd/user_users_arm64.go new file mode 100644 index 0000000..a4a6172 --- /dev/null +++ b/cmd/user_users_arm64.go @@ -0,0 +1,51 @@ +//go:build windows && arm64 + +package cmd + +import ( + "fmt" + "github.com/olekukonko/tablewriter" + "github.com/spf13/cobra" + "os" + "os/exec" + "strings" +) + +var userCmd = &cobra.Command{ + Use: "users", + Short: "获取用户信息 (Windows ARM64 简化版)", + Run: checkusers, +} + +func init() { + rootCmd.AddCommand(userCmd) +} + +func checkusers(cmd *cobra.Command, args []string) { + // 使用 PowerShell 命令获取用户信息,因为 go-win64api 不支持 ARM64 + psCmd := `Get-LocalUser | Select-Object Name, FullName, Enabled, LastLogon, UserMayChangePassword, PasswordRequired | Format-Table -AutoSize` + + execCmd := exec.Command("powershell", "-Command", psCmd) + output, err := execCmd.CombinedOutput() + if err != nil { + fmt.Printf("\033[31m错误:获取用户列表失败 (%v)\033[0m\n", err) + return + } + + fmt.Println("Windows ARM64 用户信息 (通过 PowerShell 获取):") + fmt.Println(strings.TrimSpace(string(output))) + + // 简化的表格显示 + table := tablewriter.NewWriter(os.Stdout) + table.SetAutoFormatHeaders(false) + table.SetHeader([]string{ + "说明", + "状态", + }) + + table.Append([]string{"用户信息获取方式", "PowerShell (ARM64 兼容)"}) + table.Append([]string{"详细信息", "请查看上方 PowerShell 输出"}) + table.Append([]string{"注意", "ARM64 版本功能有限"}) + + table.Render() +} diff --git a/cmd/wifi_darwin.go b/cmd/wifi_darwin.go new file mode 100644 index 0000000..9c2ea7f --- /dev/null +++ b/cmd/wifi_darwin.go @@ -0,0 +1,22 @@ +//go:build darwin + +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" +) + +// wifiCmd represents the wifi command for macOS +var wifiCmd = &cobra.Command{ + Use: "wifi", + Short: "WiFi 密码获取 (macOS 不支持)", + Long: `WiFi 密码获取功能在 macOS 上不可用`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("WiFi 密码获取功能在 macOS 上不可用") + }, +} + +func init() { + rootCmd.AddCommand(wifiCmd) +} diff --git a/cmd/windows_darwin.go b/cmd/windows_darwin.go new file mode 100644 index 0000000..bbad7cc --- /dev/null +++ b/cmd/windows_darwin.go @@ -0,0 +1,22 @@ +//go:build darwin + +package cmd + +import ( + "fmt" + "github.com/spf13/cobra" +) + +// windowsCmd represents the windows command for macOS +var windowsCmd = &cobra.Command{ + Use: "windows", + Short: "Windows 安全策略检查 (macOS 不支持)", + Long: `Windows 安全策略检查功能在 macOS 上不可用`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("Windows 安全策略检查功能在 macOS 上不可用") + }, +} + +func init() { + rootCmd.AddCommand(windowsCmd) +} diff --git a/run/navicat/navicat_darwin.go b/run/navicat/navicat_darwin.go new file mode 100644 index 0000000..cd9a454 --- /dev/null +++ b/run/navicat/navicat_darwin.go @@ -0,0 +1,7 @@ +//go:build darwin + +package navicat + +import "github.com/spf13/cobra" + +func Run(cmd *cobra.Command, args []string) { return } diff --git a/run/windows/netstat.go b/run/windows/netstat.go index 51f1d1c..ef1a9ba 100644 --- a/run/windows/netstat.go +++ b/run/windows/netstat.go @@ -1,3 +1,5 @@ +//go:build windows + package windows import ( diff --git a/run/windows/windows_darwin.go b/run/windows/windows_darwin.go new file mode 100644 index 0000000..da89fb3 --- /dev/null +++ b/run/windows/windows_darwin.go @@ -0,0 +1,9 @@ +//go:build darwin + +package windows + +// Windows 函数的 macOS 占位符实现 +func Windows() { + // macOS 上不执行任何操作 + return +} diff --git a/run/xshell/xshell_darwin.go b/run/xshell/xshell_darwin.go new file mode 100644 index 0000000..96c36ea --- /dev/null +++ b/run/xshell/xshell_darwin.go @@ -0,0 +1,7 @@ +//go:build darwin + +package xshell + +import "github.com/spf13/cobra" + +func Run(cmd *cobra.Command, args []string) { return }