From da2fe57c2644de68dc3db66414835cc4b81fe8b1 Mon Sep 17 00:00:00 2001 From: Arker123 <94680887+Arker123@users.noreply.github.com> Date: Fri, 16 Jun 2023 12:38:59 +0530 Subject: [PATCH] added go binaries versions >= 1.11.9 (#9) * Update Readme.md * Added go binaries generation script --------- Co-authored-by: Moritz --- src/go-binaries-all-versions/README.md | 1 - src/go-binaries-all-versions/Readme.md | 21 +++++ src/go-binaries-all-versions/go.mod | 4 + .../go_binary_generator.py | 91 +++++++++++++++++++ src/go-binaries-all-versions/main32.go | 20 ++++ src/go-binaries-all-versions/main64.go | 20 ++++ 6 files changed, 156 insertions(+), 1 deletion(-) delete mode 100644 src/go-binaries-all-versions/README.md create mode 100644 src/go-binaries-all-versions/Readme.md create mode 100644 src/go-binaries-all-versions/go.mod create mode 100644 src/go-binaries-all-versions/go_binary_generator.py create mode 100644 src/go-binaries-all-versions/main32.go create mode 100644 src/go-binaries-all-versions/main64.go diff --git a/src/go-binaries-all-versions/README.md b/src/go-binaries-all-versions/README.md deleted file mode 100644 index 7ebc942..0000000 --- a/src/go-binaries-all-versions/README.md +++ /dev/null @@ -1 +0,0 @@ -The ZIP archives contain the compiled Go binaries (32- and 64-bit) for all minor versions 1.11 - 1.20, derived from the "go-hello" source code found in flare-floss-testfiles/src/go-hello. diff --git a/src/go-binaries-all-versions/Readme.md b/src/go-binaries-all-versions/Readme.md new file mode 100644 index 0000000..43b3239 --- /dev/null +++ b/src/go-binaries-all-versions/Readme.md @@ -0,0 +1,21 @@ +# Test Files for Go Binary Versions + +This repository contains two ZIP archives, each containing compiled Go binaries for minor versions 1.11 to 1.20, specifically for the 386 and amd64 architectures, along with their corresponding source code. + +## Contents + +Each ZIP archive corresponds to a specific architecture and contains the following files: + +- `bin/versions_32.zip`: Zip file containing the compiled Go binaries for the 386 architecture. +- `bin/versions_64.zip`: Zip file containing the compiled Go binaries for the amd64 architecture. +- `main32.go`: Source code for the 386 architecture binaries. +- `main64.go`: Source code for the amd64 architecture binaries. + +## Generating Go Binaries using Docker + +To automate the process of generating Go binaries for all versions from 1.11 to 1.20 using Docker, you can use the provided Python script. Follow the steps below: + +- Make sure Docker is installed and properly configured on your system. +- Run the script using the following command: `python3 go_binary_generator.py`. + +The script will handle the setup, compilation, and generation of Go binaries for the specified minor versions. The resulting binaries will be saved in the `bin/` directory. \ No newline at end of file diff --git a/src/go-binaries-all-versions/go.mod b/src/go-binaries-all-versions/go.mod new file mode 100644 index 0000000..c2fddb4 --- /dev/null +++ b/src/go-binaries-all-versions/go.mod @@ -0,0 +1,4 @@ +module go-test + +go 1.19 + diff --git a/src/go-binaries-all-versions/go_binary_generator.py b/src/go-binaries-all-versions/go_binary_generator.py new file mode 100644 index 0000000..cced581 --- /dev/null +++ b/src/go-binaries-all-versions/go_binary_generator.py @@ -0,0 +1,91 @@ +# Copyright (C) 2023 Mandiant, Inc. All Rights Reserved. +""" +This Python script automates the process of generating Go binaries for versions 1.11 to 1.20 using Docker. By leveraging Docker containers, it ensures a consistent and reproducible environment for compiling the Go source code across different platforms. + +Please note that Docker must be installed and properly configured on your system for the script to execute successfully. + +Usage: + python go_binary_generator.py + +The resulting binaries will be saved in the `bin/` directory. +""" + +import subprocess + +go_versions = """ +1.11 +1.12 +1.13 +1.14 +1.15 +1.16 +1.17 +1.18 +1.19 +1.20 +""" + +f = open("docker-compose.yml", "w") + +f.write( + """services: + app: + build: .""" +) + +f.close() + +subprocess.call(["docker", "compose", "up"]) +print("Compose is UP") + +architecture = {"386": 32, "amd64": 64} + +for arch in architecture.keys(): + for version in go_versions.split(): + print("version: ", version) + + f = open("Dockerfile", "w") + + f.write( + """# syntax=docker/dockerfile:1 +FROM golang:{} + +WORKDIR /app +COPY go.mod ./ +RUN go mod download +COPY *.go ./ +RUN GOOS=windows GOARCH={} go install main{}.go""".format( + version, arch, architecture[arch] + ) + ) + f.close() + + f = open("go.mod", "w") + + f.write( + """module go-test + +go {} + """.format( + version + ) + ) + + f.close() + + subprocess.call(["docker", "build", "--tag", "go-test", "."]) + subprocess.call( + [ + "docker", + "run", + "-v", + ".:/var/opt", + "go-test", + "mv", + "/go/bin/main{}.exe".format(architecture[arch]), + "/var/opt/bin/main_{}_{}.exe".format(architecture[arch], version), + ] + ) + +subprocess.call(["docker", "compose", "down"]) +print("Compose is DOWN") diff --git a/src/go-binaries-all-versions/main32.go b/src/go-binaries-all-versions/main32.go new file mode 100644 index 0000000..78b072b --- /dev/null +++ b/src/go-binaries-all-versions/main32.go @@ -0,0 +1,20 @@ +package main; + +import ( + "fmt"; + "os"; + "bufio"; +) + +func main() { + fmt.Print("Enter Password: "); + user_input,_,err := bufio.NewReader(os.Stdin).ReadLine(); + if err != nil { + fmt.Println("Something is wrong with your computer, ",err); + } + if string(user_input) == "Bugfest" { + fmt.Println("You Cracked it, A Hero is born"); + } else { + fmt.Println("Don't Worry, Relax, Chill and Try harder"); + } +} diff --git a/src/go-binaries-all-versions/main64.go b/src/go-binaries-all-versions/main64.go new file mode 100644 index 0000000..644360b --- /dev/null +++ b/src/go-binaries-all-versions/main64.go @@ -0,0 +1,20 @@ +package main; + +import ( + "fmt"; + "os"; + "bufio"; +) + +func main() { + fmt.Print("Enter Password: "); + user_input,_,err := bufio.NewReader(os.Stdin).ReadLine(); + if err != nil { + fmt.Println("Something is wrong with your computer, ",err); + } + if string(user_input) == "PasswordisPrank" { + fmt.Println("You Cracked it, A Hero is born"); + } else { + fmt.Println("Don't Worry, Relax, Chill and Try harder"); + } +}