Skip to content

Commit f26eb9c

Browse files
committed
Added Get-TargetCPU cmdlet
Removed elements permitted by the restricted language Removed formatting files
1 parent de947cc commit f26eb9c

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

DLLInfo/DLLInfo.Format.ps1xml

Whitespace-only changes.

DLLInfo/DLLInfo.psd1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
RootModule = 'DLLInfo.psm1'
44
ModuleVersion = '1.0'
55
GUID = 'cf990a96-889f-4c16-9681-d92c592be539'
6-
Author = 'Alan Płócieniak'
7-
CompanyName = 'Alan Płócieniak'
8-
Copyright = '(c) 2019 Alan Płócieniak. All rights reserved.'
6+
Author = 'Alan Plocieniak'
7+
CompanyName = 'Alan Plocieniak'
8+
Copyright = '(c) 2019 Alan Plocieniak. All rights reserved.'
99
Description = 'Read information about DLL file'
1010
PowerShellVersion = '3.0'
11-
FormatsToProcess = 'DLLInfo.Format.ps1xml'
1211
FunctionsToExport = '*'
1312
PrivateData = @{
1413
PSData = @{

DLLInfo/Public/Get-TargetCPU.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Get-TargetCPU {
2+
[cmdletbinding()]
3+
param (
4+
[string]$dllPath
5+
)
6+
$mapping = @{}
7+
$mapping[[System.Reflection.ImageFileMachine]::I386] = "Intel32";
8+
$mapping[[System.Reflection.ImageFileMachine]::IA64] = "Intel64";
9+
$mapping[[System.Reflection.ImageFileMachine]::AMD64] = "AMD64";
10+
11+
$dll = [System.Reflection.Assembly]::LoadFile($dllPath)
12+
$module = $dll.GetModules($false)[0]
13+
$imageFileMachine = New-Object -TypeName "System.Reflection.ImageFileMachine"
14+
$portableExecutableKinds = New-Object -TypeName "System.Reflection.PortableExecutableKinds"
15+
$module.GetPEKind([ref]$portableExecutableKinds, [ref]$imageFileMachine)
16+
if ($portableExecutableKinds -eq "ILOnly" -and $imageFileMachine -eq "I386") {
17+
"AnyCPU"
18+
}
19+
else {
20+
$mapping[$imageFileMachine]
21+
}
22+
}

Tests/DLLInfo.Tests.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,37 @@ Describe 'Test-JitOptimized' {
6161
Test-JitOptimized $Assembly
6262
}
6363

64+
$Job = Start-Job $RunAs32Bit -RunAs32 -Arg $Assembly
65+
$Job | Wait-Job | Receive-Job | Should -Be $Expected
66+
}
67+
}
68+
}
69+
70+
Describe 'Get-TargetCPU' {
71+
Context "Check test DLLs - x64" {
72+
It "Given valid -Assembly '<Assembly>', it returns <Expected>" -TestCases @(
73+
@{ Assembly = "$PSScriptRoot\bin\Debug\AssemblyInfoTest.dll"; Expected = 'AnyCPU' }
74+
@{ Assembly = "$PSScriptRoot\bin\Release\AssemblyInfoTest.dll"; Expected = 'AnyCPU' }
75+
@{ Assembly = "$PSScriptRoot\bin\x64\Debug\AssemblyInfoTest.dll"; Expected = 'AMD64' }
76+
@{ Assembly = "$PSScriptRoot\bin\x64\Release\AssemblyInfoTest.dll"; Expected = 'AMD64' }
77+
) {
78+
param ($Assembly, $Expected)
79+
Get-TargetCPU $Assembly | Should -Be $Expected
80+
}
81+
}
82+
83+
Context "Check test DLLs - x86" {
84+
It "Given valid -Assembly '<Assembly>', it returns <Expected>" -TestCases @(
85+
@{ Assembly = "$PSScriptRoot\bin\x86\Debug\AssemblyInfoTest.dll"; Expected = 'Intel32' }
86+
@{ Assembly = "$PSScriptRoot\bin\x86\Release\AssemblyInfoTest.dll"; Expected = 'Intel32' }
87+
) {
88+
param ($Assembly, $Expected)
89+
$RunAs32Bit = {
90+
param($Assembly)
91+
Import-Module .\DLLInfo\DLLInfo.psm1 -Force
92+
Get-TargetCPU $Assembly
93+
}
94+
6495
$Job = Start-Job $RunAs32Bit -RunAs32 -Arg $Assembly
6596
$Job | Wait-Job | Receive-Job | Should -Be $Expected
6697
}

0 commit comments

Comments
 (0)