-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_all.ps1
More file actions
138 lines (122 loc) · 5.75 KB
/
build_all.ps1
File metadata and controls
138 lines (122 loc) · 5.75 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
# build_all.ps1
# Full build for TrayObserver — uses direct string invocation, no array splatting
# Run from the PS session where x64env.ps1 has already been executed.
# Usage: cd C:\Intel\Watcher ; .\build_all.ps1
$Root = $PSScriptRoot
$CompA = "$Root\ComponentA"
$CompB = "$Root\ComponentB"
$GUI = "$Root\GUI"
$Common = "$Root\Common"
$Deploy = "$Root\Deploy"
function Run-Build {
param([string]$Label, [string]$CmdLine)
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " $Label" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
Write-Host $CmdLine -ForegroundColor DarkGray
Write-Host ""
$output = cmd /c "$CmdLine 2>&1"
$output | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0) {
Write-Host "[FAILED] $Label (exit code $LASTEXITCODE)" -ForegroundColor Red
throw "Build failed at: $Label"
}
Write-Host "[OK] $Label" -ForegroundColor Green
}
$CF = "/nologo /W4 /WX- /O2 /EHsc /DUNICODE /D_UNICODE /D_CRT_SECURE_NO_WARNINGS /GS /sdl /guard:cf"
$SEC = "/NXCOMPAT /DYNAMICBASE /HIGHENTROPYVA /GUARD:CF /SAFESEH:NO"
# Compile a .rc file to .res using rc.exe (from Windows Kits)
function Compile-RC {
param([string]$RcFile, [string]$ResFile)
$output = cmd /c "rc.exe /nologo /fo ""$ResFile"" ""$RcFile"" 2>&1"
$output | ForEach-Object { Write-Host $_ }
if ($LASTEXITCODE -ne 0) {
Write-Host "[WARN] RC compile failed for $RcFile — continuing without version info" -ForegroundColor Yellow
return $false
}
return $true
}
# Compile all version resource files
Write-Host "Compiling version resources..." -ForegroundColor Cyan
$resTrayhook = if (Compile-RC "$CompA\TrayHook.rc" "$CompA\TrayHook.res") { """$CompA\TrayHook.res""" } else { "" }
$resCompA = if (Compile-RC "$CompA\ComponentA.rc" "$CompA\ComponentA.res") { """$CompA\ComponentA.res""" } else { "" }
$resPayload = if (Compile-RC "$CompB\PayloadHook.rc" "$CompB\PayloadHook.res") { """$CompB\PayloadHook.res""" } else { "" }
$resCompB = if (Compile-RC "$CompB\ComponentB.rc" "$CompB\ComponentB.res") { """$CompB\ComponentB.res""" } else { "" }
$resGUI = if (Compile-RC "$Root\TrayObserver.rc" "$Root\TrayObserver.res") { """$Root\TrayObserver.res""" } else { "" }
$INC_A = "/I""$Common"" /I""$CompA"""
$INC_B = "/I""$Common"" /I""$CompB"" /I""$CompA"""
$INC_GUI = "/I""$Common"" /I""$CompA"" /I""$CompB"" /I""$GUI"""
Run-Build "TrayHook.dll" (
"cl.exe $CF $INC_A /LD /D_USRDLL " +
"""$CompA\TrayHook.cpp"" $resTrayhook " +
"/Fe:""$CompA\TrayHook.dll"" " +
"/link /DLL /SUBSYSTEM:WINDOWS /DEF:""$CompA\TrayHook.def"" " +
"$SEC user32.lib kernel32.lib psapi.lib shell32.lib strsafe.lib"
)
Run-Build "ComponentA.dll" (
"cl.exe $CF $INC_A /LD /DCOMPONENTA_EXPORTS " +
"""$CompA\ComponentA.cpp"" ""$CompA\TraySnapshot.cpp"" $resCompA " +
"/Fe:""$CompA\ComponentA.dll"" " +
"/link /DLL /SUBSYSTEM:WINDOWS /DEF:""$CompA\ComponentA.def"" " +
"$SEC /CETCOMPAT user32.lib kernel32.lib psapi.lib comctl32.lib shell32.lib strsafe.lib advapi32.lib"
)
Run-Build "PayloadHook.dll" (
"cl.exe $CF $INC_B /LD " +
"""$CompB\PayloadHook.cpp"" $resPayload " +
"/Fe:""$CompB\PayloadHook.dll"" " +
"/link /DLL /SUBSYSTEM:WINDOWS /DEF:""$CompB\PayloadHook.def"" " +
"$SEC user32.lib kernel32.lib psapi.lib shell32.lib strsafe.lib"
)
Run-Build "ComponentB.dll" (
"cl.exe $CF $INC_B /LD /DCOMPONENTB_EXPORTS " +
"""$CompB\ComponentB.cpp"" ""$CompB\ProcessFilter.cpp"" $resCompB " +
"/Fe:""$CompB\ComponentB.dll"" " +
"/link /DLL /SUBSYSTEM:WINDOWS /DEF:""$CompB\ComponentB.def"" " +
"$SEC /CETCOMPAT user32.lib kernel32.lib psapi.lib shell32.lib strsafe.lib wintrust.lib crypt32.lib advapi32.lib"
)
Run-Build "TrayObserver.exe" (
"cl.exe $CF $INC_GUI " +
"""$GUI\MainWindow.cpp"" ""$GUI\DashView.cpp"" ""$GUI\Views_Misc.cpp"" " +
"""$GUI\Theme.cpp"" ""$GUI\EventStore.cpp"" ""$GUI\CsvLogger.cpp"" $resGUI " +
"/Fe:""$GUI\TrayObserver.exe"" " +
"/link /SUBSYSTEM:WINDOWS /ENTRY:wWinMainCRTStartup " +
"$SEC /CETCOMPAT " +
"user32.lib kernel32.lib psapi.lib comctl32.lib shell32.lib strsafe.lib gdi32.lib uxtheme.lib advapi32.lib " +
"""$CompA\ComponentA.lib"" ""$CompB\ComponentB.lib"""
)
Write-Host ""
Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Collecting runtime files" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan
if (-not (Test-Path $Deploy)) { New-Item -ItemType Directory -Path $Deploy | Out-Null }
$files = @(
"$CompA\TrayHook.dll",
"$CompA\ComponentA.dll",
"$CompB\PayloadHook.dll",
"$CompB\ComponentB.dll",
"$GUI\TrayObserver.exe"
)
$allFound = $true
foreach ($f in $files) {
if (Test-Path $f) {
Copy-Item $f $Deploy -Force
Write-Host " -> $(Split-Path $f -Leaf)" -ForegroundColor Green
} else {
Write-Host " MISSING: $f" -ForegroundColor Red
$allFound = $false
}
}
Write-Host ""
if ($allFound) {
Write-Host "============================================" -ForegroundColor Green
Write-Host " Build complete. Output: $Deploy" -ForegroundColor Green
Write-Host "============================================" -ForegroundColor Green
Write-Host ""
Write-Host "Before first run:" -ForegroundColor Yellow
Write-Host " 1. Add $Deploy to Windows Defender exclusions" -ForegroundColor Yellow
Write-Host " 2. Add $Deploy to ESET exclusions" -ForegroundColor Yellow
Write-Host " 3. Run elevated: $Deploy\TrayObserver.exe" -ForegroundColor Yellow
} else {
Write-Host "Some files missing — check build output above for errors." -ForegroundColor Red
}