-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTCC-Analyzer.ps1
More file actions
1402 lines (1183 loc) · 62.6 KB
/
TCC-Analyzer.ps1
File metadata and controls
1402 lines (1183 loc) · 62.6 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# TCC-Analyzer v0.1
#
# @author: Martin Willing
# @copyright: Copyright (c) 2026 Martin Willing. All rights reserved. Licensed under the MIT license.
# @contact: Any feedback or suggestions are always welcome and much appreciated - mwilling@lethal-forensics.com
# @url: https://lethal-forensics.com/
# @date: 2026-03-16
#
#
# ██╗ ███████╗████████╗██╗ ██╗ █████╗ ██╗ ███████╗ ██████╗ ██████╗ ███████╗███╗ ██╗███████╗██╗ ██████╗███████╗
# ██║ ██╔════╝╚══██╔══╝██║ ██║██╔══██╗██║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██║██╔════╝██╔════╝
# ██║ █████╗ ██║ ███████║███████║██║█████╗█████╗ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗██║██║ ███████╗
# ██║ ██╔══╝ ██║ ██╔══██║██╔══██║██║╚════╝██╔══╝ ██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║╚════██║██║██║ ╚════██║
# ███████╗███████╗ ██║ ██║ ██║██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║███████╗██║ ╚████║███████║██║╚██████╗███████║
# ╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝╚══════╝
#
#
# Dependencies:
#
# ImportExcel v7.8.10 (2024-10-21)
# https://github.com/dfinke/ImportExcel
#
# jq v1.7.1 (2023-12-13)
# https://github.com/stedolan/jq
#
# SQLite Tools for Windows v3.50.4 (2025-07-30)
# https://sqlite.org/download.html --> Command-line tools for Windows x64 --> sqlite-tools-win-x64-3500400.zip
#
#
# Changelog:
# Version 0.1
# Release Date: 2025-11-10
# Initial Release
#
#
# Tested on Windows 10 Pro (x64) Version 22H2 (10.0.19045.6456) and PowerShell 5.1 (5.1.19041.6456)
# Tested on Windows 10 Pro (x64) Version 22H2 (10.0.19045.6456) and PowerShell 7.5.5
#
#
#############################################################################################################################################################################################
#############################################################################################################################################################################################
<#
.SYNOPSIS
TCC-Analyzer v0.1 - Automated Forensic Analysis of macOS TCC database file(s) for DFIR
.DESCRIPTION
TCC-Analyzer.ps1 is a PowerShell script utilized to simplify the analysis of the macOS TCC.db.
.PARAMETER OutputDir
Specifies the output directory. Default is "$env:USERPROFILE\Desktop\TCC-Analyzer".
Note: The subdirectory 'TCC-Analyzer' is automatically created.
.PARAMETER Path
Specifies the path to the input directory.
.EXAMPLE
PS> .\TCC-Analyzer.ps1
.EXAMPLE
PS> .\TCC-Analyzer.ps1 -Path "$env:USERPROFILE\Desktop\tcc_<USERNAME>"
.EXAMPLE
PS> .\TCC-Analyzer.ps1 -Path "H:\macos-collector\Aftermath_Collection\tcc_<USERNAME>" -OutputDir "H:\MacOS-Analyzer-Suite"
.NOTES
Author - Martin Willing
.LINK
https://lethal-forensics.com/
#>
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region CmdletBinding
[CmdletBinding()]
Param(
[String]$Path,
[String]$OutputDir
)
#endregion CmdletBinding
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region Initialisations
# Set Progress Preference to Silently Continue
$OriginalProgressPreference = $Global:ProgressPreference
$Global:ProgressPreference = 'SilentlyContinue'
#endregion Initialisations
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region Declarations
# Declarations
# Script Root
if ($PSVersionTable.PSVersion.Major -gt 2)
{
# PowerShell 3+
$SCRIPT_DIR = $PSScriptRoot
}
else
{
# PowerShell 2
$SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
}
# Output Directory
if (!($OutputDir))
{
$script:OUTPUT_FOLDER = "$env:USERPROFILE\Desktop\TCC-Analyzer" # Default
}
else
{
if ($OutputDir -cnotmatch '.+(?=\\)')
{
Write-Host "[Error] You must provide a valid directory path." -ForegroundColor Red
Exit
}
else
{
$script:OUTPUT_FOLDER = "$OutputDir\TCC-Analyzer" # Custom
}
}
# Tools
# jq
$script:jq = "$SCRIPT_DIR\Tools\jq\jq-windows-amd64.exe"
# SQLite3
$script:SQLite3 = "$SCRIPT_DIR\Tools\SQLite\sqlite3.exe"
# Configuration File (JSON)
if(!(Test-Path "$PSScriptRoot\Config.json"))
{
Write-Host "[Error] Config.json NOT found." -ForegroundColor Red
Exit
}
else
{
$Config = Get-Content "$PSScriptRoot\Config.json" | ConvertFrom-Json
# BackgroundColor
if ($Config.ImportExcel.BackgroundColor)
{
if ($Config.ImportExcel.BackgroundColor -cnotmatch '^(([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5])),(([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5])),(([0-1]?[0-9]?[0-9])|([2][0-4][0-9])|(25[0-5]))$') # <0-255>,<0-255>,<0-255>
{
Write-Host "[Error] You must provide a valid RGB Color Code." -ForegroundColor Red
Return
}
}
# Excel - Color Scheme
$script:BackgroundColor = [System.Drawing.Color]$Config.ImportExcel.BackgroundColor
$script:FontColor = $Config.ImportExcel.FontColor
}
#endregion Declarations
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region Header
# Windows Title
$DefaultWindowsTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "TCC-Analyzer v0.1 - Automated Forensic Analysis of macOS TCC database file(s) for DFIR"
# Check if the PowerShell script is being run with admin rights
if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
Write-Host "[Error] This PowerShell script must be run with admin rights." -ForegroundColor Red
Exit
}
# Check if PowerShell module 'ImportExcel' is installed
if (!(Get-Module -ListAvailable -Name ImportExcel))
{
Write-Host "[Error] Please install 'ImportExcel' PowerShell module." -ForegroundColor Red
Write-Host "[Info] Check out: https://github.com/dfinke/ImportExcel"
Exit
}
# Flush Output Directory
if (Test-Path "$OUTPUT_FOLDER")
{
Get-ChildItem -Path "$OUTPUT_FOLDER" -Force -Recurse -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse
New-Item "$OUTPUT_FOLDER" -ItemType Directory -Force | Out-Null
}
else
{
New-Item "$OUTPUT_FOLDER" -ItemType Directory -Force | Out-Null
}
# Function Get-FileSize
Function Get-FileSize()
{
Param ([long]$Length)
If ($Length -gt 1TB) {[string]::Format("{0:0.00} TB", $Length / 1TB)}
ElseIf ($Length -gt 1GB) {[string]::Format("{0:0.00} GB", $Length / 1GB)}
ElseIf ($Length -gt 1MB) {[string]::Format("{0:0.00} MB", $Length / 1MB)}
ElseIf ($Length -gt 1KB) {[string]::Format("{0:0.00} KB", $Length / 1KB)}
ElseIf ($Length -gt 0) {[string]::Format("{0:0.00} Bytes", $Length)}
Else {""}
}
Function Test-Csv {
<#
.SYNOPSIS
Test-Csv - Fast Check if CSV is NOT empty
.DESCRIPTION
The Test-Csv cmdlet checks if the rows of your CSV file are NOT empty.
.PARAMETER Path
Specifies the path to the CSV file.
.PARAMETER MaxLines
Specifies the maximum of lines to read from CSV file.
.PARAMETER NoHeader (Optional)
If this switch is specified, function will NOT skip first line of the file.
.EXAMPLE
Test-Csv -Path <CSV> -MaxLines 2
.EXAMPLE
Test-Csv -Path <CSV> -MaxLines 1 -NoHeader
.NOTES
Author - Martin Willing
.LINK
https://lethal-forensics.com/
#>
Param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]$Path,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateRange(1, [int]::MaxValue)]
[int]$MaxLines,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch]$NoHeader
)
Begin
{
$Quotes = '"'
$Delimiter = ','
$Regex = "$Delimiter(?=(?:[^$Quotes]|$Quotes[^$Quotes]*$Quotes)*$)"
}
Process
{
$Reader = New-Object -TypeName System.IO.StreamReader -ArgumentList $Path -ErrorAction Stop
$CsvRawLinesCount = 0
$CsvDataLinesCount = 0
while($null -ne ($Line = $Reader.ReadLine()))
{
$CsvRawLinesCount++
if(!$NoHeader -and ($CsvRawLinesCount -eq 1))
{
continue
}
if($CsvRawLinesCount -gt $MaxLines)
{
break
}
if($Line -match $Regex)
{
$CsvDataLinesCount++
}
}
}
End
{
$Reader.Close()
$Reader.Dispose()
if($CsvDataLinesCount -gt 0)
{
$true
}
else
{
$false
}
}
}
# Select Log File (TCC.db)
if(!($Path))
{
Function Get-LogFile($InitialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.InitialDirectory = $InitialDirectory
$OpenFileDialog.Filter = "TCC Database|tcc_*|All Files (*.*)|*.*"
$OpenFileDialog.ShowDialog()
$OpenFileDialog.Filename
$OpenFileDialog.ShowHelp = $true
$OpenFileDialog.Multiselect = $false
}
$Result = Get-LogFile
if($Result -eq "OK")
{
$script:DatabaseFile = $Result[1]
}
else
{
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
}
else
{
$script:DatabaseFile = $Path
}
# Create a record of your PowerShell session to a text file
Start-Transcript -Path "$OUTPUT_FOLDER\Transcript.txt"
# Get Start Time
$startTime = (Get-Date)
# Logo
$Logo = @"
██╗ ███████╗████████╗██╗ ██╗ █████╗ ██╗ ███████╗ ██████╗ ██████╗ ███████╗███╗ ██╗███████╗██╗ ██████╗███████╗
██║ ██╔════╝╚══██╔══╝██║ ██║██╔══██╗██║ ██╔════╝██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██║██╔════╝██╔════╝
██║ █████╗ ██║ ███████║███████║██║█████╗█████╗ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗██║██║ ███████╗
██║ ██╔══╝ ██║ ██╔══██║██╔══██║██║╚════╝██╔══╝ ██║ ██║██╔══██╗██╔══╝ ██║╚██╗██║╚════██║██║██║ ╚════██║
███████╗███████╗ ██║ ██║ ██║██║ ██║███████╗ ██║ ╚██████╔╝██║ ██║███████╗██║ ╚████║███████║██║╚██████╗███████║
╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝╚══════╝
"@
Write-Output ""
Write-Output "$Logo"
Write-Output ""
# Header
Write-Output "TCC-Analyzer v0.1 - Automated Forensic Analysis of macOS TCC database file(s) for DFIR"
Write-Output "(c) 2026 Martin Willing at Lethal-Forensics (https://lethal-forensics.com/)"
Write-Output ""
# Analysis date (ISO 8601)
$AnalysisDate = [datetime]::Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss")
Write-Output "Analysis date: $AnalysisDate UTC"
Write-Output ""
#endregion Header
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region Analysis
# TCC - Transparency, Consent, and Control (macOS)
# A framework for regulating applications permissions by managing their access to user data.
# TCC Database(s)
# System-wide database
# /Library/Application Support/com.apple.TCC/TCC.db --> global one (root-level)
# User-specific database
# /Users/<username>/Library/Applicatio0n Support/com.apple.TCC/TCC.db (per-user)
# Note: These TCC datbase(s) are protected from editing with SIP (System Integrity Protection), but you can read them by granting your terminal application or editor full disk access.
# Aftermath Source:
# Aftermath_Collection\Aftermath_<SERIAL_NUMBER>.zip\Artifatcs\raw\tcc_<USERNAME>
# Check if Database File exists
if (!(Test-Path "$($DatabaseFile)"))
{
Write-Host "[Error] $DatabaseFile does not exist." -ForegroundColor Red
Write-Host ""
Stop-Transcript
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
# Check Signature (Magic Number)
if ($PSEdition -eq "Core")
{
$Bytes = (Get-Content -Path $DatabaseFile -AsByteStream -ReadCount 1 -TotalCount 16) # PowerShell 7
}
else
{
$Bytes = (Get-Content -Path $DatabaseFile -Encoding Byte -ReadCount 1 -TotalCount 16) # PowerShell 5.1
}
$Signature = ([System.BitConverter]::ToString($Bytes)).Replace("-"," ") # SQLite format 3
if (!($Signature -eq "53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00")) # Magic Bytes
{
Write-Host "[Error] No SQLite3 Database File provided." -ForegroundColor Red
Stop-Transcript
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
# Check if sqlite3.exe exists
if (!(Test-Path "$($SQLite3)"))
{
Write-Host "[Error] sqlite3.exe NOT found." -ForegroundColor Red
Stop-Transcript
$Host.UI.RawUI.WindowTitle = "$DefaultWindowsTitle"
Exit
}
$FileName = [IO.Path]::GetFileName($DatabaseFile)
Write-Output "[Info] Processing Transparency, Consent, and Control Database ($FileName) ..."
# MD5 Hash
$MD5 = (Get-FileHash -LiteralPath "$DatabaseFile" -Algorithm MD5).Hash
Write-Output "[Info] MD5 Hash: $MD5"
# SHA1 Hash
$SHA1 = (Get-FileHash -LiteralPath "$DatabaseFile" -Algorithm SHA1).Hash
Write-Output "[Info] SHA1 Hash: $SHA1"
# SHA256 Hash
$SHA256 = (Get-FileHash -LiteralPath "$DatabaseFile" -Algorithm SHA256).Hash
Write-Output "[Info] SHA256 Hash: $SHA256"
# Input Size
$InputSize = Get-FileSize((Get-Item "$DatabaseFile").Length)
Write-Output "[Info] Total Input Size: $InputSize"
# Count Rows of SQLite3 Database (w/ thousands separators)
[int]$Count = (& $SQLite3 -readonly $DatabaseFile 'SELECT COUNT(*) FROM ACCESS')
$Rows = '{0:N0}' -f $Count
Write-Output "[Info] Total Lines: $Rows"
# Processing TCC.db
New-Item "$OUTPUT_FOLDER\CSV" -ItemType Directory -Force | Out-Null
New-Item "$OUTPUT_FOLDER\XLSX" -ItemType Directory -Force | Out-Null
# ACCESS Table
# CSV
& $SQLite3 -readonly -header -csv $DatabaseFile 'SELECT * FROM ACCESS' | Out-File "$OUTPUT_FOLDER\CSV\Untouched.csv" -Encoding UTF8
# Count columns of 'Untouched.csv' --> Track Changes --> Adjust SQL Query if needed
[int]$Columns = ((Get-Content "$OUTPUT_FOLDER\CSV\Untouched.csv")[1] -split ",").Count
if ($Columns -ne 17)
{
Write-Host "[Info] $Columns columns found (17 columns expected). Please check ACCESS Table." -ForegroundColor Red
}
# macOS 15.3.2 = 17 columns
# XLSX
if (Test-Path "$OUTPUT_FOLDER\CSV\Untouched.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\Untouched.csv" -MaxLines 2)
{
$IMPORT = Import-Csv "$OUTPUT_FOLDER\CSV\Untouched.csv" -Delimiter ","
$IMPORT | Export-Excel -Path "$OUTPUT_FOLDER\XLSX\Untouched.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Access" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
$ColumnNumber = $WorkSheet.Dimension.End.Column
$ColumnName = (Get-ExcelColumnName $ColumnNumber).ColumnName
Set-Format -Address $WorkSheet.Cells["A1:$($ColumnName)1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-Q
$WorkSheet.Cells["A:$($ColumnName)"].Style.HorizontalAlignment="Center"
}
}
}
# SQL Query
$SQL =
"
SELECT
DATETIME(last_modified,'UNIXEPOCH') AS 'Last Modified',
service AS 'Service',
client AS 'Name',
CASE auth_value
WHEN 0 THEN 'Denied'
WHEN 1 THEN 'Unknown'
WHEN 2 THEN 'Allowed'
WHEN 3 THEN 'Limited'
WHEN 4 THEN 'Add Only'
WHEN 5 THEN 'Single Boot Allowed' -- allowed for a unique boot_uuid
END AS 'Auth Value',
CASE auth_reason
WHEN 0 THEN 'Inherited'
WHEN 1 THEN 'Error'
WHEN 2 THEN 'User Consent'
WHEN 3 THEN 'User Set'
WHEN 4 THEN 'System Set'
WHEN 5 THEN 'Service Policy'
WHEN 6 THEN 'MDM Policy'
WHEN 7 THEN 'Override Policy'
WHEN 8 THEN 'Missing Usage String'
WHEN 9 THEN 'Prompt Timeout'
WHEN 10 THEN 'Preflight Unknown'
WHEN 11 THEN 'Entitled'
WHEN 12 THEN 'App Type Policy'
END AS 'Auth Reason',
CASE client_type
WHEN 0 THEN 'Bundle Identifier'
WHEN 1 THEN 'Absolute Path'
END AS 'Client Type'
FROM ACCESS
"
# Execute SQL Query
$Results = @(& $SQLite3 -readonly -separator '**' $DatabaseFile $SQL |
ConvertFrom-String -Delimiter '\u002A\u002A' -PropertyNames "Last Modified","Service","Name","Auth Value","Auth Reason","Client Type")
# CSV
$Output = [Collections.Generic.List[PSObject]]::new()
ForEach($Record in $Results)
{
$CreatedDateTime = $Record | Select-Object -ExpandProperty "Last Modified"
$Line = [PSCustomObject]@{
"Last Modified" = (Get-Date $CreatedDateTime).ToString("yyyy-MM-dd HH:mm:ss")
"Service" = $Record.Service
"Name" = $Record.Name
"Auth Value" = $Record."Auth Value"
"Auth Reason" = $Record."Auth Reason"
"Client Type" = $Record."Client Type"
}
$Output.Add($Line)
}
$Output | Export-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -NoTypeInformation -Encoding UTF8
# XLSX
if (Test-Path "$OUTPUT_FOLDER\CSV\TCC.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -MaxLines 2)
{
$IMPORT = Import-Csv "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8 | Sort-Object { $_."Last Modified" -as [datetime] } -Descending
$IMPORT | Export-Excel -Path "$OUTPUT_FOLDER\XLSX\TCC.xlsx" -NoNumberConversion * -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "TCC" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:F1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-F
$WorkSheet.Cells["A:F"].Style.HorizontalAlignment="Center"
}
}
}
# File Size (XLSX)
if (Test-Path "$OUTPUT_FOLDER\XLSX\TCC.xlsx")
{
$Size = Get-FileSize((Get-Item "$OUTPUT_FOLDER\XLSX\TCC.xlsx").Length)
Write-Output "[Info] File Size (XLSX): $Size"
}
# Create HashTable and import 'TCC-Services.csv'
$Services_HashTable = @{}
if (Test-Path "$SCRIPT_DIR\Config\TCC-Services.csv")
{
if(Test-Csv -Path "$SCRIPT_DIR\Config\TCC-Services.csv" -MaxLines 2)
{
Import-Csv "$SCRIPT_DIR\Config\TCC-Services.csv" -Delimiter "," -Encoding UTF8 | ForEach-Object { $Services_HashTable[$_.Service] = $_.Description,$_.Category }
# Count Ingested Properties
$Count = $Services_HashTable.Count
Write-Output "[Info] Initializing 'TCC-Services.csv' Lookup Table ($Count) ..."
}
}
# Extended
if (Test-Path "$OUTPUT_FOLDER\CSV\TCC.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -MaxLines 2)
{
$Records = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8
# CSV
$Results = [Collections.Generic.List[PSObject]]::new()
ForEach($Record in $Records)
{
# Service
$Service = $Record.Service
# Check if HashTable contains Service
if($Services_HashTable.ContainsKey("$Service"))
{
$Description = $Services_HashTable["$Service"][0]
$Category = $Services_HashTable["$Service"][1]
}
else
{
$Description = "Unknown"
$Category = "Unknown"
}
$Line = [PSCustomObject]@{
"Last Modified" = $Record."Last Modified"
"Service" = $Record.Service
"Description" = $Description
"Category" = $Category
"Name" = $Record."Name"
"Auth Value" = $Record."Auth Value"
"Auth Reason" = $Record."Auth Reason"
"Client Type" = $Record."Client Type"
}
$Results.Add($Line)
}
$Results | Export-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -NoTypeInformation -Encoding UTF8
}
}
# XLSX
if (Test-Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -MaxLines 2)
{
$IMPORT = Import-Csv "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -Delimiter "," -Encoding UTF8 | Sort-Object { $_."Last Modified" -as [datetime] } -Descending
$IMPORT | Export-Excel -Path "$OUTPUT_FOLDER\XLSX\TCC-Extended.xlsx" -NoNumberConversion * -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "TCC" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:H1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-B, D and F-H
$WorkSheet.Cells["A:B"].Style.HorizontalAlignment="Center"
$WorkSheet.Cells["D:D"].Style.HorizontalAlignment="Center"
$WorkSheet.Cells["F:H"].Style.HorizontalAlignment="Center"
}
}
}
# Ckeck for "Unknown" Services
if (Test-Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -MaxLines 2)
{
$Unknown = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -Delimiter "," | Where-Object { $_."Service" -eq "Unknown" } | Measure-Object).Count
if ($Unknown -ge 1)
{
Write-Host "[Info] 'Unknown' Service found. Please check and update 'TCC-Services.csv' database." -ForegroundColor Red
}
}
}
#endregion Analysis
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region Statistics
# Stats
New-Item "$OUTPUT_FOLDER\Stats" -ItemType Directory -Force | Out-Null
# Time Frame
$TCC = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8 | Sort-Object { $_."Last Modified" -as [datetime] }
$LastModified = $TCC | Select-Object "Last Modified"
$StartDateTime = $LastModified | Select-Object -First 1 | Select-Object -ExpandProperty "Last Modified"
$EndDateTime = $LastModified | Select-Object -Last 1 | Select-Object -ExpandProperty "Last Modified"
Write-Output "[Info] Log data from $StartDateTime UTC until $EndDateTime UTC"
# TCC Permissions
$Count = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Select-Object Service | Measure-Object).Count
$Permissions = '{0:N0}' -f $Count
Write-Output "[Info] $Permissions TCC Permissions found"
# User Consent + Allowed
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object { $_."Auth Reason" -eq "User Consent" } | Measure-Object).Count
$Count = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object { $_."Auth Reason" -eq "User Consent" } | Where-Object { $_."Auth Value" -eq "Allowed" } | Measure-Object).Count
Write-Output "[Info] $Count TCC Permissions allowed by User ($Total)"
# User Consent + Denied
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object { $_."Auth Reason" -eq "User Consent" } | Measure-Object).Count
$Count = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object { $_."Auth Reason" -eq "User Consent" } | Where-Object { $_."Auth Value" -eq "Denied" } | Measure-Object).Count
Write-Output "[Info] $Count TCC Permissions denied by User ($Total)"
# Service (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Select-Object Service | Measure-Object).Count
$Count = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Select-Object Service -Unique | Measure-Object).Count
$Service = '{0:N0}' -f $Count
Write-Output "[Info] $Service TCC Services found ($Total)"
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Group-Object Service | Select-Object @{Name='Service'; Expression={ $_.Values[0] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\Service.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Service" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:C1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns B-C
$WorkSheet.Cells["B:C"].Style.HorizontalAlignment="Center"
}
}
# Service / Description (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -Delimiter "," | Select-Object Service | Measure-Object).Count
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -Delimiter "," | Group-Object Service,Description | Select-Object @{Name='Service'; Expression={ $_.Values[0] }},@{Name='Description'; Expression={ $_.Values[1] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\Service-Extended.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Services" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:D1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns C-D
$WorkSheet.Cells["C:D"].Style.HorizontalAlignment="Center"
}
}
# Auth Value (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Select-Object "Auth Value" | Measure-Object).Count
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Group-Object "Auth Value" | Select-Object @{Name='Auth Value'; Expression={ $_.Values[0] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\Auth-Value.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Auth Value" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:C1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-C
$WorkSheet.Cells["A:C"].Style.HorizontalAlignment="Center"
}
}
# Auth Reason (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Select-Object "Auth Reason" | Measure-Object).Count
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Group-Object "Auth Reason" | Select-Object @{Name='Auth Reason'; Expression={ $_.Values[0] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\Auth-Reason.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Auth Reason" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:C1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-C
$WorkSheet.Cells["A:C"].Style.HorizontalAlignment="Center"
}
}
# Auth Reason / Auth Value (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object {$_."Auth Reason" -ne ""}| Measure-Object).Count
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8 | Group-Object "Auth Reason","Auth Value" | Select-Object @{Name='Auth Reason'; Expression={ $_.Values[0] }},@{Name='Auth Value'; Expression={ $_.Values[1] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\AuthReason-AuthValue.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Auth Reason - Auth Value" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:D1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-D
$WorkSheet.Cells["A:D"].Style.HorizontalAlignment="Center"
}
}
# Client Type (Stats)
$Total = (Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Where-Object {$_."Client Type" -ne ""} | Measure-Object).Count
if ($Total -ge "1")
{
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," | Group-Object "Client Type" | Select-Object @{Name='Client Type'; Expression={ $_.Values[0] }},Count,@{Name='PercentUse'; Expression={"{0:p2}" -f ($_.Count / $Total)}} | Sort-Object Count -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\ClientType.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Client Type" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:C1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-C
$WorkSheet.Cells["A:C"].Style.HorizontalAlignment="Center"
}
}
# Exclude Apple System Processes
$NonApple = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC-Extended.csv" -Delimiter "," -Encoding UTF8 | Where-Object { $_."Name" -notmatch "^com.apple.*$" }
$Total = ($NonApple | Measure-Object).Count
$Count = ($NonApple | Sort-Object Name -Unique | Measure-Object).Count
Write-Output "[Info] $Count Third-Party Application(s) found ($Total)"
if ($Total -ge 1)
{
$NonApple | Export-Excel -Path "$OUTPUT_FOLDER\XLSX\TCC-ThirdParty.xlsx" -NoNumberConversion * -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "3rd-Party Apps" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:H1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of columns A-B and D-H
$WorkSheet.Cells["A:B"].Style.HorizontalAlignment="Center"
$WorkSheet.Cells["D:H"].Style.HorizontalAlignment="Center"
}
}
# Permissions Count by Name (Bundle Identifier)
$Stats = Import-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8 | Group-Object "Name" | Select-Object @{Name='Name'; Expression={ $_.Values[0] }},@{Name='Permissions'; Expression={ $_.Count }} | Sort-Object Permissions -Descending
$Stats | Export-Excel -Path "$OUTPUT_FOLDER\Stats\Permissions.xlsx" -FreezeTopRow -BoldTopRow -AutoSize -AutoFilter -WorkSheetname "Permissions" -CellStyleSB {
param($WorkSheet)
# BackgroundColor and FontColor for specific cells of TopRow
Set-Format -Address $WorkSheet.Cells["A1:B1"] -BackgroundColor $BackgroundColor -FontColor $FontColor
# HorizontalAlignment "Center" of column B
$WorkSheet.Cells["B:B"].Style.HorizontalAlignment="Center"
# ConditionalFormatting - Permissions requested by Bundle Identifier >= 5
$LastRow = $WorkSheet.Dimension.End.Row
Add-ConditionalFormatting -Address $WorkSheet.Cells["B2:B$LastRow"] -WorkSheet $WorkSheet -RuleType GreaterThan -ConditionValue 4 -BackgroundColor "Red"
}
# Count of Permissions by Name >= 5
[int]$Count = ($Stats | Where-Object { $_."Permissions" -ge "5" } | Measure-Object).Count
if ($Count -ge 1)
{
Write-Host "[Alert] Suspicious Application(s) detected: >=5 Application Permissions requested ($Count)" -ForegroundColor Yellow
}
# Bundle Identifier
if (Test-Path "$OUTPUT_FOLDER\CSV\TCC.csv")
{
if(Test-Csv -Path "$OUTPUT_FOLDER\CSV\TCC.csv" -MaxLines 2)
{
New-Item "$OUTPUT_FOLDER\TXT" -ItemType Directory -Force | Out-Null
$BundleIds = (Import-Csv "$OUTPUT_FOLDER\CSV\TCC.csv" -Delimiter "," -Encoding UTF8 | Where-Object { $_."Client Type" -eq "Bundle Identifier" } | Where-Object { $_."Name" -notmatch "^com.apple.*$" } | Select-Object "Name" -Unique | Sort-Object "Name")."Name"
$BundleIds | Out-File "$OUTPUT_FOLDER\TXT\BundleIds.txt" -Encoding UTF8
}
}
#endregion Statistics
#############################################################################################################################################################################################
#############################################################################################################################################################################################
#region AppStore
Function Get-iTunesInfo {
# iTunes Search API
# https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/LookupExamples.html
$Total = (Get-Content "$OUTPUT_FOLDER\TXT\BundleIds.txt" | Measure-Object).Count
$BundleIds = Get-Content "$OUTPUT_FOLDER\TXT\BundleIds.txt"
# Internet Connectivity Check
$NetworkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]‘{DCB00C01-570F-4A9B-8D69-199FDBA5723B}’)).IsConnectedToInternet
# Offline
if (!($NetworkListManager -eq "True"))
{
Write-Host "[Error] Your computer is NOT connected to the Internet." -ForegroundColor Red
}
# Online
if ($NetworkListManager -eq "True")
{
# Check if itunes.apple.com is reachable
if ((Test-NetConnection -ComputerName itunes.apple.com -Port 443).TcpTestSucceeded)
{
# Estimated Time (Average: 12 requests per minute)
[int]$TotalSeconds = $Total / 0.2
$TimeSpan = [TimeSpan]::FromSeconds($TotalSeconds)
$EstimatedTime = ('{1} min {2} sec' -f $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds)
Write-Output "[Info] Data Enrichment w/ iTunes Search API ($Total) ..."
Write-Output "[Info] Estimated Time: $EstimatedTime ..."
New-Item "$OUTPUT_FOLDER\iTunes-Lookup\JSON" -ItemType Directory -Force | Out-Null
# https://itunes.apple.com/lookup?bundleId=$BundleId
# Apple Store DE
# https://itunes.apple.com/de/lookup?bundleId=$BundleId
# https://itunes.apple.com/lookup?bundleId=$BundleId&country=de
$Country = "de" # ISO Country Code (ISO 3166-1 alpha-2) - https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
# Österreich: at
# Schweiz: ch
# USA: us
Foreach ($BundleId in $BundleIds)
{
$iTunesUrl = "https://itunes.apple.com/lookup?bundleId=$BundleId&country=$Country"
$Response = Invoke-WebRequest -Uri $iTunesUrl
$Response.Content | & $jq . | Out-File "$OUTPUT_FOLDER\iTunes-Lookup\JSON\$BundleId.json"
Start-Sleep -Seconds 5
}
# CSV
Write-Output "[Info] Creating iTunes Search Report ..."
Get-ChildItem -Recurse -Force -ErrorAction SilentlyContinue "$OUTPUT_FOLDER\iTunes-Lookup\JSON" | Foreach-Object FullName | Foreach-Object {
$FilePath = $_
if ((Get-Item "$FilePath").Length -gt 0kb)
{
$bundleId = $_ | ForEach-Object{($_ -split "\\")[-1]} | ForEach-Object{($_ -split "\.json")[0]}
$trackName = & $jq -r '.results[0].trackName' "$FilePath" 2> $null
if ("$trackName" -eq "null")
{
$trackName = ""
}
$trackId = & $jq -r '.results[0].trackId' "$FilePath" 2> $null
if ("$trackId" -eq "null")
{
$trackId = ""
}
$artistName = & $jq -r '.results[0].artistName' "$FilePath" 2> $null
if ("$artistName" -eq "null")
{
$artistName = ""
}
$artistId = & $jq -r '.results[0].artistId' "$FilePath" 2> $null
if ("$artistId" -eq "null")
{
$artistId = ""
}
$description = & $jq -r '.results[0].description' "$FilePath" 2> $null
if ("$description" -eq "null")
{
$description = ""
}
$sellerUrl = & $jq -r '.results[0].sellerUrl' "$FilePath" 2> $null
if ("$sellerUrl" -eq "null")
{
$sellerUrl = ""
}
$trackViewUrl = & $jq -r '.results[0].trackViewUrl' "$FilePath" 2> $null
if ("$trackViewUrl" -eq "null")
{
$trackViewUrl = ""
}
$formattedPrice = & $jq -r '.results[0].formattedPrice' "$FilePath" 2> $null
if ("$formattedPrice" -eq "null")
{
$formattedPrice = ""
}
$currency = & $jq -r '.results[0].currency' "$FilePath" 2> $null
if ("$currency" -eq "null")
{
$currency = ""
}
$primaryGenreName = & $jq -r '.results[0].primaryGenreName' "$FilePath" 2> $null
if ("$primaryGenreName" -eq "null")
{
$primaryGenreName = ""
}
$primaryGenreId = & $jq -r '.results[0].primaryGenreId' "$FilePath" 2> $null
if ("$primaryGenreId" -eq "null")
{
$primaryGenreId = ""
}
$genres = & $jq -r '.results[0].genres[]?' "$FilePath" 2> $null
if ("$genres" -eq "null")
{
$genres = ""
}
$genreIds = & $jq -r '.results[0].genreIds[]?' "$FilePath" 2> $null
if ("$genreIds" -eq "null")
{
$genreIds = ""