PoshCode Archive  Artifact [a4733c152c]

Artifact a4733c152c9eecf6b88be1a69fb3e76aa5fd2ba544fbe68f525e743fa23cce5b:

  • File Get-PEManifest.ps1 — part of check-in [79103eabd4] at 2018-06-10 13:45:27 on branch trunk — this is simplest (and correct) way to dump mainifest of PE (user: greg zakharov size: 1455)

# encoding: ascii
# api: powershell
# title: Get-PEManifest
# description: this is simplest (and correct) way to dump mainifest of PE
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-PEManifest
# x-poshcode-id: 4759
# x-archived: 2014-01-04T21:34:41
# x-published: 2014-01-02T07:50:00
#
#
function Get-PEManifest {
  <#
    .EXAMPLE
        PS C:\>Get-PEManifets E:\SysInternals\whois.exe
    .NOTES
        Author: greg zakharov
  #>
  [CmdletBinding(SupportsShouldProcess=$true)]
  param(
    [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)]
    [ValidateScript({Test-Path $_})]
    [String]$FileName
  )
  
  begin {
    Add-Type -Assembly System.Deployment
    
    $SystemUtilsType = ([AppDomain]::CurrentDomain.GetAssemblies() | ? {
      $_.Location.Split('\')[-1].Equals('System.Deployment.dll')
    }).GetType('System.Deployment.Application.Win32InterOp.SystemUtils')
    
    $SystemUtilsClass = [Activator]::CreateInstance($SystemUtilsType)
  }
  process {
    if ($PSCmdlet.ShouldProcess($FileName, 'Dumping manifest of')) {
      try {
        -join ($SystemUtilsClass.GetType().InvokeMember('GetManifestFromPEResources',
                      [Reflection.BindingFlags]'Public, Static, InvokeMethod', $null,
                                      $SystemUtilsType, @($FileName)) | % {[Char]$_})
      }
      catch {}
    }
  }
  end {}
}