etc/parser/test_innosetup.ps1
using namespace System.IO function Test-InnoSetup { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateScript({!!($script:file = Convert-Path -Path $_ -ErrorAction 0)})] [ValidateNotNullOrEmpty()] [String]$Path ) end { try { $br = [BinaryReader]::new(($fs = [File]::OpenRead(($Path = $file)))) if ($br.ReadUInt16() -ne 0x5A4D) { # installer is a regular PE file throw [InvalidOperationException]::new('DOS signature has not been found.') } $fs.Position = 0x3C # e_lfanew $fs.Position = $br.ReadInt32() # IMAGE_NT_HEADERS if ($br.ReadUInt32() -ne 0x4550) { throw [InvalidOperationException]::new('PE signature has not been found.') } $fs.Position += 0x10 # IMAGE_FILE_HEADER->SizeOfOptionalHeader $fs.Position += $br.ReadUInt16() + 0x18 # .text (PointerToRawData) $fs.Position = $br.ReadUInt32() if ($br.ReadUInt32() -ne 0x401004) { throw [InvalidOperationException]::new('Borland signature has not been found.') } ([xml](Get-PeManifest $Path)[2]).assembly.description } catch { Write-Verbose $_ } finally { ($br, $fs).ForEach{ if ($_) { $_.Dispose() } } } } } |