-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPatch-V.ps1
More file actions
182 lines (149 loc) · 4.25 KB
/
Patch-V.ps1
File metadata and controls
182 lines (149 loc) · 4.25 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
Param
(
[Parameter(Mandatory=$true)]
$Path,
$Out=".\patched",
$limit=4,
[System.Boolean]$DryRun=$false
)
function Get-HvBinsList()
{
return Get-Content (Join-Path $PSScriptRoot "components.txt")
}
function Get-HvBins($Dir)
{
$result = @{}
$comps = Get-HvBinsList
foreach($d in $Dir)
{
$bin = Get-ChildItem -Path $d.FullName -Attributes Archive
foreach($b in $bin)
{
<#
if($b.Extension -ne ".exe" -and $b.Extension -ne ".dll" -and $b.Extension -ne ".sys")
{
continue
}
#>
if(!($b.Name -in $comps))
{
continue
}
$tmp = @{}
$parent = $b.FullName | Split-Path
$tmp['bin'] = $b.FullName
$tmp['f'] = Join-Path $parent (Join-Path "f" $b.Name)
$tmp['r'] = Join-Path $parent (Join-Path "r" $b.Name)
$result[$b.Name] = $tmp
}
}
return $result
}
function Get-Patch($Dir, $Type)
{
$patch_info = @{}
$comp = Get-HvBinsList
if($Type -ne "f" -and $Type -ne "r")
{
Write-Host "Invalid Patch $Type"
return $patch_info
}
$patches = Get-ChildItem -Recurse -Path $Dir -Attributes Archive | Where-Object -Property Name -in $comp | Where-Object -Property PSParentPath -like "*\f"
foreach($p in $patches)
{
$patch_info[$p.Name] = $p.FullName
}
<#
foreach($d in (Get-ChildItem -Path $Dir -Filter $type -Recurse -Attributes Directory))
{
if(!(Test-Path (Join-Path $d.FullName $Type)))
{
continue
}
foreach($patch in Get-ChildItem -Path (Join-Path $d.FullName $Type))
{
$patch_info[$patch.Name] = $patch.FullName
}
}
#>
return $patch_info
}
function Get-BaseFile()
{
if(!(Test-Path ".\base\"))
{
New-Item -Path ".\base" -ItemType Directory
}
$Src = "C:\Windows\WinSxS"
Write-Host ("Find all hyper-v directory from {0}" -f $Src)
#$local = Get-HvDirs -Dir $Src
$local = Get-ChildItem -Path $Src -Attributes Directory
$bin = Get-HvBins -Dir $local
$bin_enum = $bin.GetEnumerator()
$arg = @()
foreach($b in $bin_enum)
{
$bin_name = $b.name
$patch_info = $bin[$b.Name]
if(!(Test-Path $patch_info['r']))
{
Write-Host ("{0} has no reverse patch, is it already initial version?" -f $bin_name)
Copy-Item -Path $patch_info['bin'] -Destination (Join-Path ".\base" $bin_name)
}
else
{
$arg += "delta_patch.py -i {0} -o {1} {2}" -f $patch_info['bin'], (Join-Path ".\base" $bin_name), $patch_info['r']
#Wait-Process -Id (Start-Process "python" -PassThru -ArgumentList $arg -NoNewWindow).Id
}
}
$arg | ForEach-Object -ThrottleLimit $limit -Parallel {
if($Using:DryRun -eq $true)
{
Write-Host ("DryRun: python {0}" -f $_)
}
else {
Wait-Process -Id (Start-Process "python" -PassThru -ArgumentList $_ -NoNewWindow -RedirectStandardOutput ".\NUL").Id
}
}
}
function Start-ForwardPatch($Patch)
{
$Base = Get-ChildItem -Path ".\base"
if(!(Test-Path $Out))
{
New-Item -Path $Out -ItemType Directory
}
$arg = @()
foreach($b in $Base)
{
if($null -eq $Patch[$b.Name])
{
Write-Host ("{0} not found from patch" -f $b.Name)
continue
}
$arg += "delta_patch.py -i {0} -o {1} {2}" -f $b.FullName, (Join-Path $Out $b.Name), $Patch[$b.Name]
}
$arg | ForEach-Object -ThrottleLimit $limit -Parallel {
if($Using:DryRun -eq $true)
{
Write-Host ("DryRun: python {0}" -f $_)
}
else
{
Wait-Process -Id (Start-Process "python" -PassThru -ArgumentList $_ -NoNewWindow -RedirectStandardOutput ".\NUL").Id
}
}
}
Push-Location
Set-location -Path $PSScriptRoot
if((Get-ChildItem -Path ".\base").length -ne 0)
{
$SkipRev = (Read-Host -Prompt "base dir is not empty, skip reverse patching?[y/n]") -like "y*"
}
if(!$SkipRev)
{
Get-BaseFile
}
$forwards = Get-Patch -Dir $Path -Type "f"
Start-ForwardPatch -Patch $forwards
Pop-Location