-
Notifications
You must be signed in to change notification settings - Fork 6
/
Out-SquarifiedTreeMap.ps1
777 lines (735 loc) · 24.8 KB
/
Out-SquarifiedTreeMap.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
Function Out-SquarifiedTreeMap
{
<#
.SYNOPSIS
Used to present a Squarified Treemap and optional heatmap for visualizing data.
.DESCRIPTION
Used to present a Squarified Treemap and optional heatmap for visualizing data.
.PARAMETER Width
Sets the Width of the squarified treemap window
.PARAMETER Height
Sets the Height of the squarified treemap window
.PARAMETER InputObject
Collection of Data that will be represented in the squarified treemap.
Accepts pipeline input.
.PARAMETER LabelProperty
Determines the Label that can be displayed on the UI in the tooltip.
.PARAMETER DataProperty
Used to determine the Size of each item in the squarified treemap. Must be used
when supplying an object with a property. If passing just values, then this must be
left blank.
.PARAMETER HeatmapProperty
Used when a heatmap will be displayed in squarified treemap by setting the property
that will be used to determine the color scheme for the UI. If MaxHeatMapSize is not used,
then the largest value will be used as the threshold.
.PARAMETER MaxHeatMapSize
Used to set a threshold to influence the colors of the heatmap. If left blank and HeatMapProperty
is used, then the largest value for HeatMapProperty will be used as the threshold.
.PARAMETER ToolTip
Custom tooltip that will apply to UI. Each square/rectangle will have a tooltip
which will appear when mouse is over the object. This must be a scriptblock that
contains a here-string. The use of $This is allowed and contains the following
available properties:
LabelProperty
DataProperty
HeatmapProperty
Row
Orientation
Width
Height
Coordinate
ObjectData (This contains the object that was passed to this function)
.PARAMETER ShowLabel
Custom label that will apply to rectangle in the UI. This must be a scriptblock that
contains a here-string. The use of $This is allowed and contains the following
available properties:
LabelProperty
DataProperty
HeatmapProperty
Row
Orientation
Width
Height
Coordinate
ObjectData (This contains the object that was passed to this function)
.PARAMETER PassThru
Allows you to select a single item on the treemap that will close out the UI and output the corresponding
original object based on the selected item for use with another command.
You can move this UI around as long as you are holding down on the CTRL key prior to left clicking on the UI and
then drag it around. This will prevent the UI from closing and the object being presented.
.NOTES
Name: Out-SquarifiedTreeMap
Author: Boe Prox
Version History:
1.3 //Boe Prox - 11/08/2016
-Updated ShowLable to accept scriptblock for more customizable labels
1.2 //Boe Prox - 10/31/2016
-Allowed for displaying a label on the UI
1.1 //Boe Prox - 10/28/2016
-Removed runspaces to allow piping of data from UI into another command
-Allowed for selecting of a single item to output original object
1.0 //Boe Prox - 12/07/2015
-Production Version
.EXAMPLE
1..8|Out-SquarifiedTreeMap -Width 600 -Height 200 -MaxHeatMapSize 8 -ShowLabel HeatmapProperty
Description
-----------
Creates a squarified treemap with a heat map with incoming data. A MaxHeatMapSize of
15 was set to ensure an accurate heatmap is displayed with the given data. The size of
the UI was also set as well.
.EXAMPLE
$Tooltip = {
@"
Process Name <PID>: $($This.LabelProperty) <$($This.ObjectData.Id)>
WorkingSet Memory(MB): $([math]::Round(($This.DataProperty/1MB),2))
"@
}
Get-Process | Sort-Object -prop WS -Descending | Select -First 8 |
Out-SquarifiedTreeMap -Tooltip $Tooltip -LabelProperty ProcessName -DataProperty WS -HeatmapProperty WS -Width 600 -Height 400 `
-PassThru -ShowLabel {"$($This.LabelProperty) <$($This.ObjectData.ID)>"} |
Stop-Process -WhatIf
Description
-----------
A Squarified Treemap with a heat map is created of all running processes. To support the default tooltip,
the LabelProperty was chosen with the ProcessName. The DataProperty was used with WS for the sizing of the
squares in the UI based on memory. The same property is used for the Heatmap to help show the largest and
smallest consumer of memory. Upon clicking one of the items on the UI, it will output the original object
so it can be used in another command as the -PassThru parameter was used.
.EXAMPLE
$FileInfo = Get-ChildItem -Directory|ForEach {
$Files = Get-ChildItem $_.fullname -Recurse -File|measure-object -Sum -Property length
[pscustomobject]@{
Name = $_.name
Fullname = $_.fullname
Count = [int64]$Files.Count
Size = [int64]$Files.Sum
}
}
$Tooltip = {
@"
Name = $($This.LabelProperty)
Fullname = $($This.ObjectData.FullName)
FileCount = $($This.Dataproperty)
Size = $([math]::round(($This.HeatmapProperty/1MB),2)) MB
"@
}
$FileInfo |
Out-SquarifiedTreeMap -Width 800 -Height 600 -LabelProperty Name `
-DataProperty Count -HeatmapProperty Size -ToolTip $Tooltip -ShowLabel LabelProperty -PassThru
Description
-----------
A Squarified Treemap with a heat map is created of folder sizes. First a command is run to
determine the sizes of a set of folders and then a custom ToolTip is created using a scriptblock
with a here-string within it. The use of $This is shown with using LabelProperty, DataProperty and
HeatMapProperty to better display the data when the mouse is hovering over each square.
#>
Param (
[float]$Width = 600,
[float]$Height = 200,
[parameter(ValueFromPipeline = $True)]
[object[]]$InputObject = @(60, 60),
[ValidateNotNullorEmpty()]
[string]$LabelProperty,
[ValidateNotNullorEmpty()]
[string]$DataProperty,
[ValidateNotNullorEmpty()]
[string]$HeatmapProperty,
[ValidateNotNullorEmpty()]
[int64]$MaxHeatMapSize,
[scriptblock]$ToolTip,
[scriptblock]$ShowLabel,
[switch]$PassThru
)
Begin
{
Import-Module ShowUI
Write-Verbose "[BEGIN]Starting Function"
#region Helper Functions
Function New-SquareTreeMapData
{
[cmdletbinding()]
Param (
[float]$Width,
[float]$Height,
[parameter(ValueFromPipeline = $True)]
[object[]]$InputObject,
[string]$LabelProperty,
[string]$DataProperty,
[string]$HeatmapProperty,
[int64]$MaxHeatMapSize
)
Begin
{
Try
{
[void][treemap.coordinate]
}
Catch
{
Add-Type -TypeDefinition @"
using System;
namespace TreeMap
{
public class Coordinate
{
public float X;
public float Y;
public Coordinate(float x, float y)
{
X = x;
Y = y;
}
public Coordinate(float x)
{
X = x;
Y = 0;
}
public Coordinate()
{
X = 0;
Y = 0;
}
public override string ToString()
{
return X+","+Y;
}
}
}
"@
}
Function Get-StartingOrientation
{
Param ([float]$Width,
[float]$Height)
Switch (($Width -ge $Height))
{
$True { 'Vertical' }
$False { 'Horizontal' }
}
}
#region Starting Data
$Tag = 1
$Row = 1
$Rectangle = New-Object System.Collections.ArrayList
$DecimalThreshold = .4
$TempData = New-Object System.Collections.ArrayList
If ($PSBoundParameters.ContainsKey('InputObject'))
{
$Pipeline = $False
Write-Verbose "Adding `$InputObject to list"
[void]$TempData.AddRange($InputObject)
}
Else
{
$Pipeline = $True
}
#Sort the data
$List = New-Object System.Collections.ArrayList
$Stack = New-Object System.Collections.Stack
$FirstCoordRun = $True
$CurrentX = 0
$CurrentY = 0
#endregion Starting Data
}
Process
{
If ($Pipeline)
{
#Write-Verbose "Adding $($_) to list"
[void]$TempData.Add($_)
}
}
End
{
If ($PSBoundParameters.ContainsKey('DataProperty'))
{
$TempData | Sort-Object $DataProperty | ForEach {
#If it is 0, then it should not occupy space
If ($_.$DataProperty -gt 0)
{
$Stack.Push($_)
}
}
}
Else
{
$TempData | Sort-Object | ForEach {
#If it is 0, then it should not occupy space
If ($_ -gt 0)
{
$Stack.Push($_)
}
}
}
$ElementCount = $Stack.Count
#Begin building out the grid
$Temp = New-Object System.Collections.ArrayList
While ($Stack.Count -gt 0)
{
$PreviousWidth = 0
$PreviousHeight = 0
$TotalBlockHeight = 0
$TotalBlockWidth = 0
Write-Verbose "Width: $Width - Height: $Height"
#Write-Verbose "StackCount: $($Stack.Count)"
$FirstRun = $True
#Write-Verbose "Row: $Row"
If ($PSBoundParameters.ContainsKey('DataProperty'))
{
$TotalArea = ($Stack | Measure-Object -Property $DataProperty -Sum).Sum
}
Else
{
$TotalArea = ($Stack | Measure-Object -Sum).Sum
}
#Write-Verbose 'Getting starting orientation'
$Orientation = Get-StartingOrientation -Width $Width -Height $Height
Write-Verbose "Orientation: $Orientation"
$Iteration = 0
Do
{
$Iteration++
#Write-Verbose "Iteration: $Iteration"
#Write-Verbose "TotalArea: $($TotalArea)"
[void]$List.Add($Stack.Pop())
If ($PSBoundParameters.ContainsKey('DataProperty'))
{
$PercentArea = (($List | Measure-Object -Property $DataProperty -Sum).Sum/$TotalArea)
}
Else
{
$PercentArea = (($List | Measure-Object -Sum).Sum/$TotalArea)
}
#Write-Verbose "PercentArea: $($PercentArea)"
}
Until (($PercentArea -ge $DecimalThreshold) -OR ($Stack.Count -eq 0))
#Write-Verbose "Threshold met!"
If ($List.Count -gt 1)
{
If ($PSBoundParameters.ContainsKey('DataProperty'))
{
$_area = ($List | Measure-Object -Property $DataProperty -Sum).Sum
}
Else
{
$_area = ($List | Measure-Object -Sum).Sum
}
}
$List | ForEach {
If ($PSBoundParameters.ContainsKey('DataProperty'))
{
$Item = $_.$DataProperty
}
Else
{
$Item = $_
}
If ($PSBoundParameters.ContainsKey('LabelProperty'))
{
$Label = $_.$LabelProperty
}
If ($PSBoundParameters.ContainsKey('HeatmapProperty'))
{
$HeatmapData = $_.$HeatmapProperty
}
ElseIf ($PSBoundParameters.ContainsKey('MaxHeatMapSize'))
{
$HeatmapData = $_
}
Switch ($Orientation)
{
'Vertical' {
#Get block width
$BlockWidth = ($PercentArea * $Width)
Write-Verbose "BlockWidth: $($BlockWidth)"
If ($Iteration -eq 1)
{
$BlockHeight = $Height
}
Else
{
#Get block height
$_percentarea = ($Item / $_area)
$BlockHeight = ($_percentarea * $Height)
Write-Verbose "BlockHeight: $($BlockHeight)"
}
}
'Horizontal' {
#Get block height
$BlockHeight = ($PercentArea * $Height)
Write-Verbose "BlockHeight: $($BlockHeight)"
If ($Iteration -eq 1)
{
$BlockWidth = $Width
}
Else
{
#Get block width
$_percentarea = ($Item / $_area)
$BlockWidth = ($_percentarea * $Width)
Write-Verbose "BlockWidth: $($BlockWidth)"
}
}
}
If ($FirstCoordRun)
{
Write-Verbose 'First run coordinates'
$Coordinate = New-Object -Typename treemap.coordinate -ArgumentList $CurrentX, $CurrentY
$FirstCoordRun = $False
}
Else
{
Write-Verbose 'Rest of coordinates'
Switch ($Orientation)
{
'Vertical' {
Write-Verbose 'Setting Vertical coordinates'
Write-Verbose "TotalHeight: $($TotalBlockHeight)"
$Y = $TotalBlockHeight + $CurrentY
$Coordinate = New-Object -Typename treemap.coordinate -ArgumentList $CurrentX, $Y
}
'Horizontal' {
Write-Verbose "TotalWidth: $($TotalBlockWidth)"
Write-Verbose 'Setting Horizontal coordinates'
$X = $TotalBlockWidth + $CurrentX
$Coordinate = New-Object -Typename treemap.coordinate -ArgumentList $X, $CurrentY
}
}
}
[pscustomobject]@{
Tag = $Tag
LabelProperty = $Label
DataProperty = $Item
HeatmapProperty = $HeatmapData
Row = $Row
Orientation = $Orientation
Width = $BlockWidth
Height = $BlockHeight
Coordinate = $Coordinate
ObjectData = $_
}
$Tag++
$PreviousWidth = $BlockWidth
$PreviousHeight = $BlockHeight
$TotalBlockHeight = $TotalBlockHeight + $BlockHeight
$TotalBlockWidth = $TotalBlockWidth + $BlockWidth
}
If ($Orientation -eq 'Vertical')
{
$CurrentX = $BlockWidth + $CurrentX
$Width = $Width - $BlockWidth
}
Else
{
$CurrentY = $CurrentY + $BlockHeight
$Height = $Height - $BlockHeight
}
Write-Verbose "CurrentX: $($CurrentX)"
Write-Verbose "CurrentY: $($CurrentY)"
$list.Clear()
$Row++
$FirstCoordRun = $True
}
}
}
Function Color
{
Param ($Decimal)
if($Decimal -eq 0.0) {
Return ([windows.media.color]::FromRgb(0, 0, 255)).ToString()
}
If ($Decimal -gt 1)
{
$Decimal = 1
}
$Red = ([float](2.0) * $Decimal)
$Red = If ($Red -gt 1)
{
255
}
Else
{
$Red * 255
}
$Green = (([float](2.0) * (1 - $Decimal)))
$Green = If ($Green -gt 1)
{
255
}
Else
{
$Green * 255
}
([windows.media.color]::FromRgb($Red, $Green, 0)).ToString()
}
Function New-Rectangle
{
Param (
$Width,
$Height,
$Color,
$Tooltip,
$Tag
)
$Rectangle = new-object System.Windows.Shapes.Rectangle
$Rectangle.Width = $Width
$Rectangle.Height = $Height
$Rectangle.Fill = $Color
$Rectangle.Stroke = 'Black'
$Rectangle.ToolTip = $Tooltip
$Rectangle.Tag = $Tag
Return $Rectangle
}
Function New-ViewBox
{
Param (
$Width,
$Height,
$Text
)
$Label = new-object System.Windows.Controls.Label
$Viewbox = new-object System.Windows.Controls.Viewbox
$DropShadow = New-Object System.Windows.Media.Effects.DropShadowEffect
$DropShadow.Opacity = 5
$DropShadow.BlurRadius = 5
$DropShadow.Color = 'Black'
$DropShadow.ShadowDepth = 0
$Viewbox.Stretch = 'Uniform'
$Viewbox.Width = $Width
$Viewbox.Height = $Height
$Label.IsHitTestVisible = $False
$Label.FontFamily = 'Calibri'
$Label.FontWeight = 'Bold'
$Label.Foreground = 'White'
$Label.Content = $Text
$Label.Effect = $DropShadow
$Viewbox.AddChild($Label)
Return $Viewbox
}
#endregion Helper Functions
$TempData = New-Object System.Collections.ArrayList
If ($PSBoundParameters.ContainsKey('InputObject'))
{
$Pipeline = $False
Write-Verbose "Adding `$InputObject to list"
[void]$TempData.AddRange($InputObject)
}
Else
{
$Pipeline = $True
}
Write-Verbose "[BEGIN] End Begin"
}
Process
{
Write-Verbose "[PROCESS]"
If ($Pipeline)
{
Write-Verbose "Adding $($_) to list"
[void]$TempData.Add($_)
}
}
End
{
Write-Verbose "[END] Begin End"
#region Hashtables
$DataHash = [hashtable]::Synchronized(@{
Width = $Width
Height = $Height
})
#endregion Hashtables
If ($PSBoundParameters.ContainsKey('PassThru'))
{
[void]$PSBoundParameters.Remove('PassThru')
$Script:IsPassThru = $True
}
Else
{
$Script:IsPassThru = $False
}
Write-Verbose "[PassThruBoundParam] $($Script:IsPassThru)"
If ($PSBoundParameters.ContainsKey('ShowLabel'))
{
[void]$PSBoundParameters.Remove('ShowLabel')
$Script:ShowLabel = $True
$DataHash['ShowLabel'] = $ShowLabel
}
Else
{
$Script:ShowLabel = $False
}
If (-NOT $PSBoundParameters.ContainsKey('Width'))
{
$PSBoundParameters['Width'] = $Width
}
If (-NOT $PSBoundParameters.ContainsKey('Height'))
{
$PSBoundParameters['Height'] = $Height
}
If ($PSBoundParameters.ContainsKey('ToolTip'))
{
[void]$PSBoundParameters.Remove('ToolTip')
$HasToolTip = $True
$DataHash['ToolTip'] = $ToolTip
}
Else
{
$HasToolTip = $False
}
$DataHash['HasToolTip'] = $HasToolTip
$PSBoundParameters['InputObject'] = $TempData
If ($PSBoundParameters.ContainsKey('PipelineVariable'))
{
[void]$PSBoundParameters.Remove('PipelineVariable')
}
$TreeMapData = New-SquareTreeMapData @PSBoundParameters
$DataHash['TreeMapData'] = $TreeMapData
If ($PSBoundParameters.ContainsKey('HeatmapProperty'))
{
$Maximum = ($TreeMapData | Measure-Object -Property HeatmapProperty -Maximum).Maximum
$DataHash['HeatmapProperty'] = $HeatmapProperty
$DataHash['Maximum'] = $Maximum
}
If ($PSBoundParameters.ContainsKey('MaxHeatMapSize'))
{
$Maximum = $MaxHeatMapSize
$DataHash['MaxHeatMapSize'] = $MaxHeatMapSize
$DataHash['Maximum'] = $Maximum
}
#region XAML
[xml]$xaml = @"
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
>
<Viewbox >
<Canvas MinWidth = "$($DataHash.Width)" MinHeight = "$($DataHash.Height)"
x:Name="Canvas" />
</Viewbox>
</UserControl>
"@
#endregion XAML
#region Connect to Control
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
$Window = [System.Windows.Markup.XamlReader]::Load($reader)
$xaml.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]") | ForEach {
New-Variable -Name $_.Name -Value $Window.FindName($_.Name) -Force -ErrorAction SilentlyContinue -Scope Script
}
$Window.Add_MouseRightButtonDown({
If ($_.OriginalSource -is [System.Windows.Shapes.Rectangle])
{
$Source = $_.OriginalSource
$Script:Result = $DataHash.TreeMapData | Where {
$_.Tag -eq $Source.Tag
} | Select-Object -ExpandProperty ObjectData
$Script:Result | Write-Verbose
Write-Verbose "Loading remote memory with call to Get-ProcessMemory -s $s -ID $($Script:Result.Id) -Address $($Script:Result.BaseAddress) -Length $($Script:Result.Size) "
# load memory into a file
$addr_hdr = $Script:Result.BaseAddress-4096
$Size_hdr = $Script:Result.Size+4096
$RemoteMem = Get-ProcessMemory -s $s -ID $Script:Result.Id -Address $addr_hdr -Length $Size_hdr
Write-Verbose "RemoteMemoryRead of $($RemoteMem.Length) bytes"
$MemTemp = [System.IO.Path]::GetTempFileName()
Write-Verbose "Temp file for remote memory is $MemTemp"
[System.IO.File]::WriteAllBytes($MemTemp, $RemoteMem)
$infoMem = "ProcessID: $($Script:Result.Id) Address: $($addr_hdr.ToString(""x"")) Length: $($Size_hdr.ToString(""x"")) temp: $($MemTemp)"
# query pagehash server for it's interpretation of the same block
$goldTmp = [System.IO.Path]::GetTempFileName()
Write-Verbose "Temp file for golden image is $goldTmp"
Write-Verbose "Get-GoldenImage -file $($Script:Result.ModuleName) -mapped $($Script:Result.BaseAddress) -writeOut $goldTmp"
Get-GoldenImage -file $Script:Result.ModuleName -mapped $Script:Result.BaseAddress -writeOut $goldTmp
Write-Verbose "Attempting Invoke-Command -ScriptBlock { Get-BinDiff $($argS[0]) $($argS[1]) } -ArgS $MemTemp $goldTmp"
$infoGold = "ModuleName: $($Script:Result.ModuleName) temp: $($goldTmp))"
if((([System.IO.FileInfo]$MemTemp).Length -gt 0) -and (([System.IO.FileInfo]$goldTmp).Length -gt 0)) {
# I'm still new to PS and this thing was annoying
# for some reason the right click (I think since it's a new Window the dispatcher is getting pissed off)
# anyhow
#Slow method with FlowDocument
#$cmd = "Import-Module .\Test-AllVirtualMemory.ps1; Get-BinDiff $MemTemp $goldTmp $infoMem $infoGold -Verbose "
$cmd = "Add-Type -AssemblyName PresentationFramework; import-module showui; Import-Module .\Test-AllVirtualMemory.ps1; Get-FastBinDiff $MemTemp $goldTmp $addr_hdr"
Write-Verbose "Attempting: $cmd"
[System.Diagnostics.Process]::Start("powershell.exe", $cmd)
#Invoke-Command -ScriptBlock { Get-BinDiff $argS[0] $argS[1] } -ArgS $MemTemp $goldTmp
}
}
})
#endregion Connect to Control
$Window.Add_MouseLeftButtonDown({
$Script:KeyDown = [System.Windows.Input.Keyboard]::IsKeyDown("RightCtrl") -OR [System.Windows.Input.Keyboard]::IsKeyDown("LeftCtrl")
Write-Verbose "[MouseButtonDown-CTRLKeyDown] $($Script:KeyDown)"
Write-Verbose "[IsPassThru] $($Script:IsPassThru)"
If ($_.OriginalSource -is [System.Windows.Shapes.Rectangle])
{
$Tooltip = {
@"
Name = $($This.LabelProperty)
FullName = $($This.ObjectData.FullName)
PercentValid = $($This.ObjectData.PercentValid)
Size = $($This.ObjectData.Size)
"@
}
$Source = $_.OriginalSource
$Script:Result = $DataHash.TreeMapData | Where {
$_.Tag -eq $Source.Tag
} | Select-Object -ExpandProperty ObjectData
Out-SquarifiedTreeMap -InputObject $Script:Result.Children -Width $Width -Height $Height -DataProperty Size -HeatmapProperty Heat -MaxHeatMapSize 1.0 -LabelProperty Label -ToolTip $Tooltip -ShowLabel {"$($This.ObjectData.Label)"} | Show-UI
}
})
$DataHash.TreeMapData | ForEach {
$This = $_
If ($DataHash.ContainsKey('HeatmapProperty'))
{
$Decimal = $_.HeatmapProperty / $DataHash.Maximum
$Color = (Color -Decimal $Decimal)
}
ElseIf ($DataHash.ContainsKey('MaxHeatMapSize'))
{
$Decimal = $_.HeatmapProperty / $DataHash.Maximum
$Color = (Color -Decimal $Decimal)
}
Else
{
Write-Verbose 'Default color used'
$Color = 'Green'
}
Write-Verbose "Color: $($Color)"
Write-Verbose "Creating Rectangle for $($_.Data)"
If (-NOT $DataHash.HasToolTip)
{
$__Tooltip = @"
Label: $($This.LabelProperty)
Data: $($This.DataProperty)
HeatMap: $($This.HeatmapProperty)
"@
}
Else
{
$ToolTip = [scriptblock]::Create($DataHash.ToolTip.ToString())
$__Tooltip = $ToolTip.Invoke() | Out-String
}
$Rectangle = New-Rectangle -Width $_.Width -Height $_.Height -Color $Color -Tooltip $__Tooltip -Tag $_.Tag
[void]$Canvas.Children.Add($Rectangle)
[System.Windows.Controls.Canvas]::SetLeft($Rectangle, $_.Coordinate.X)
[System.Windows.Controls.Canvas]::SetTop($Rectangle, $_.Coordinate.Y)
If ($ShowLabel)
{
$ShowLabel = [scriptblock]::Create($DataHash.ShowLabel.ToString())
$__ShowLabel = $ShowLabel.Invoke() | Out-String
$Viewbox = New-ViewBox -Width $_.Width -Height $_.Height -Text $__ShowLabel
[void]$Canvas.Children.Add($Viewbox)
[System.Windows.Controls.Canvas]::SetLeft($Viewbox, $_.Coordinate.X)
[System.Windows.Controls.Canvas]::SetTop($Viewbox, $_.Coordinate.Y)
}
}
#Show UI
Write-Verbose "[END] Show UI"
$Window
Write-Verbose "[END] UI Close"
If ($IsPassThru)
{
Write-Verbose "Output Object"
$Result
}
}
}