-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
WinEDB_Browser.ps1
6119 lines (5893 loc) · 563 KB
/
WinEDB_Browser.ps1
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
<#
--------------------------------------------------------------------------------
Generated by: Costas Katsavounidis
https://kacos2000.github.io/WinEDB/
https://github.com/kacos2000/WinEDB
--------------------------------------------------------------------------------
#>
function Main {
<#
.SYNOPSIS
The Main function starts the project application.
.PARAMETER Commandline
$Commandline contains the complete argument string passed to the script packager executable.
.NOTES
Use this function to initialize your script and to call GUI forms.
.NOTES
To get the console output in the Packager (Forms Engine) use:
$ConsoleOutput (Type: System.Collections.ArrayList)
#>
Param ([String]$Commandline)
if((Show-MainForm_psf) -eq 'OK')
{
}
$script:ExitCode = 0 #Set the exit code for the Packager
}
#endregion Source: Startup.pss
#region Source: MainForm.psf
function Show-MainForm_psf
{
#----------------------------------------------
#region Import the Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load('System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][reflection.assembly]::Load('System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
[void][reflection.assembly]::Load('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
#endregion Import Assemblies
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
[System.Windows.Forms.Application]::EnableVisualStyles()
$WinEDBBrowser = New-Object 'System.Windows.Forms.Form'
$splitcontainer1 = New-Object 'System.Windows.Forms.SplitContainer'
$menustrip1 = New-Object 'System.Windows.Forms.MenuStrip'
$toolstrip1 = New-Object 'System.Windows.Forms.ToolStrip'
$fileToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$Open = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolStripSeparator = New-Object 'System.Windows.Forms.ToolStripSeparator'
$exitToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$About = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$openfiledialog1 = New-Object 'System.Windows.Forms.OpenFileDialog'
$ExportDLL = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator1 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$datagridview1 = New-Object 'System.Windows.Forms.DataGridView'
$treeview1 = New-Object 'System.Windows.Forms.TreeView'
$splitcontainer2 = New-Object 'System.Windows.Forms.SplitContainer'
$splitcontainer3 = New-Object 'System.Windows.Forms.SplitContainer'
$datagridview2 = New-Object 'System.Windows.Forms.DataGridView'
$contextmenustrip1 = New-Object 'System.Windows.Forms.ContextMenuStrip'
$Copy1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$Copy1Fullpath = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator9 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Expand1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$Collapse1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator10 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$ExpandAll1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$CollapseAll1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator11 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Exit1 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$contextmenustrip3 = New-Object 'System.Windows.Forms.ContextMenuStrip'
$Copy3 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$CopyAll3 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator4 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Print3 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator5 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Exit3 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$contextmenustrip2 = New-Object 'System.Windows.Forms.ContextMenuStrip'
$Copy2 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$CopyAll2 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator2 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Print2 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$toolstripseparator3 = New-Object 'System.Windows.Forms.ToolStripSeparator'
$Exit2 = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$imagelist1 = New-Object 'System.Windows.Forms.ImageList'
$imagelist2 = New-Object 'System.Windows.Forms.ImageList'
$Status = New-Object 'System.Windows.Forms.ToolStripLabel'
$progressbar1 = New-Object 'System.Windows.Forms.ToolStripProgressBar'
$ThumbnailCacheId_find = New-Object 'System.Windows.Forms.ToolStripTextBox'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion Generated Form Objects
#----------------------------------------------
# User Generated Script
#----------------------------------------------
function Get-DPI
{
[OutputType([single])]
param
(
[IntPtr]$Handle = [IntPtr]::Zero
)
$g = [System.Drawing.Graphics]::FromHwnd($Handle)
$dpi = $g.DpiX
$g.Dispose()
return $dpi
}
function Enable-DataGridViewDoubleBuffer
{
param ([Parameter(Mandatory = $true)]
[System.Windows.Forms.DataGridView]$grid,
[switch]$Disable)
$type = $grid.GetType();
$propInfo = $type.GetProperty("DoubleBuffered", ('Instance', 'NonPublic'))
$propInfo.SetValue($grid, $Disable -eq $false, $null)
}
$WinEDBBrowser_Load={
Enable-DataGridViewDoubleBuffer $datagridview1
Enable-DataGridViewDoubleBuffer $datagridview2
$splitcontainer1.AutoScroll = $true
$splitcontainer2.AutoScroll = $true
$splitcontainer3.AutoScroll = $true
# Enable $datagridview Resizing
$datagridview1.ColumnHeadersHeightSizeMode = 'AutoSize'
$datagridview1.RowHeadersWidthSizeMode = 'AutoSizeToAllHeaders'
$datagridview1.AutoSizeColumnsMode = 'AllCells'
$datagridview2.ColumnHeadersHeightSizeMode = 'AutoSize'
$datagridview2.RowHeadersWidthSizeMode = 'AutoSizeToAllHeaders'
$datagridview2.AutoSizeColumnsMode = 'AllCells'
if ((Get-DPI $WinEDBBrowser.Handle) -gt 96)
{
$treeview1.ImageList = $imagelist1 # HighDPI (24*24)
$toolstrip1.ImageScalingSize = New-Object System.Drawing.Size (24, 24)
$menustrip1.ImageScalingSize = New-Object System.Drawing.Size (24, 24)
# $richtextbox1.Font = New-Object Drawing.Font($oldFont.FontFamily, 8, [Drawing.FontStyle]::Regular)
for ($i = 1; $i -lt 2; $i++)
{
(Get-Variable contextmenustrip$i -ValueOnly).ImageScalingSize = New-Object System.Drawing.Size (24, 24)
}
}
else
{
$treeview1.ImageList = $imagelist2 # Regular (16 * 16)
$toolstrip1.ImageScalingSize = New-Object System.Drawing.Size (16, 16)
$menustrip1.ImageScalingSize = New-Object System.Drawing.Size (16, 16)
# $richtextbox1.Font = New-Object Drawing.Font($oldFont.FontFamily, 8, [Drawing.FontStyle]::Regular)
for ($i = 1; $i -lt 2; $i++)
{
(Get-Variable contextmenustrip$i -ValueOnly).ImageScalingSize = New-Object System.Drawing.Size (16, 16)
}
}
# Get current user access level & check if user is Administrator
# $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
# $IsAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=net-7.0
# https://learn.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
$FileAttributesEnum = [Ordered]@{
'1' = 'ReadOnly'
'2' = 'Hidden'
'4' = 'System'
'16' = 'Directory'
'32' = 'Archive'
'64' = 'Device'
'128' = 'Normal'
'256' = 'Temporary'
'512' = 'Sparse_File'
'1024' = 'Reparse_Point'
'2048' = 'Compressed'
'4096' = 'Offline'
'8192' = 'Not_Content_Indexed'
'16384' = 'Encrypted'
'32768' = 'Integrity_Stream'
'65536' = 'Virtual'
'131072' = 'No_Scrub_Data'
'524288' = 'Pinned'
'262144' = 'Recall_On_Open'
'1048576' = 'Unpinned'
'4194304' = 'Recall_On_DataAccess'
'2147483648' = 'TxF_flag'
}
$TablesToKeep = [System.Array]@(
'SystemIndex_Gthr'
'SystemIndex_PropertyStore'
)
$MSysTypes = [System.Collections.Hashtable]@{
'1' = 'Table'
'2' = 'Column'
'3' = 'Index'
'4' = 'Long Value'
'5' = 'Call Back'
}
# Columns set as Binary (8-bytes) that are actually Filetime
$dates = @(
'Date'
'Time'
<#'DateModified'
'DateCreated'
'DateAccessed'
'DateAcquired'
'DateArchived'
'DateCompleted'
'DateImported'
'DatePrinted'
'DateSaved'
'ItemDate'
'DateVisited'
'DateEncoded'
'DateReceived'
'DateSent'
'DateTaken'
'GatherTime'
'DateLastUsed'
'StartDate'
'EndTime'
'StartTime'
'ReminderTime'#>
'Anniversary'
'Birthday'
<#'DueDate'
'EndDate'
'GPS_Date'
'OriginalBroadcastDate'
'RecordingTime'
'CreationTime'
'ExpireDate'#>
'Modified'
'IssueDate'
'Expires'
<# 'ExpirationTime'
'LastChangeTime'
'DownloadDateExpire'#>
)
$DatesAsInt64 = @(
'Time'
<# 'AccessedTime'
'CreationTime'
'ExpiryTime'
'ModifiedTime'
'PostCheckTime'
'SyncTime'#>
)
$unicodeAsLongBinary = @(
'LocaleName'
'Address'
'Name'
'Author'
'Addresses'
'Resources'
'Category'
'ItemParticipants'
'AppIdList'
'DaysActive'
'HoursActive'
'Children'
'ConnectedServiceIdentities'
'DataSuppliers'
'PhoneNumbers'
'EmailAddresses'
'Hobbies'
'IMAddress'
'Contributor'
'Importance'
'Kind'
'DlnaProfileID'
'Producer'
'Artist'
'Conductor'
'Director'
'Event'
'Genre'
'Keywords'
'Writer'
'Person'
'Location'
'Album'
'TagViewAggregate'
'QueryPropertyHits'
'EncryptionOwners'
'StorageProviderShareStatuses'
'Supplemental_Tag'
'Message_ToName'
'IdBlob'
)
# Timespans in ms
$timespans = @(
'ActivityHistory_ActiveDuration'
'Document_TotalEditingTime'
'Media_Duration'
)
# Columns that are Sizes (uint64) but set as Binary (8-bytes)
$sizes = @(
'-System_Size'
'TransferSize'
)
# Create match strings
$szlist = $sizes -join '|'
$tlist = $timespans -join '|'
$dlist = $dates -join '|'
$d2list = $DatesAsInt64 -join '|'
$ulist = $unicodeAsLongBinary -join '|'
function Show-ErrorMessage
{
param
(
[Parameter(Mandatory = $true)]
[string]$ErrorMessage
)
[void][System.Windows.Forms.MessageBox]::Show($WinEDBBrowser, "$($ErrorMessage)", "WinEDB Browser", "OK", "Error")
}
function Show-InfoMessage
{
param
(
[Parameter(Mandatory = $true)]
[string]$InfoMessage
)
[void][System.Windows.Forms.MessageBox]::Show($WinEDBBrowser, "$($InfoMessage)", "WinEDB Browser", "OK", "Information")
}
function Show-WarningMessage
{
param
(
[Parameter(Mandatory = $true)]
[string]$WarningMessage
)
[void][System.Windows.Forms.MessageBox]::Show($WinEDBBrowser, "$($WarningMessage)", "WinEDB Browser", "OK", "Warning")
}
function Get-Nodes
{
param
(
[Parameter(Mandatory = $true)]
$nodes
)
foreach ($node in $nodes)
{
[System.Windows.Forms.Application]::DoEvents()
$node
Get-Nodes -nodes $node.Nodes
}
}
function Get-NodesText
{
param
(
[Parameter(Mandatory = $true)]
[System.Windows.Forms.TreeNode[]]$nodes,
[Parameter(Mandatory = $true)]
[String]$String
)
foreach ($node in $nodes.Nodes)
{
[System.Windows.Forms.Application]::DoEvents()
if ($node.Text -eq ("$($String)"))
{
return $node
break
}
}
}
function Get-TextFromBytes
{
[OutputType([string])]
param
(
[Parameter(Mandatory = $true)]
[Byte[]]$RawBytes
)
if ($rawbytes.length -eq 0) { return $null }
elseif($rawbytes.length -ge 4)
{
# text strings with bom
switch ($rawbytes[0])
{
0xFF {
if ($rawbytes[1] -eq 0xFE) { [System.Text.Encoding]::Unicode.GetString($rawbytes); break } # unicode
}
0xEF {
if ($rawbytes[1] -eq 0xBB -and $rawbytes[2] -eq 0xBF) { [System.Text.Encoding]::UTF8.GetString($rawbytes); break } # utf8
}
0xFE {
if ($rawbytes[1] -eq 0xFF) { [System.Text.Encoding]::BigEndianUnicode.GetString($rawbytes); break } # BE unicode
}
0x00 {
if ($rawbytes[1] -eq 0x00 -and $rawbytes[2] -eq 0xFE -and $rawbytes[3] -eq 0xFF) { [System.Text.Encoding]::UTF32.GetString($rawbytes); break } # utf32
}
0x2B {
if ($rawbytes[0] -eq 0x2B -and $rawbytes[1] -eq 0x2F -and $rawbytes[2] -eq 0x76) { [System.Text.Encoding]::UTF7.GetString($rawbytes); break } #utf7
}
{ $_ -in (0x20 .. 0x7F) }{
if ($rawbytes[1] -eq 0x00 -and $rawbytes[2] -in (0x20 .. 0x7F) -and $rawbytes[3] -eq 0x00) { [System.Text.Encoding]::Unicode.GetString($rawbytes); break } # unicode
elseif ($rawbytes[1] -in (0x20 .. 0x7F) -and $rawbytes[2] -in (0x20 .. 0x7F) -and $rawbytes[3] -in (0x20 .. 0x7F)) { [System.Text.Encoding]::UTF8.GetString($rawbytes); break } # ASCII/UTF8
else { [System.BitConverter]::ToString($rawbytes).Replace('-', '') }
}
default
{
[System.BitConverter]::ToString($rawbytes).Replace('-', '')
}
}
}
else
{
if ($rawbytes[0] -in (0x20 .. 0x7F) -and $rawbytes[1] -eq 0x00) # unicode
{ [System.Text.Encoding]::Unicode.GetString($rawbytes) }
elseif ($rawbytes[0] -in (0x20 .. 0x7F) -and $rawbytes[1] -in (0x20 .. 0x7F)) # ASCII
{ [System.Text.Encoding]::UTF8.GetString($rawbytes) } # Should play well with ASCII too
else { [System.BitConverter]::ToString($rawbytes).Replace('-', '') } # Just get the Hex String
}
} # End of Get-TextFromBytes
function GetText-fromHex
{
param
(
[Parameter(Mandatory = $true)]
[AllowEmptyString()]
[System.String]$Hex
)
if ([System.String]::IsNullOrEmpty($Hex)) { return $null }
try
{
# Check if string is valid Hex
[System.Text.RegularExpressions.Regex]$regex = '^[a-fA-F0-9]+$' #'\p{XDigit}'
if ($regex.Matches($Hex).Success -and $regex.Matches($Hex).length -eq $Hex.Length)
{
# Convert String to Byte Array
$bytes = ($Hex -Split '(..)' -ne '').foreach{ [int]"0x$($_)" }
# Try to Convert the Byte Array to Text
$text = Get-TextFromBytes -RawBytes $bytes
# Check if the returned Text is Valid ASCII
[regex]$regex2 = '^[\x20-\x7F]+$'
if ($regex2.Matches($text).Success -and $regex2.Matches($text).length -eq $text.Length)
{ $text }
else { $null }
}
else { $null }
}
catch { $null }
} # End of GetText-fromHex
function Get-SafeFilename
{
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
[object]$Path
)
process
{
$pattern = "[" + (([System.IO.Path]::GetInvalidFileNameChars().foreach{ "\x" + ([int]$_).ToString('X2') }) -join '') + "]+"
[System.Text.RegularExpressions.Regex]::Replace($Path, $pattern1,'')
}
} # Get-SafeFilename
$Open_Click={
$openfiledialog1.Filter = "Windows.edb (Windows.edb)|Windows.edb*|All files (*.*)|*.*"
# "ESE Files (*.edb;*.dat)|*.edb;*.dat|All File (*.*)|*.*"
$openfiledialog1.Title = "Please select a Windows.EDB file"
if ($openfiledialog1.ShowDialog() -eq 'OK')
{
# Clear stuff
$WinEDBBrowser.Text = "WinEDB Browser"
$treeview1.Nodes.Clear()
$datagridview1.DataSource = $null
$datagridview2.DataSource = $null
$script:dBRecords = $null
$script:dBData = $null
$script:schema = $null
$ThumbnailCacheId_find.Text = $null
$ThumbnailCacheId_find.Enabled = $false
$script:thumbfieldname = $null
$progressbar1.Visible = $false
[GC]::Collect()
# Get File
$script:filename = $openfiledialog1.FileName
$fname = Split-Path -path $filename -Leaf
$WinEDBBrowser.Text = "WinEDB Browser - $($fname)"
if ($treeview1.Nodes) { $treeview1.Nodes.Clear() }
else { }
$file = @([PSCustomObject][Ordered]@{
'FileName' = $fname
'CreationTimeUtc' = [system.IO.File]::GetCreationTimeUtc($filename).ToString("dd/MM/yyyy HH:mm:ss.fffffff")
'LastAccessTimeUtc' = [system.IO.File]::GetLastAccessTimeUtc($filename).ToString("dd/MM/yyyy HH:mm:ss.fffffff")
'LastWriteTimeUtc' = [system.IO.File]::GetLastWriteTimeUtc($filename).ToString("dd/MM/yyyy HH:mm:ss.fffffff")
'Attributes' = [system.IO.File]::GetAttributes($filename)
'Size' = [System.IO.FileInfo]::new($filename).Length
})
$Status.Text = "Selected File: $($File) "
$treeview1.BeginUpdate()
$RootNode = $treeview1.Nodes.Add($filename, $filename)
$RootNode.ImageIndex = 4
$RootNode.SelectedImageIndex = 4
$null = $RootNode.Nodes.Add('FileName', "Filename: $($file.Filename)")
$null = $RootNode.Nodes.Add('CreationTimeUtc', "CreationTimeUtc: $($file.CreationTimeUtc)")
$null = $RootNode.Nodes.Add('LastAccessTimeUtc', "LastAccessTimeUtc: $($file.LastAccessTimeUtc)")
$null = $RootNode.Nodes.Add('LastWriteTimeUtc', "LastWriteTimeUtc: $($file.LastWriteTimeUtc)")
$null = $RootNode.Nodes.Add('Attributes', "Attributes: $($file.Attributes)")
$null = $RootNode.Nodes.Add('Size', "Size: $($file.Size)")
$treeview1.EndUpdate()
if ($file.size -gt 0)
{
Load-ManagedInterop
Read-EDB -File $filename
}
}
else
{
$WinEDBBrowser.Text = "WinEDB Browser"
[System.Console]::Beep(500, 150)
}
}
# ColumnTypes
# https://learn.microsoft.com/en-us/windows/win32/extensible-storage-engine/jet-coltyp
$ColumnTypes = [System.Collections.Hashtable]@{
'0' = 'Nil' # An invalid column type
'1' = 'Bit' # A column type that allows three values: True, False, or NULL
'2' = 'Unsigned Byte' # A 1-byte unsigned integer
'3' = 'Short' # A 2-byte signed integer
'4' = 'Long' # A 4-byte signed integer
'5' = 'Currency' # An 8-byte signed integer
'6' = 'IEEE Single' # A single-precision (4-byte) floating point number.
'7' = 'IEEE Double' # A double-precision (8-byte) floating point number
'8' = 'DateTime' # fractional days since the year 1900
'9' = 'Binary' # A fixed or variable length, raw binary column that can be up to 255 bytes long
'10' = 'Text' # A fixed or variable length text column that can be up to 255 ASCII characters in length or 127 Unicode characters in length.
'11' = 'Long Binary' # A fixed or variable length, raw binary column that can be up to 2147483647 bytes long
'12' = 'Long Text' # A fixed or variable length, text column that can be up to 2147483647 ASCII characters or 1073741823 Unicode long
'13' = 'SLV' # obsolete
'14' = 'UnsignedLong' # A 4-byte unsigned integer (RetrieveColumnAsUInt32))
'15' = 'Long Long' # An 8-byte signed integer
'16' = 'GUID' # A fixed length 16 byte binary column that natively represents the GUID data type (RetrieveColumnAsGuid)
'17' = 'Unsigned Short' # A 2-byte unsigned integer (RetrieveColumnAsUInt16)
'18' = 'Max' # A constant describing the maximum (that is, one beyond the largest valid) column type supported by the engine
}
function Get-EDBcolumnData
{
param
(
[Parameter(Mandatory = $true)]
$Session,
[Parameter(Mandatory = $true)]
$Table,
[Parameter(Mandatory = $true)]
$Column
)
$Binarydata = [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumn($Session, $Table, $column.Columnid, [Microsoft.Isam.Esent.Interop.RetrieveColumnGrbit]::RetrieveIgnoreDefault, $null)
$data = if ($null -ne $Binarydata)
{
switch ($column.Coltyp)
{
'Long' { [Bitconverter]::ToInt32($Binarydata, 0); break }
'17' { [Bitconverter]::ToUInt16($Binarydata, 0); break }
'14' { [Bitconverter]::ToUInt32($Binarydata, 0); break }
'15' { [Bitconverter]::ToInt64($Binarydata, 0); break }
'Bit'{ [Bitconverter]::ToBoolean($Binarydata, 0); break }
'Short'{ [Bitconverter]::ToInt16($Binarydata, 0); break }
'UnsignedByte'{ $Binarydata; break }
'LongText'{
if ($null -ne $column.Cp)
{
[System.Text.Encoding]::GetEncoding("$($column.Cp)").GetString($Binarydata); break
}
else { [System.Text.Encoding]::Unicode.GetString($Binarydata); break }
}
'Binary'{
switch ($column.name)
{
{ $_ -eq 'LastModified' -and $Column.MaxLength -eq 8 }
{
try { [datetime]::FromFileTimeUtc("0x$([System.BitConverter]::ToString($Binarydata).Replace('-', ''))").ToString("dd/MM/yyyy HH:mm:ss.fffffff"); break } # Big Endian
catch [System.Management.Automation.MethodInvocationException] { }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
{ $_ -match $szlist }
{
try { [Bitconverter]::ToUInt64($Binarydata, 0); break }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
{ $_ -match $dlist -and $_ -match '^[\d]{2}' -and $Column.MaxLength -eq 8 }
{
try { [datetime]::FromFileTimeUtc([Bitconverter]::ToUInt64($Binarydata, 0)).ToString("dd/MM/yyyy HH:mm:ss.fffffff"); break } # Little Endian
catch [System.Management.Automation.MethodInvocationException] { }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
{ $_ -match $dlist -and $_ -notmatch '^[\d]{2}' -and $Column.MaxLength -eq 8 }{
try { [datetime]::FromFileTimeUtc("0x$([System.BitConverter]::ToString($Binarydata).Replace('-', ''))").ToString("dd/MM/yyyy HH:mm:ss.fffffff"); break } # Big Endian
catch [System.Management.Automation.MethodInvocationException] { }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
{ $_ -match $tlist }
{
try
{
$dur = [Bitconverter]::ToUInt64($Binarydata, 0)
"$([timespan]::FromTicks($dur).ToString('dd\:hh\:mm\:ss')) ($($dur))"
break
}
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
{ $_ -match 'ActivityHistory_Importance' }
{
try { [Bitconverter]::ToUInt64($Binarydata, 0) }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', '') }
}
{ $_ -match 'FileName1' }{ [System.Text.Encoding]::Unicode.GetString($Binarydata); break }
default { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
}
'LongBinary'{
# Check the Name Column
if ($column.name -match $ulist -and $column.name -match '^[\d]{2}')
{
try { [System.Text.Encoding]::Unicode.GetString($Binarydata) }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', '') }
break
}
elseif ($column.name -match $ulist -and $_ -notmatch '^[\d]{2}')
{
try { [System.Text.Encoding]::UTF8.GetString($Binarydata) }
catch { [System.BitConverter]::ToString($Binarydata).Replace('-', '') }
break
}
else { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
'Text'{ [System.Text.Encoding]::GetEncoding("$($column.Cp)").GetString($Binarydata); break }
'DateTime'{
try { [datetime]::FromFileTimeUtc([Bitconverter]::ToUInt64($Binarydata, 0)).ToString("dd/MM/yyyy HH:mm:ss.fffffff"); break }
catch [System.Management.Automation.MethodInvocationException] { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
catch { [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsDateTime($Session, $Table, $column.Columnid, [Microsoft.Isam.Esent.Interop.RetrieveColumnGrbit]::None); break }
}
'Currency'{ [Bitconverter]::ToInt64($Binarydata, 0); break }
'IEEESingle'{ [Bitconverter]::ToSingle($Binarydata, 0); break }
'IEEEDouble'{ [Bitconverter]::ToDouble($Binarydata, 0); break }
'16' { [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsGuid($Session, $Table, $column.Columnid, [Microsoft.Isam.Esent.Interop.RetrieveColumnGrbit]::None); break }
'Guid'{ [Microsoft.Isam.Esent.Interop.Api]::RetrieveColumnAsGuid($Session, $Table, $column.Columnid, [Microsoft.Isam.Esent.Interop.RetrieveColumnGrbit]::None); break }
default { [System.BitConverter]::ToString($Binarydata).Replace('-', ''); break }
}
}
else { $null }
return $data
} # End Get-EDBcolumnData
function Read-EDB
{
param
(
[Parameter(Mandatory = $true)]
$File
)
$stopWatch = New-Object -TypeName System.Diagnostics.Stopwatch
$stopWatch.Start()
# Set Folder for output
$snow = Get-Date -Format "ddMMMyyyy-HHmmss"
# EseDB
$SourcedbFile = $File
$outfile = "$($env:TEMP)\$([IO.Path]::GetRandomFileName())"
# copy/overwrite db to system temp just in case
$Status.Text = "Copying $($File) dB to $($outfile)"
try { [System.IO.File]::Copy($SourcedbFile, $outfile, $true) }
catch{ invoke-expression ("esentutl.exe /y /vss " + "$($SourcedbFile)" + " /d " + $($outfile) + " /o") }
if (Test-Path $outfile -IsValid)
{
# Check if file Attribute is Read-Only
if ([System.IO.File]::GetAttributes($outfile).HasFlag([System.IO.FileAttributes]::ReadOnly))
{
# Set dB Attributes to Normal
[System.IO.File]::SetAttributes($outfile, [System.IO.FileAttributes]::Normal)
}
$dbfile = $outfile
$Status.Text = "Finished copying the dB to $($env:TEMP)"
}
else
{
$stopWatch.Stop()
$stopWatch.Reset()
Show-ErrorMessage -ErrorMessage "Error copying the dB to $($env:TEMP)`n $(($Error[0].Exception.InnerException | Out-String))"
return
}
[System.Int64]$FileSize = -1
Try
{
# JET_DbInfo: Returns the filesize of the database, in pages (Int32)
[Microsoft.Isam.Esent.Interop.Api]::JetGetDatabaseFileInfo($dbfile, [ref]$FileSize, [Microsoft.Isam.Esent.Interop.JET_DbInfo]::Filesize)
$Status.Text = "Database size: $($FileSize.ToString('N0'))"
if ($FileSize -le 0)
{
$stopWatch.Stop()
$stopWatch.Reset()
Show-ErrorMessage -ErrorMessage "Database size: $($FileSize.ToString('N0')) - Nothing to read :-/"
return
}
}
Catch [System.Management.Automation.RuntimeException] # non-fatal, so we can continue
{
# Out-Host -InputObject $Error[0].Exception.GetType().FullName
Show-WarningMessage -WarningMessage "$(($Error[0].Exception.InnerException | Out-String))"
}
# Get the Page Size
[System.Int32]$PageSize = -1
[Microsoft.Isam.Esent.Interop.Api]::JetGetDatabaseFileInfo($dbfile, [ref]$PageSize, [Microsoft.Isam.Esent.Interop.JET_DbInfo]::PageSize)
# New Instance
$Instance = [Microsoft.Isam.Esent.Interop.JET_INSTANCE]::Nil
# New Session
$Session = [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil
$syspath = "$($env:TEMP)\$([IO.Path]::GetRandomFileName())"
$logpath = "$($env:TEMP)\$([IO.Path]::GetRandomFileName())"
# Set Instance Parameters
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::DatabasePageSize, $PageSize, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::Recovery, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableIndexChecking, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableIndexCleanup, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableOnlineDefrag, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::CreatePathIfNotExist, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EventSourceKey, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::DisablePerfmon, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::CircularLog, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::SystemPath, 0, $syspath)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::LogFilePath, 0, $logpath)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::OutstandingIOMax, [int]32768, $null)
# Create Instance
[Microsoft.Isam.Esent.Interop.Api]::JetCreateInstance2([ref]$Instance, 'WinEDB[0]', 'WinEDB[0]', [Microsoft.Isam.Esent.Interop.CreateInstanceGrbit]::None)
# Init Instance
try
{
$null = [Microsoft.Isam.Esent.Interop.Api]::JetInit2([ref]$Instance, [Microsoft.Isam.Esent.Interop.InitGrbit]::None)
}
catch
{
Show-ErrorMessage -ErrorMessage "Could not Create Instance:`n $(($Error[0].Exception.InnerException | Out-String))"
# Delete temp copy of the dB
[System.IO.File]::Delete($dbfile)
return
}
# script Block to use later for export to CSV jobs
$SaveRowData = {
param
($rPath,$RowRecords)
# Just in case one deletes the Output folder while WinEdb is running
$outpath = Split-Path $rPath -Parent
$filename = Split-Path $rPath -Leaf
if (!(Test-Path -Path $outpath))
{
try { $null = [System.IO.Directory]::CreateDirectory("$($outpath)") }
catch { $rPath = "$($env:TEMP)\$filename" }
}
# Get all the Headers
$Headers = [System.Collections.ArrayList]@{ }
$RowRecords.ForEach{ $_.psobject.properties.Name.foreach{ if (!$Headers.Contains($_)) { $null = $Headers.Add($_) } } }
$Headers.Sort()
# Export the Headers (for debugging/comparisons)
# $Headers | Out-File -FilePath "$($rPath.TrimEnd('Records.csv'))Headers.txt" -Encoding utf8
# Create a blank CSV with only headers
$Headers -join '|' | Add-Content -Path $rPath
# Add the Records to CSV
$RowRecords | Export-Csv -Path $rPath -Delimiter '|' -Encoding UTF8 -NoTypeInformation -Append -Force
$Headers.Clear()
$RowRecords.Clear()
$outdata.Clear()
[System.GC]::Collect()
}
# Begin Session
[Microsoft.Isam.Esent.Interop.Api]::JetBeginSession($Instance, [ref]$Session, [System.String]::Empty, [System.String]::Empty)
try
{
$DatabaseId = [Microsoft.Isam.Esent.Interop.JET_DBID]::Nil
$Status.Text = "Attaching DB... "
# Attach dB
[Microsoft.Isam.Esent.Interop.Api]::JetAttachDatabase($Session, $dbfile, [Microsoft.Isam.Esent.Interop.AttachDatabaseGrbit]::None)
# Check the instance
[Microsoft.Isam.Esent.Interop.JET_INSTANCE_INFO[]]$instances = $null
[System.Int32]$inr = 0
[Microsoft.Isam.Esent.Interop.Api]::JetGetInstanceInfo([ref]$inr, [ref]$instances)
$Status.Text = "Nr of Instances: $($inr) -> $($instances.szInstanceName -join '. ')"
}
catch [System.Management.Automation.MethodException]{
$Status.Text = "$($Error[0].Exception.InnerException | Out-String) - [1] Will attempt to repair with Esentutl"
[Microsoft.Isam.Esent.Interop.Api]::JetTerm2($Instance, [Microsoft.Isam.Esent.Interop.TermGrbit]::Complete)
try
{
# Commands
$ese_repair = "esentutl.exe /p " + "$($dbfile)" + " /g /o"
$ese_defrag = "esentutl.exe /d " + "$($dbfile)" + " /o"
# repair
$Status.Text = "[1] Attempting repair of $($dbfile) with Esentutl /p"
invoke-expression -Command $ese_repair -OutVariable Esentrepairlog
# defragment
$Status.Text = "[1] Attempting defragmentation of $($dbfile) with Esentutl /d"
invoke-expression -Command $ese_defrag -OutVariable Esentdefraglog
# New Session
$Session = [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil
$syspath = "$($env:TEMP)\$([IO.Path]::GetRandomFileName())"
$logpath = "$($env:TEMP)\$([IO.Path]::GetRandomFileName())"
# Set Instance Parameters
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::DatabasePageSize, $PageSize, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::Recovery, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableIndexChecking, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableIndexCleanup, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EnableOnlineDefrag, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::CreatePathIfNotExist, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::EventSourceKey, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::DisablePerfmon, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::CircularLog, [int]$true, $null)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::SystemPath, 0, $syspath)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::LogFilePath, 0, $logpath)
$null = [Microsoft.Isam.Esent.Interop.Api]::JetSetSystemParameter($Instance, [Microsoft.Isam.Esent.Interop.JET_SESID]::Nil, [Microsoft.Isam.Esent.Interop.JET_param]::OutstandingIOMax, [int]32768, $null)
# Create Instance
[Microsoft.Isam.Esent.Interop.Api]::JetCreateInstance2([ref]$Instance, 'WinEDB[1]', 'WinEDB[1]', [Microsoft.Isam.Esent.Interop.CreateInstanceGrbit]::None)
# Init Instance
$null = [Microsoft.Isam.Esent.Interop.Api]::JetInit2([ref]$Instance, [Microsoft.Isam.Esent.Interop.InitGrbit]::None)
# Begin Session
[Microsoft.Isam.Esent.Interop.Api]::JetBeginSession($Instance, [ref]$Session, [System.String]::Empty, [System.String]::Empty)
# Re-Attach dB
[Microsoft.Isam.Esent.Interop.Api]::JetAttachDatabase($Session, $dbfile, [Microsoft.Isam.Esent.Interop.AttachDatabaseGrbit]::None)
}
catch
{
$stopWatch.Stop()
$stopWatch.Reset()
$Status.Text = $null
Show-ErrorMessage -ErrorMessage "[2] Could not Attach the temp copy of $($SourcedbFile):`n $(($Error[0].Exception.InnerException | Out-String))`nTry repairing it with 'esentutl.exe'"
[Microsoft.Isam.Esent.Interop.Api]::JetEndSession($Session, [Microsoft.Isam.Esent.Interop.EndSessionGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetTerm2($Instance, [Microsoft.Isam.Esent.Interop.TermGrbit]::None)
# Delete temp copy of the dB
[System.IO.File]::Delete($dbfile)
return
}
}
catch
{
$stopWatch.Stop()
$stopWatch.Reset()
$Status.Text = $null
Show-ErrorMessage -ErrorMessage "Could not Attach the temp dB $($dbfile):`n $(($Error[0].Exception.InnerException | Out-String))"
[Microsoft.Isam.Esent.Interop.Api]::JetEndSession($Session, [Microsoft.Isam.Esent.Interop.EndSessionGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetTerm2($Instance, [Microsoft.Isam.Esent.Interop.TermGrbit]::None)
# Delete temp copy of the dB
[System.IO.File]::Delete($dbfile)
return
}
# Open dB
$Status.Text = "Opening DB... "
try
{
[Microsoft.Isam.Esent.Interop.Api]::JetOpenDatabase($Session, $dbfile, [System.String]::Empty, [ref]$DatabaseId, [Microsoft.Isam.Esent.Interop.OpenDatabaseGrbit]::ReadOnly)
}
catch
{
$stopWatch.Stop()
$stopWatch.Reset()
$Status.Text = $null
Show-ErrorMessage -ErrorMessage "Could not Open the temp dB $($dbfile)`n $(($Error[0].Exception.InnerException | Out-String))"
[Microsoft.Isam.Esent.Interop.Api]::JetDetachDatabase2($Session, $dbfile, [Microsoft.Isam.Esent.Interop.DetachDatabaseGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetEndSession($Session, [Microsoft.Isam.Esent.Interop.EndSessionGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetTerm2($Instance, [Microsoft.Isam.Esent.Interop.TermGrbit]::Complete)
# Delete temp copy of the dB
[System.IO.File]::Delete($dbfile)
return
}
# Get All Table Names
# Returns the names of the tables in the database.
try
{
$TableNames = [System.Collections.ArrayList]@([Microsoft.Isam.Esent.Interop.Api]::GetTableNames($Session, $DatabaseId))
$TableNames.Insert(0, 'MSysObjects') # Manually Insert the System Tables (hidden from the Interop API)
$TableNames.Insert(1, 'MSysObjectsShadow')
$TableNames.Insert(2, 'MSysObjids')
$TableNames.Insert(3, 'MSysLocales')
}
catch
{
$stopWatch.Stop()
$stopWatch.Reset()
$Status.Text = $null
Show-ErrorMessage -ErrorMessage "Could not Acess the temp dB $($dbfile):`n $(($Error[0].Exception.InnerException | Out-String))"
[Microsoft.Isam.Esent.Interop.Api]::JetCloseDatabase($Session, $DatabaseId, [Microsoft.Isam.Esent.Interop.CloseDatabaseGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetDetachDatabase2($Session, $dbfile, [Microsoft.Isam.Esent.Interop.DetachDatabaseGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetEndSession($Session, [Microsoft.Isam.Esent.Interop.EndSessionGrbit]::None)
[Microsoft.Isam.Esent.Interop.Api]::JetTerm2($Instance, [Microsoft.Isam.Esent.Interop.TermGrbit]::None)
# Delete temp copy of the dB
[System.IO.File]::Delete($dbfile)
return
}
# Initialise Dictionary
$script:dBRecords = [System.Collections.Specialized.OrderedDictionary]::New()
$script:dBData = [System.Collections.Specialized.OrderedDictionary]::New()
$script:schema = [System.Collections.Specialized.OrderedDictionary]::New()
$script:thumbfieldname = $null
# Add Initial Nodes to Tree
$treeview1.BeginUpdate()
$Root = $treeview1.Nodes.Insert(1, '1', 'Entries')
$Root.ImageIndex = 5
$Root.SelectedImageIndex = 5
$OrphanNode = $treeview1.Nodes.Insert(2, '0', 'Orphans')
$OrphanNode.ImageIndex = 6
$OrphanNode.ImageIndex = 6
$TableData = [System.Collections.ArrayList]@()
# Create Folder for exported Table data
$dbfilename = Split-Path -Path $SourcedbFile -Leaf
$outfolder = [Environment]::GetFolderPath('Desktop') + "\$($dbfilename)_$($snow)"
$null = [System.IO.Directory]::CreateDirectory("$($outfolder)")
# Export Esent repair/defrag info (if it exists) to show that it was executed
if (!!$Esentrepairlog) { $Esentrepairlog | Out-File -FilePath "$($outfolder)\EsentUtl_log.txt" -Encoding utf8 }
if (!!$Esentdefraglog) { $Esentdefraglog | Out-File -FilePath "$($outfolder)\EsentUtl_log.txt" -Encoding utf8 -Append }
# Sert Progress Bar
$progressbar1.Visible = $true
$progressbar1.Step = 500
$progressbar1.Value = 0
# Get Paths from the Gather Path table First (if the table exists) to build the Tree
if ($TableNames -contains 'SystemIndex_GthrPth')
{
$TableName = 'SystemIndex_GthrPth' # Paths
$Status.Text = "Please wait - Reading $($TableName) ..."
$Table = [Microsoft.Isam.Esent.Interop.JET_TABLEID]::Nil
$null = [Microsoft.Isam.Esent.Interop.Api]::TryOpenTable($Session, $DatabaseId, $tablename, [Microsoft.Isam.Esent.Interop.OpenTableGrbit]::Sequential, [ref]$Table)
$Columns = [Microsoft.Isam.Esent.Interop.Api]::GetTableColumns($Session, $DatabaseId, $TableName)
$ColumnArray = [System.Collections.ArrayList]@()
$RowRecords = [System.Collections.ArrayList]@()
foreach ($Column in $Columns)
{
$null = $ColumnArray.Add(@($Column))
}
$columnCount = $ColumnArray.count
# move to first row of the table (simultaneously check if table is empty)
# Try to move to the first record in the table. If the table is empty this
# returns false, if a different error is encountered an exception is thrown.
try