-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-Release.ps1
More file actions
140 lines (114 loc) · 6.39 KB
/
Build-Release.ps1
File metadata and controls
140 lines (114 loc) · 6.39 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
<#
.SYNOPSIS
������� �������� ������ ������� CreateOrder.
.DESCRIPTION
Подготавливает защищённую релизную сборку: штатный пароль на VBA-проект и Ghost Module (скрытие важных модулей).
���������� ������� ���� � ������ ���� � ������� (��������, CreateOrder_Release_20260225_153000.xlsm).
#>
param(
[string]$SourceFile = "CreateOrder.xlsm"
)
# ����������� ��������� ������� �� UTF-8 ��� ����������� ������ ������� ����
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# ���������� ������������ ��� ��������� ����� � ����� � ��������
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$releaseDir = Join-Path (Get-Location) "CreateOrderReleases"
$OutputFile = Join-Path $releaseDir "CreateOrder_Release_$timestamp.xlsm"
Write-Host "=== ������ ������ ����������� ������ ===" -ForegroundColor Cyan
# ������� ���������� ����� ��� �������� �������� �������
New-Item -ItemType Directory -Path $releaseDir -Force | Out-Null
# �������� ������� ��������� �����
if (-not (Test-Path $SourceFile)) {
Write-Host "[X] ������: �������� ���� $SourceFile �� ������!" -ForegroundColor Red
exit
}
# 1. ���������� ��������� ����������
$tempDir = Join-Path $env:TEMP "CreateOrderBuild_$timestamp"
$tempZip = Join-Path $tempDir "temp_archive.zip"
$extractDir = Join-Path $tempDir "extracted"
New-Item -ItemType Directory -Path $extractDir -Force | Out-Null
Copy-Item -Path $SourceFile -Destination $tempZip -Force
Write-Host "[1/4] ���������� ������ xlsm..." -ForegroundColor Yellow
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($tempZip, $extractDir)
# 2. ����� vbaProject.bin
$vbaBinPath = Join-Path $extractDir "xl\vbaProject.bin"
if (-not (Test-Path $vbaBinPath)) {
Write-Host "[X] ������: ���� vbaProject.bin �� ������ � ������!" -ForegroundColor Red
Remove-Item $tempDir -Recurse -Force
exit
}
# 3. �������� ������� (Binary Byte Patching)
Write-Host "[2/4] ���������� �������� ������..." -ForegroundColor Yellow
$bytes = [System.IO.File]::ReadAllBytes($vbaBinPath)
$ascii = [System.Text.Encoding]::ASCII
function Replace-ByteSequence {
param(
[byte[]]$Buffer,
[byte[]]$Search,
[byte[]]$Replace
)
if ($Search.Length -ne $Replace.Length) {
throw "Search and replace sequences must have the same length."
}
$matches = 0
for ($i = 0; $i -le $Buffer.Length - $Search.Length; $i++) {
$found = $true
for ($j = 0; $j -lt $Search.Length; $j++) {
if ($Buffer[$i + $j] -ne $Search[$j]) {
$found = $false
break
}
}
if ($found) {
for ($j = 0; $j -lt $Replace.Length; $j++) {
$Buffer[$i + $j] = $Replace[$j]
}
$matches++
}
}
return $matches
}
# --- Слой 1: штатный пароль на VBA-проект, без DPx-хаков ---
# --- ���� 2: Ghost Modules (������� �� ������) ---
# ������ ������ ������� ��� ������� (������ �� ������� ����� Alt+F8)
$modulesToHide = @(
"modActivation", # ������ ��������
"mdlRibbonHandlers", # ������ �������� � �����
"mdlMainExport", # �������� ������
"mdlRaportExport", # �������
"mdlSpravkaExport", # ������� ���
"mdlRiskExport", # ������ �� ����
"mdlUniversalPaymentExport", # ��������
"mdlFRPExport", # ������ ������
"mdlWordImport", # ������ ��������
"MdlBackup", # �������
"frmAbout"
)
$ghostedCount = 0
foreach ($modName in $modulesToHide) {
$searchStr = "Module=$modName"
$searchBytes = $ascii.GetBytes($searchStr)
$replaceBytes = $ascii.GetBytes((" " * $searchStr.Length))
$patchedCount = Replace-ByteSequence -Buffer $bytes -Search $searchBytes -Replace $replaceBytes
if ($patchedCount -gt 0) {
$ghostedCount += $patchedCount
Write-Host " -> [Ghosting]: ������ '$modName' �����. matches=$patchedCount" -ForegroundColor Green
} else {
Write-Host " -> [Ghosting]: ������ '$modName' �� ������ � ������ PROJECT." -ForegroundColor DarkYellow
}
}
# ��������� ���� ������� � �����
[System.IO.File]::WriteAllBytes($vbaBinPath, $bytes)
Write-Host " -> [Patch]: ghosted modules=$ghostedCount" -ForegroundColor Green
# 4. �������� ���������
Write-Host "[3/4] ��������� ��������� ������..." -ForegroundColor Yellow
Remove-Item $tempZip -Force
[System.IO.Compression.ZipFile]::CreateFromDirectory($extractDir, $tempZip)
# 5. ������� ����������
Write-Host "[4/4] �����������..." -ForegroundColor Yellow
Copy-Item -Path $tempZip -Destination $OutputFile -Force
# ������� ������
Remove-Item $tempDir -Recurse -Force
Write-Host "=== ������! ===" -ForegroundColor Cyan
Write-Host "���������� ���� ������: $OutputFile" -ForegroundColor Green