Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Dec 11, 2023
1 parent 2a99bac commit 1f79b5a
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 158 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: CI

on:
push:
paths:
- 'src/**'
- 'opt/**'
pull_request:
branches: [ "master" ]
workflow_dispatch:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/runnerCI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: runner CI build

on:
push:
paths:
- 'runner/**'
pull_request:
branches: [ "master" ]
workflow_dispatch:

jobs:
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- name: Run a one-line script
shell : pwsh
run: |
./runner/build.ps1 -OutputFile esh.exe
./runner/build.ps1 -OutputFile esh-SigThief.exe -SigThief
- uses: actions/upload-artifact@v3
with:
path: |
esh.exe
esh-SigThief.exe
2 changes: 1 addition & 1 deletion opt/install
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

pwsh -nologo -File "$SCRIPT_DIR/install.ps1" -FromScript "$@"
pwsh -nologo -File "$SCRIPT_DIR/install.ps1" "$@"
exit $?
2 changes: 1 addition & 1 deletion opt/install.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@pwsh -nologo -File "%~dp0\install.ps1" -FromScript %*
@pwsh -nologo -File "%~dp0\install.ps1" %*
@exit /b %ERRORLEVEL%
31 changes: 20 additions & 11 deletions opt/install.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env pwsh
[CmdletBinding()]param(
[switch]$Force=$false,
[ValidateSet('yes', 'no', 'ask', 'auto')][string]$StartEsh='auto',
[parameter(DontShow)][switch]$FromScript=$false
[switch]$Fix=$false,
[ValidateSet('yes', 'no', 'ask', 'auto')][string]$StartEsh='auto'
)

