1+ param (
2+ [Parameter (ParameterSetName = ' x86' )]
3+ [Parameter (ParameterSetName = ' x86Clean' )]
4+ [Parameter (ParameterSetName = ' x86Init' )]
5+ [switch ]$x86 ,
6+
7+ [Parameter (ParameterSetName = ' cil' )]
8+ [Parameter (ParameterSetName = ' cilClean' )]
9+ [Parameter (ParameterSetName = ' cilInit' )]
10+ [switch ]$cil ,
11+
12+ [Parameter (Mandatory = $true , ParameterSetName = ' x86Init' )]
13+ [Parameter (Mandatory = $true , ParameterSetName = ' cilInit' )]
14+ [switch ]$init ,
15+
16+ [Parameter (Mandatory = $true , ParameterSetName = ' x86' )]
17+ [Parameter (Mandatory = $true , ParameterSetName = ' cil' )]
18+ [Parameter (Mandatory = $true , ParameterSetName = ' x86Init' )]
19+ [Parameter (Mandatory = $true , ParameterSetName = ' cilInit' )]
20+ [string ]$cliFolder ,
21+
22+ [Parameter (Mandatory = $true , ParameterSetName = ' x86Clean' )]
23+ [Parameter (Mandatory = $true , ParameterSetName = ' cilClean' )]
24+ [switch ]$clean
25+ )
26+
27+ function x86 {
28+ function init-lief {
29+ git clone https:// github.com / lief- project/ LIEF.git
30+ cd LIEF
31+ cmake - G " NMake Makefiles" - DCMAKE_BUILD_TYPE= Release - DBUILD_SHARED_LIBS= OFF - DCMAKE_MSVC_RUNTIME_LIBRARY= " MultiThreaded" .
32+ nmake
33+ nmake install
34+ cd ..
35+ }
36+
37+ function init-zydis {
38+ git clone https:// github.com / zyantific/ zydis.git -- recursive
39+ cd zydis
40+ cmake - G " NMake Makefiles" - DCMAKE_BUILD_TYPE= Release - DBUILD_SHARED_LIBS= OFF - DCMAKE_MSVC_RUNTIME_LIBRARY= " MultiThreaded" .
41+ nmake
42+ nmake install
43+ cd ..
44+ }
45+
46+ function init-fmt {
47+ git clone https:// github.com / fmtlib/ fmt.git
48+ }
49+
50+ function init-boost-library ($name ) {
51+ git clone https:// github.com / boostorg/ $name.git
52+ xcopy / E / I / Y $name \include\boost boost- minimal\boost
53+ Remove-Item - Path $name - Recurse - Force
54+ }
55+
56+ function init-boost {
57+ if (-not (Test-Path boost- minimal)) {
58+ mkdir boost- minimal
59+ }
60+ init- boost- library algorithm
61+ init- boost- library mpl
62+ init- boost- library range
63+ init- boost- library preprocessor
64+ init- boost- library type_traits
65+ init- boost- library iterator
66+ init- boost- library assert
67+ init- boost- library mp11
68+ init- boost- library static_assert
69+ init- boost- library core
70+ init- boost- library concept_check
71+ init- boost- library utility
72+ init- boost- library function
73+ init- boost- library bind
74+ init- boost- library throw_exception
75+ init- boost- library optional
76+ init- boost- library config
77+ }
78+
79+ function init-args {
80+ git clone https:// github.com / Taywee/ args.git
81+ }
82+
83+ if ($init ) {
84+ Push-Location extractor/ x86
85+ init- lief
86+ init- zydis
87+ init- fmt
88+ init- boost
89+ init- args
90+ Pop-Location
91+ }
92+
93+ if ($clean ) {
94+ Push-Location extractor/ x86
95+ if (Test-Path args) { Remove-Item - Path args - Recurse - Force }
96+ if (Test-Path boost- minimal) { Remove-Item - Path boost- minimal - Recurse - Force }
97+ if (Test-Path fmt) { Remove-Item - Path fmt - Recurse - Force }
98+ if (Test-Path LIEF) { Remove-Item - Path LIEF - Recurse - Force }
99+ if (Test-Path zydis) { Remove-Item - Path zydis - Recurse - Force }
100+ Pop-Location
101+ } else {
102+ Push-Location extractor/ x86
103+
104+ cl.exe / DFMT_HEADER_ONLY / DZYDIS_STATIC_BUILD / I zydis\include / I zydis\dependencies\zycore\include / I LIEF/ include / I fmt/ include / I boost- minimal / I args / utf- 8 src/ main.cpp zydis\Zydis.lib zydis/ zycore/ zycore.lib LIEF/ LIEF.lib / EHsc / std:c+ +17 / link / out:extractor.exe
105+
106+ if ($LASTEXITCODE -ne 0 ) {
107+ Write-Host " Build failed"
108+ Pop-Location
109+ exit 1
110+ }
111+
112+ Pop-Location
113+
114+ $toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder " binary" ) " tools" ) " win64"
115+ New-Item - ItemType Directory - Force - Path $toolsWin64Folder
116+ $binaryFolder = Join-Path - Path $cliFolder - ChildPath " binary"
117+ New-Item - ItemType Directory - Force - Path $binaryFolder
118+ Copy-Item - Path " $PSScriptRoot /extractor/x86/codeql-extractor.yml" - Destination $binaryFolder - Force
119+ Copy-Item - Path " $PSScriptRoot /downgrades" - Destination $binaryFolder - Recurse - Force
120+ $qlLibFolder = Join-Path - Path " $PSScriptRoot /ql" - ChildPath " lib"
121+ Copy-Item - Path (Join-Path $qlLibFolder " semmlecode.binary.dbscheme" ) - Destination $binaryFolder - Force
122+ Copy-Item - Path (Join-Path $qlLibFolder " semmlecode.binary.dbscheme.stats" ) - Destination $binaryFolder - Force
123+ Copy-Item - Path " $PSScriptRoot /tools/x86/*" - Destination (Join-Path $binaryFolder " tools" ) - Recurse - Force
124+ Copy-Item - Path " $PSScriptRoot /extractor/x86/extractor.exe" - Destination $toolsWin64Folder / extractor.exe
125+ }
126+ }
127+
128+ function cil {
129+ Push-Location extractor/ cil
130+ $toolsWin64Folder = Join-Path (Join-Path (Join-Path $cliFolder " cil" ) " tools" ) " win64"
131+ dotnet build Semmle.Extraction.CSharp.IL - o $toolsWin64Folder - c Release -- self- contained
132+ if ($LASTEXITCODE -ne 0 ) {
133+ Write-Host " Build failed"
134+ Pop-Location
135+ exit 1
136+ }
137+
138+ Pop-Location
139+
140+ New-Item - ItemType Directory - Force - Path $toolsWin64Folder
141+ $cilFolder = Join-Path - Path $cliFolder - ChildPath " cil"
142+ New-Item - ItemType Directory - Force - Path $cilFolder
143+ Copy-Item - Path " $PSScriptRoot /extractor/cil/codeql-extractor.yml" - Destination $cilFolder - Force
144+ Copy-Item - Path " $PSScriptRoot /downgrades" - Destination $cilFolder - Recurse - Force
145+ $qlLibFolder = Join-Path - Path " $PSScriptRoot /ql" - ChildPath " lib"
146+ Copy-Item - Path (Join-Path $qlLibFolder " semmlecode.binary.dbscheme" ) - Destination $cilFolder - Force
147+ Copy-Item - Path (Join-Path $qlLibFolder " semmlecode.binary.dbscheme.stats" ) - Destination $cilFolder - Force
148+ Copy-Item - Path " $PSScriptRoot /tools/cil/*" - Destination (Join-Path $cilFolder " tools" ) - Recurse - Force
149+ }
150+
151+ if ($x86 ) {
152+ x86
153+ }
154+
155+ if ($cil ) {
156+ cil
157+ }
0 commit comments