forked from Lil-House/Pyarmor-Static-Unpack-1shot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
178 lines (137 loc) · 4.42 KB
/
build.ps1
File metadata and controls
178 lines (137 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# ================================
# Pyarmor 1shot Full Automation
# build.ps1
# ================================
$ErrorActionPreference = "Stop"
function Write-Step {
param([string]$Message)
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor DarkGray
Write-Host $Message -ForegroundColor Cyan
Write-Host ("=" * 80) -ForegroundColor DarkGray
}
function Fail {
param([string]$Message)
Write-Host "[ERROR] $Message" -ForegroundColor Red
exit 1
}
function Assert-Exists {
param(
[Parameter(Mandatory = $true)][string]$Path,
[string]$Label = "Path"
)
if (-not (Test-Path -LiteralPath $Path)) {
Fail "$Label not found: $Path"
}
}
function Ensure-Dir {
param([Parameter(Mandatory = $true)][string]$Path)
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -ItemType Directory -Path $Path | Out-Null
}
}
function Invoke-NativeCommand {
param(
[Parameter(Mandatory = $true)][string]$FilePath,
[Parameter()][string[]]$Arguments = @(),
[string]$WorkingDirectory = $PWD.Path
)
Write-Host "[CMD] $FilePath $($Arguments -join ' ')" -ForegroundColor Yellow
Push-Location $WorkingDirectory
try {
& $FilePath @Arguments
$exitCode = $LASTEXITCODE
}
finally {
Pop-Location
}
if ($exitCode -ne 0) {
throw "명령 실행 실패 (exit code $exitCode): $FilePath $($Arguments -join ' ')"
}
}
# ---- 고정 경로 ----
$BASE_DIR = "C:\tmp\Pyarmor-Static-Unpack-1shot"
$BUILD_DIR = Join-Path $BASE_DIR "build"
$PYCDC_DIR = Join-Path $BASE_DIR "pycdc"
$TARGET_DIR = "C:\tmp\v305.exe_extracted"
$RUNTIME_PYD = Join-Path $TARGET_DIR "pyarmor_runtime_009673\pyarmor_runtime.pyd"
$ONESHOT_EXE = Join-Path $BUILD_DIR "Release\pyarmor-1shot.exe"
$ONESHOT_DEST = Join-Path $BASE_DIR "oneshot\pyarmor-1shot.exe"
$SHOT_SCRIPT = Join-Path $BASE_DIR "oneshot\shot.py"
$LOG_FILE = Join-Path $BASE_DIR "1shot.log"
$WSL_DEST = "\\wsl.localhost\Ubuntu-24.04\home\phantom\v138\test_data"
$PYC_PATTERN = "엔잡곰자동화시스템_반자동v305_배포용_s.pyc*"
# ---- Validation ----
Write-Step "Validation"
Assert-Exists -Path $BASE_DIR -Label "BaseDir"
Assert-Exists -Path $PYCDC_DIR -Label "pycdc"
Assert-Exists -Path $TARGET_DIR -Label "TargetDir"
Assert-Exists -Path $RUNTIME_PYD -Label "RuntimePyd"
Assert-Exists -Path $SHOT_SCRIPT -Label "shot.py"
try {
$pythonCmd = (Get-Command python -ErrorAction Stop).Source
}
catch {
Fail "python not found in PATH"
}
try {
$cmakeCmd = (Get-Command cmake -ErrorAction Stop).Source
}
catch {
Fail "cmake not found in PATH"
}
Ensure-Dir -Path $WSL_DEST
# ---- Clean build ----
Write-Step "Clean build"
if (Test-Path -LiteralPath $BUILD_DIR) {
Remove-Item -Recurse -Force $BUILD_DIR
}
New-Item -ItemType Directory -Path $BUILD_DIR | Out-Null
# 기존 로그 삭제
if (Test-Path -LiteralPath $LOG_FILE) {
Remove-Item -Force $LOG_FILE
}
# ---- Configure ----
Write-Step "CMake configure"
Invoke-NativeCommand `
-FilePath $cmakeCmd `
-Arguments @("-S", $PYCDC_DIR, "-B", $BUILD_DIR, "-G", "Visual Studio 17 2022")
# ---- Build (max CPU) ----
Write-Step "CMake build"
Invoke-NativeCommand `
-FilePath $cmakeCmd `
-Arguments @("--build", $BUILD_DIR, "--config", "Release", "--", "/m")
Assert-Exists -Path $ONESHOT_EXE -Label "pyarmor-1shot.exe"
# ---- Copy exe ----
Write-Step "Copy exe"
Copy-Item -LiteralPath $ONESHOT_EXE -Destination $ONESHOT_DEST -Force
Assert-Exists -Path $ONESHOT_DEST -Label "oneshot exe"
# ---- Run shot ----
Write-Step "Run shot.py"
Clear-Host
Set-Location $BASE_DIR
& $pythonCmd `
$SHOT_SCRIPT `
$TARGET_DIR `
-r $RUNTIME_PYD `
--show-all `
--no-banner `
--export-raw-data `
*> $LOG_FILE
if ($LASTEXITCODE -ne 0) {
throw "Python 실행 실패 (exit code $LASTEXITCODE)"
}
Assert-Exists -Path $LOG_FILE -Label "1shot.log"
# ---- Copy artifacts ----
Write-Step "Copy artifacts"
Copy-Item -LiteralPath $LOG_FILE -Destination $WSL_DEST -Force
$pycFiles = Get-ChildItem -Path (Join-Path $TARGET_DIR $PYC_PATTERN) -ErrorAction SilentlyContinue
if (-not $pycFiles) {
Fail "pyc 파일 없음: $(Join-Path $TARGET_DIR $PYC_PATTERN)"
}
foreach ($f in $pycFiles) {
Copy-Item -LiteralPath $f.FullName -Destination $WSL_DEST -Force
Write-Host "Copied: $($f.FullName)" -ForegroundColor Green
}
Write-Step "Done"
Write-Host "Done: Full pipeline success" -ForegroundColor Green