function illusionlimb($path) {
Expand All @@ -15,15 +15,24 @@ illusionlimb opt_init.ps1

if (-not $eshDir) {
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
if (Get-Command git -ErrorAction Ignore) {
try { git clone https://github.com/steve02081504/esh $env:LOCALAPPDATA/esh --depth 1 }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
}
else{
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止脚本")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
$eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Expand All @@ -35,4 +44,4 @@ else {
if ($EshellUI) { Write-Host "(并且你正在使用它 :))" }
}

. $eshDir/src/opt/install.ps1 -Force:$Force -StartEsh:$StartEsh -FromScript:$FromScript
. $eshDir/src/opt/install.ps1 -Force:$Force -StartEsh:$StartEsh -Fix:$Fix
25 changes: 11 additions & 14 deletions opt/run
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,17 @@ if [[ -d "/c/Windows" ]]; then
SCRIPT_DIR=$(echo "$SCRIPT_DIR" | sed -e 's/\/c/C:/g' -e 's/\//\\/g' -e 's/^\\//g')
fi

if [[ -z "$command" ]]; then
if [[ -z "$File" ]]; then
pwsh $parsed_args -nologo -NoExit -File "$SCRIPT_DIR/run.ps1"
else
File=$(echo "$File" | sed -e 's/"/`"/g')
pwsh $parsed_args -nologo -NoExit -Command ". $SCRIPT_DIR/run.ps1 ; . $File"
fi
else
pwshCommand=""
NoExit="-NoExit"
if [[ -n "$File" ]]; then
File=$(echo "$File" | sed -e 's/"/`"/g')
pwshCommand="$pwshCommand ; . $File"
NoExit=""
fi
if [[ -n "$command" ]]; then
command=$(echo "$command" | sed -e 's/"/`"/g')
if [[ -z "$File" ]]; then
pwsh $parsed_args -nologo -Command ". $SCRIPT_DIR/run.ps1 ; Invoke-Expression $command"
else
File=$(echo "$File" | sed -e 's/"/`"/g')
pwsh $parsed_args -nologo -Command ". $SCRIPT_DIR/run.ps1 ; . $File ; Invoke-Expression $command"
fi
pwshCommand="$pwshCommand ; Invoke-Expression \"$command\""
NoExit=""
fi
pwsh $parsed_args -nologo $NoExit -command ". $SCRIPT_DIR/run.ps1$pwshCommand"
exit $?
25 changes: 10 additions & 15 deletions opt/run.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,21 @@ for %%i in (%*) do (
)
)

if defined command (
set "command=!command:"=""!"
)
set "Noexit=-NoExit"
set "pwshCommand="

if defined File (
set "File=!File:"=""!"
set "pwshCommand=!pwshCommand! ; . !File!"
set "Noexit="
)

if defined command (
if defined File (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; . !File!; Invoke-Expression !command!"
) else (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; Invoke-Expression !command!"
)
) else (
if defined File (
pwsh !remainingArgs! -nologo -Command ". %~dp0\run.ps1; . !File!"
) else (
pwsh !remainingArgs! -nologo -NoExit -File "%~dp0\run.ps1"
)
set "command=!command:"=""!"
set "pwshCommand=!pwshCommand! ; Invoke-Expression !command!"
set "Noexit="
)

pwsh.exe %remainingArgs% %Noexit% -nologo -Command ". %~dp0\run.ps1; !pwshCommand!"

@echo on
@exit /b %ERRORLEVEL%
1 change: 0 additions & 1 deletion runner/.gitignore

This file was deleted.

101 changes: 97 additions & 4 deletions runner/build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,99 @@
[CmdletBinding()]param ($OutputFile = "$PSScriptRoot/esh.exe")
[CmdletBinding()]
param (
$OutputFile = "$PWD/esh.exe",
[Parameter(ParameterSetName = 'SigThief')][switch]$SigThief = $false,
[switch]$DetailedLog = $false
)
DynamicParam {
if ($SigThief) {
$SigThiefParam = New-Object System.Management.Automation.RuntimeDefinedParameter('SigThiefFile', [string], ([System.Management.Automation.ParameterAttribute]@{HelpMessage = 'The file to steal signature from.' }))
$RuntimeParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$RuntimeParamDictionary.Add('SigThiefFile', $SigThiefParam)
return $RuntimeParamDictionary
}
}

process {
function GetToolFromGit($ToolName, $ToolAuthor="steve02081504"){
Write-Host "Downloading $ToolAuthor/$ToolName..."
try{
if (Get-Command git -ErrorAction Ignore) {
git clone https://github.com/$ToolAuthor/$ToolName "$PSScriptRoot/tools/$ToolName"
}
else{
Invoke-WebRequest -Uri https://github.com/$ToolAuthor/$ToolName/archive/refs/heads/master.zip -OutFile "$PSScriptRoot/tools/$ToolName.zip"
Expand-Archive -Path "$PSScriptRoot/tools/$ToolName.zip" -DestinationPath "$PSScriptRoot/tools"
Move-Item "$PSScriptRoot/tools/$ToolName-master" "$PSScriptRoot/tools/$ToolName"
Remove-Item "$PSScriptRoot/tools/$ToolName.zip"
}
} catch {
Write-Warning "Download failed."
Exit
}
Write-Host "Download complete."
}
if (-not (Test-Path "$PSScriptRoot/tools/ps2exe/ps2exe.ps1")) {
if(Get-Command ps2exe -ErrorAction Ignore){
Write-Host "Existing ps2exe doesn't meet the functionality requirements needed for a build, downloading target fork..."
}
GetToolFromGit ps2exe
}
if (-not (Test-Path "$PSScriptRoot/tools/psminnifyer/psminnifyer.ps1")) {
GetToolFromGit psminnifyer
}
& $PSScriptRoot/tools/ps2exe/ps2exe.ps1 $PSScriptRoot/main.ps1 "$PSScriptRoot/build/esh.exe" -NoConsole `
-Minifyer { $_ | &$PSScriptRoot/tools/psminnifyer/psminnifyer.ps1 } `
-TempDir "$PSScriptRoot/build" -iconFile $PSScriptRoot/../img/esh.ico `
-title 'E-Shell' -description 'E-Shell' -version '1960.7.17.13' `
-company 'E-tek' -product 'E-Sh' -copyright '(c) E-tek Corporation. All rights reserved.' | Out-Default

$ConfuserFile = if (Test-Path "$PSScriptRoot/tools/ConfuserEx/Confuser.CLI.exe") { "$PSScriptRoot/tools/ConfuserEx/Confuser.CLI.exe" }
else { (Get-Command Confuser.CLI -ErrorAction Ignore).Source }
if(-not $ConfuserFile){
Write-Host "Confuser.CLI not found. Downloading..."
try{
Invoke-WebRequest https://github.com/mkaring/ConfuserEx/releases/latest/download/ConfuserEx-CLI.zip -OutFile $PSScriptRoot/tools/ConfuserEx.zip
New-Item -ItemType Directory -Force -Path $PSScriptRoot/tools/ConfuserEx | Out-Null
Expand-Archive -Path $PSScriptRoot/tools/ConfuserEx.zip -DestinationPath $PSScriptRoot/tools/ConfuserEx
} catch {
Write-Warning "Download failed.. Skipping obfuscation.
Download it from https://github.com/mkaring/ConfuserEx
and put it in the environment path or in $PSScriptRoot/tools/ConfuserEx"
}
if (Test-Path "$PSScriptRoot/tools/ConfuserEx/Confuser.CLI.exe") {
$ConfuserFile = "$PSScriptRoot/tools/ConfuserEx/Confuser.CLI.exe"
Write-Host "Download complete."
}
}
if($ConfuserFile){
$OutputLength = (Get-Item "$PSScriptRoot/build/esh.exe").Length
& $ConfuserFile -n -o="$PSScriptRoot/build" "$PSScriptRoot/build/esh.exe" | Out-Null #太长了
$ObfusLength = (Get-Item "$PSScriptRoot/build/esh.exe").Length
if($ObfusLength -ne $OutputLength){
Write-Host "Obfuscation complete -> $ObfusLength bytes"
}
elseif($LASTEXITCODE -eq 1){
Write-Warning "Obfuscation failed."
}
}

if (-not (Get-Module -ListAvailable ps2exe)) {
Install-Module ps2exe
if ($SigThief) {
if (-not (Test-Path "$PSScriptRoot/tools/SigThief/sigthief.py")) {
GetToolFromGit SigThief
}
if (-not $SigThiefFile) {
$SigThiefFile = "$env:windir\explorer.exe"
}
if (Get-Command python -ErrorAction Ignore) {
python "$PSScriptRoot/tools/SigThief/sigthief.py" -i $SigThiefFile -t "$PSScriptRoot/build/esh.exe" -o $OutputFile
}
else {
Write-Warning "Python not found. Skipping sigthief."
Copy-Item "$PSScriptRoot/build/esh.exe" $OutputFile
}
}
else{
Copy-Item "$PSScriptRoot/build/esh.exe" $OutputFile
Write-Host "Skipping sigature theft."
}
}
Invoke-ps2exe $PSScriptRoot/main.ps1 $OutputFile -NoConsole -iconFile $PSScriptRoot/../img/esh.ico -title 'E-Shell' -description 'E-Shell' -version '1960.7.17.13' -company 'E-tek' -product 'E-Sh' -copyright '(c) E-tek Corporation. All rights reserved.'
3 changes: 3 additions & 0 deletions runner/build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/esh.exe
/esh.pdb
/main.ps1
2 changes: 2 additions & 0 deletions runner/build/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,261
27 changes: 18 additions & 9 deletions runner/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ if (-not $eshDir) {

if (-not $eshDir) {
Remove-Item $env:LOCALAPPDATA/esh -Confirm -ErrorAction Ignore -Recurse
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
if (Get-Command git -ErrorAction Ignore) {
try { git clone https://github.com/steve02081504/esh $env:LOCALAPPDATA/esh --depth 1 }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
}
}
else{
Remove-Item $env:TEMP/esh-master -Force -ErrorAction Ignore -Confirm:$false -Recurse
try { Invoke-WebRequest https://bit.ly/Esh-zip -OutFile $env:TEMP/Eshell.zip }
catch {
$Host.UI.WriteErrorLine("下载错误 终止程序")
exit 1
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
}
Expand-Archive $env:TEMP/Eshell.zip $env:TEMP -Force
Remove-Item $env:TEMP/Eshell.zip -Force
Move-Item $env:TEMP/esh-master $env:LOCALAPPDATA/esh -Force
$eshDir = "$env:LOCALAPPDATA/esh"
try { Invoke-WebRequest 'https://bit.ly/SAO-lib' -OutFile "$eshDir/data/SAO-lib.txt" }
catch {
Expand All @@ -36,7 +45,7 @@ if (-not $eshDir) {
}

if ($RunInstall){
. $eshDir/src/opt/install.ps1 $RemainingArguments
Invoke-Expression "&$eshDir/src/opt/install.ps1 $RemainingArguments"
exit
}
if (-not (Get-Command pwsh -ErrorAction Ignore)) {
Expand Down
4 changes: 4 additions & 0 deletions runner/tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/PS2EXE
/psminnifyer
/SigThief
/ConfuserEx
2 changes: 2 additions & 0 deletions runner/tools/desktop.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,71
Loading

0 comments on commit 1f79b5a

Please sign in to comment.