Skip to content

Commit

Permalink
Add Windows scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MEhrn00 committed Feb 26, 2024
1 parent 68560da commit 1451e14
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/checkformat.sh → .github/scripts/linux/checkformat.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repo_base() {
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..
local _repo_base_dir=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
Expand Down
12 changes: 6 additions & 6 deletions .github/scripts/ci.sh → .github/scripts/linux/ci.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ MYTHIC_CODE="Payload_Type/thanatos/mythic"
AGENT_CODE="Payload_Type/thanatos/agent"

# Populates the 'REPO_PATH' to the base of the repo
populate_thanatos_path() {
repo_base() {
# Get the path to the directory containing this script
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base=${_script_dir}/../..
local _repo_base=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base}/.git" ]; then
Expand All @@ -26,16 +26,16 @@ populate_thanatos_path() {
set -e
populate_thanatos_path
pushd $REPO_PATH &> /dev/null
./.github/scripts/checkformat.sh
./.github/scripts/linux/checkformat.sh
echo ""

./.github/scripts/lint.sh
./.github/scripts/linux/lint.sh
echo ""

./.github/scripts/test.sh
./.github/scripts/linux/test.sh
echo ""

./.github/scripts/sanitizers.sh
./.github/scripts/linux/sanitizers.sh
echo ""

popd &> /dev/null
2 changes: 1 addition & 1 deletion .github/scripts/coverage.sh → .github/scripts/linux/coverage.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repo_base() {
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..
local _repo_base_dir=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/lint.sh → .github/scripts/linux/lint.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repo_base() {
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..
local _repo_base_dir=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
Expand Down Expand Up @@ -50,6 +50,7 @@ lint() {

set -e
repo_base
lint_requirements
pushd $REPO_BASE &> /dev/null
lint
popd &> /dev/null
2 changes: 1 addition & 1 deletion .github/scripts/sanitizers.sh → .github/scripts/linux/sanitizers.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repo_base() {
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..
local _repo_base_dir=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/test.sh → .github/scripts/linux/test.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repo_base() {
local _script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# Traverse up to the base of the git repository
local _repo_base_dir=${_script_dir}/../..
local _repo_base_dir=${_script_dir}/../../..

# Ensure that the repo base contains the '.git' directory
if [ ! -d "${_repo_base_dir}/.git" ]; then
Expand Down
37 changes: 37 additions & 0 deletions .github/scripts/windows/checkformat.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$repo_base=""
$mythic_code="Payload_Type/thanatos/mythic"
$agent_code="Payload_Type/thanatos/agent"


function Get-RepoBase {
$repo_base_dir = Split-Path -Path "$PSScriptRoot/../.." -Resolve
if (-Not (Test-Path -Path "$repo_base_dir/.git")) {
Write-Host "Could not find git repository base"
Exit 1
}

$repo_base = $repo_base_dir
}

function Check-FormatRequirements {
Get-Command gofmt -ErrorAction Stop | Out-Null
Get-Command cargo -ErrorAction Stop | Out-Null
}

function CheckFormat {
Write-Host "[*] Running code format checks"

Write-Host "[*] Agent code"
Push-Location -Path $agent_code
$cmd = "cargo build -p genconfig && cargo fmt --all -- --color always --check"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location
}

Get-RepoBase
Check-FormatRequirements
Push-Location $repo_base
CheckFormat
Pop-Location
23 changes: 23 additions & 0 deletions .github/scripts/windows/ci.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$repo_base=""
$mythic_code="Payload_Type/thanatos/mythic"
$agent_code="Payload_Type/thanatos/agent"


function Get-RepoBase {
$repo_base_dir = Split-Path -Path "$PSScriptRoot/../.." -Resolve
if (-Not (Test-Path -Path "$repo_base_dir/.git")) {
Write-Host "Could not find git repository base"
Exit 1
}

$repo_base = $repo_base_dir
}

Get-RepoBase
Push-Location $repo_base
./.github/scripts/windows/checkformat.ps1
./.github/scripts/windows/lint.ps1
./.github/scripts/windows/test.ps1
./.github/scripts/windows/sanitizers.ps1

Pop-Location
45 changes: 45 additions & 0 deletions .github/scripts/windows/lint.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$repo_base=""
$mythic_code="Payload_Type/thanatos/mythic"
$agent_code="Payload_Type/thanatos/agent"


function Get-RepoBase {
$repo_base_dir = Split-Path -Path "$PSScriptRoot/../.." -Resolve
if (-Not (Test-Path -Path "$repo_base_dir/.git")) {
Write-Host "Could not find git repository base"
Exit 1
}

$repo_base = $repo_base_dir
}

function Check-LintRequirements {
Get-Command golangci-lint -ErrorAction Stop | Out-Null
cargo clippy -V | Out-Null
}

function Lint {
Write-Host "[*] Running lint checks"

Write-Host "[*] Mythic code"
Push-Location -Path $mythic_code
$cmd = "golangci-lint run"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location

Write-Host "[*] Agent code"
Push-Location -Path $agent_code
$cmd = "cargo build -p genconfig && cargo clippy --workspace --color always --all-features --all-targets -- -D warnings"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location
}

Get-RepoBase
Check-LintRequirements
Push-Location $repo_base
Lint
Pop-Location
52 changes: 52 additions & 0 deletions .github/scripts/windows/sanitizers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
$repo_base=""
$mythic_code="Payload_Type/thanatos/mythic"
$agent_code="Payload_Type/thanatos/agent"


function Get-RepoBase {
$repo_base_dir = Split-Path -Path "$PSScriptRoot/../.." -Resolve
if (-Not (Test-Path -Path "$repo_base_dir/.git")) {
Write-Host "Could not find git repository base"
Exit 1
}

$repo_base = $repo_base_dir
}

function Check-SanitizerRequirements {
Get-Command go -ErrorAction Stop | Out-Null
Get-Command cargo -ErrorAction Stop | Out-Null
cargo +nightly -V | Out-Null
Get-Command Get-VSSetupInstance -ErrorAction Stop | Out-Null
Get-VSSetupInstance | Select-VSSetupInstance -Require Microsoft.VisualStudio.Component.VC.ASAN | Out-Null
}

function Sanitizers {
Write-Host "[*] Running sanitizer tests"

$vspath = (Get-VSSetupInstance | Select-VSSetupInstance -Require Microsoft.VisualStudio.Component.VC.ASAN).InstallationPath
Import-Module $vspath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll
Enter-VsDevShell -VsInstallPath $vspath -SkipAutomaticLocation | Out-Null

if (-Not ($env:PATH -contains "$env:VCToolsInstallDir/bin/Hostx64/x64")) {
$env:PATH="$env:PATH;$env:VCToolsInstallDir/bin/Hostx64/x64"
}

Push-Location -Path $agent_code
$env:RUSTFLAGS = "-Zsanitizer=address"
$env:CARGO_INCREMENTAL = "0"
$cmd = "cargo +nightly test --color always -p ffiwrappers --all-features --target x86_64-pc-windows-msvc"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location

Remove-Item env:RUSTFLAGS
Remove-Item env:CARGO_INCREMENTAL
}

Get-RepoBase
Check-SanitizerRequirements
Push-Location $repo_base
Sanitizers
Pop-Location
50 changes: 50 additions & 0 deletions .github/scripts/windows/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$repo_base=""
$mythic_code="Payload_Type/thanatos/mythic"
$agent_code="Payload_Type/thanatos/agent"


function Get-RepoBase {
$repo_base_dir = Split-Path -Path "$PSScriptRoot/../.." -Resolve
if (-Not (Test-Path -Path "$repo_base_dir/.git")) {
Write-Host "Could not find git repository base"
Exit 1
}

$repo_base = $repo_base_dir
}

function Check-TestRequirements {
Get-Command go -ErrorAction Stop | Out-Null
Get-Command cargo -ErrorAction Stop | Out-Null
}

function Test {
Write-Host "[*] Running tests"

Write-Host "[*] Mythic code"
Push-Location -Path $mythic_code
$cmd = "go test ./commands/..."
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd

$cmd = "go test -run `"^TestPayloadMockBuild/`" ./builder"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location

Write-Host "[*] Agent code"
Push-Location -Path $agent_code
$cmd = "cargo build -p genconfig && cargo test --color always --workspace --exclude genconfig --all-features"
Write-Host "current directory: $pwd"
Write-Host "command: $cmd"
Invoke-Expression -Command $cmd
Pop-Location
}

Get-RepoBase
Check-TestRequirements
Push-Location $repo_base
Test
Pop-Location
27 changes: 21 additions & 6 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@
{
"label": "Thanatos: Check formatting",
"type": "shell",
"command": "./.github/scripts/checkformat.sh",
"command": "./.github/scripts/linux/checkformat.sh",
"windows": {
"command": "./.github/scripts/windows/checkformat.ps1"
},
"group": "test",
},
{
"label": "Thanatos: Generate code coverage data",
"type": "shell",
"command": "./.github/scripts/coverage.sh",
"command": "./.github/scripts/linux/coverage.sh",
"group": "none",
"problemMatcher": [],
},
{
"label": "Thanatos: Lint",
"type": "shell",
"command": "./.github/scripts/lint.sh",
"command": "./.github/scripts/linux/lint.sh",
"windows": {
"command": "./.github/scripts/windows/lint.ps1"
},
"group": "test",
},
{
"label": "Thanatos: Tests",
"type": "shell",
"command": "./.github/scripts/test.sh",
"command": "./.github/scripts/linux/test.sh",
"windows": {
"command": "./.github/scripts/windows/test.ps1"
},
"group": {
"isDefault": true,
"kind": "test"
Expand All @@ -32,7 +41,10 @@
{
"label": "Thanatos: Sanitizer tests",
"type": "shell",
"command": "./.github/scripts/sanitizers.sh",
"command": "./.github/scripts/linux/sanitizers.sh",
"windows": {
"command": "./.github/scripts/windows/sanitizers.ps1"
},
"group": {
"isDefault": false,
"kind": "test"
Expand All @@ -41,7 +53,10 @@
{
"label": "Thanatos: CI scripts",
"type": "shell",
"command": "./.github/scripts/ci.sh",
"command": "./.github/scripts/linux/ci.sh",
"windows": {
"command": "./.github/scripts/windows/ci.ps1"
},
"group": {
"isDefault": false,
"kind": "test"
Expand Down

0 comments on commit 1451e14

Please sign in to comment.