Skip to content

Commit

Permalink
added go binaries versions >= 1.11.9 (#9)
Browse files Browse the repository at this point in the history
* Update Readme.md

* Added go binaries generation script

---------

Co-authored-by: Moritz <[email protected]>
  • Loading branch information
Arker123 and mr-tz authored Jun 16, 2023
1 parent ae34ac4 commit da2fe57
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/go-binaries-all-versions/README.md

This file was deleted.

21 changes: 21 additions & 0 deletions src/go-binaries-all-versions/Readme.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions src/go-binaries-all-versions/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module go-test

go 1.19

91 changes: 91 additions & 0 deletions src/go-binaries-all-versions/go_binary_generator.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 20 additions & 0 deletions src/go-binaries-all-versions/main32.go
Original file line number Diff line number Diff line change
@@ -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");
}
}
20 changes: 20 additions & 0 deletions src/go-binaries-all-versions/main64.go
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit da2fe57

Please sign in to comment.