├── README.md ├── extractifyr ├── README.md └── extractifyr.ps1 └── pngify ├── README.md └── pngify.ps1 /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell Scripts 2 | Collection of extensive PowerShell scripts I've written. 3 | -------------------------------------------------------------------------------- /extractifyr/README.md: -------------------------------------------------------------------------------- 1 | # extractifyr 2 | *This script is a work in progress.* 3 | 4 | **extractifyr** is a PowerShell script that will identify all zip files within a directory (as well as all child directories therein) and present the option to extract those files. Alternately, the user can specify a file to extract. Even if the file isn't named .zip, if it's a zip-compressed archive, it will be found! This is very useful for quickly dumping zip-compressed resources from video game directories, etc. 5 | 6 | ![ScreenShot](http://dsasmblr.com/github/img/extractifyr-image.png) 7 | 8 | **Instructions:** 9 | 10 | 1. *Select a file to extract or a folder to scan.* 11 | 2. *Select a directory to extract the file(s) to.* 12 | 3. *Do it again if you want.* =) 13 | 14 | There will be a lot more coming for this script, in which this space will be updated accordingly! 15 | -------------------------------------------------------------------------------- /extractifyr/extractifyr.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Script: extractifyr 3 | By: Stephen Chapman 4 | Site: http://dsasmblr.com/blog 5 | GitHub: http://github.com/dsasmblr 6 | #> 7 | 8 | 9 | #-----------------# 10 | # -- FUNCTIONS -- # 11 | #-----------------# 12 | 13 | 14 | #Script header 15 | Function Script-Header() 16 | { 17 | Write-Host "#-----------------------#`r" 18 | Write-Host " e-x-t-r-a-c-t-i-f-y-r `r" 19 | Write-Host " By Stephen Chapman `r" 20 | Write-Host " dsasmblr.com `r" 21 | Write-Host "#-----------------------#`n" 22 | } 23 | 24 | #Allows user to choose file to extract files from 25 | Function Get-FileName() 26 | { 27 | If ($StoredFilePath -Eq "") { 28 | #Tries to default to Steam directory 29 | $SteamPath = "C:\Program Files (x86)\Steam\steamapps\common" 30 | $SteamPathTest = Test-Path $SteamPath 31 | $FilePath = If ($SteamPathTest) {$SteamPath} Else {"C:\"} 32 | } Else { 33 | $FilePath = $StoredFilePath 34 | } 35 | 36 | #Dialog box to select file 37 | [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null 38 | $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 39 | $OpenFileDialog.InitialDirectory = $FilePath 40 | $OpenFileDialog.ShowDialog() | Out-Null 41 | $OpenFileDialog.FileName 42 | 43 | #Store file path 44 | $Global:StoredFilePath = $OpenFileDialog.FileName.TrimEnd([System.IO.Path]::GetFileName($OpenFileDialog.FileName)) 45 | } 46 | 47 | #Allows user to choose folder to extract files to 48 | Function Get-FolderName($Origin) 49 | { 50 | If ($StoredDirPath -Eq ""){ 51 | #Tries to default to Steam directory first, then desktop 52 | $SteamPath = "C:\Stephen\Steam\steamapps\common" 53 | $SteamPathTest = Test-Path $SteamPath 54 | $DesktopPath = [Environment]::GetFolderPath("Desktop") 55 | $DesktopPathTest = Test-Path $DesktopPath 56 | $DirPath = If ($SteamPathTest) {$SteamPath} ElseIf ($DesktopPathTest) {$DesktopPath} Else {"C:\"} 57 | } Else { 58 | $DirPath = $StoredDirPath 59 | } 60 | 61 | #Dialog box to select file 62 | Add-Type -Assembly "System.Windows.Forms" 63 | $FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog 64 | $FolderBrowser.SelectedPath = $DirPath 65 | If ($FolderBrowser.ShowDialog() -eq "Cancel") { 66 | User-Choice 67 | } 68 | $FolderBrowser.SelectedPath 69 | 70 | If ($Origin -Ne "ExtractTo") { 71 | $Global:StoredDirPath = $FolderBrowser.SelectedPath 72 | } 73 | } 74 | 75 | #Extracts files from selected file, to selected folder 76 | Function Extract-Files($Origin, $FilesToExtract, $DirToExtractTo) 77 | { 78 | If ($Origin -Eq "UserChoice") { 79 | # This block is ran if user specifies a particular file to extract 80 | Do { 81 | #Assign path to file 82 | $File = Get-FileName 83 | If ($File -Eq "") { 84 | Write-Host "`nAre you sure you want to cancel?" 85 | $Answer = Read-Host "[Y] to cancel, [Enter] to choose a file" 86 | If ($Answer -Eq "Y") { 87 | User-Choice 88 | } 89 | } 90 | } While ($File -Eq "") 91 | 92 | Read-Host "`nFile selected! Now press [Enter] to choose a directory to extract to" 93 | 94 | Do { 95 | #Assign path to extraction folder 96 | $Folder = Get-FolderName 97 | If ($Folder -Eq "") { 98 | Write-Host "`nAre you sure you want to cancel?" 99 | $Answer = Read-Host "[Y] to cancel, [Enter] to choose a file" 100 | If ($Answer -Eq "Y") { 101 | User-Choice 102 | } 103 | } 104 | } While ($Folder -Eq "") 105 | 106 | #Assign original filename for use and preservation 107 | $FileName = [System.IO.Path]::GetFileName($File) 108 | 109 | #Check for .zip extension and provision for Expand-Archive's file extension requirement 110 | If ($File -NotLike "*.zip") { 111 | #Create filename with .zip extension 112 | $FileNameWithZip = $FileName + ".zip" 113 | #Rename the file in the folder 114 | Rename-Item -Path $File -NewName $FileNameWithZip 115 | #Create new path to renamed file 116 | $NewPath = $File.TrimEnd($FileName) 117 | $NewPath += $FileNameWithZip 118 | #Create directory based on file name 119 | $NewDir = New-Item -Path $Folder -Name $FileName -Type Directory 120 | #Extract file(s) from archive 121 | Expand-Archive -LiteralPath $NewPath -DestinationPath $NewDir -Force -ErrorAction SilentlyContinue 122 | #Rename the file in the folder to its original name 123 | Rename-Item -Path $NewPath -NewName $FileName 124 | } Else { 125 | #Create directory based on file name 126 | $NewDir = New-Item -Path $Folder -Name $FileName -Type Directory 127 | #Extract file(s) from archive if extension is already .zip 128 | Expand-Archive -LiteralPath $File -DestinationPath $NewDir -Force -ErrorAction SilentlyContinue 129 | } 130 | } Else { 131 | #This block is ran if user had a directory scanned 132 | ForEach ($FileName in $FilesToExtract) { 133 | 134 | #Assign original filename for use and preservation 135 | $OriginalFileName = [System.IO.Path]::GetFileName($FileName) 136 | 137 | # Check for .zip extension and provision for Expand-Archive's file extension requirement 138 | If ($FileName -NotLike "*.zip") { 139 | #Create filename with .zip extension 140 | $FileNameWithZip = $FileName + ".zip" 141 | #Rename the file in the folder 142 | Rename-Item -Path $FileName -NewName $FileNameWithZip 143 | #Create new path to renamed file for Expand-Archive 144 | $NewPath = $FileName.TrimEnd($FileName) 145 | $NewPath += $FileNameWithZip 146 | #Create directory based on file name 147 | $NewDir = New-Item -Path $DirToExtractTo -Name $OriginalFileName -Type Directory 148 | #Extract file(s) from archive 149 | Expand-Archive -LiteralPath $NewPath -DestinationPath $NewDir -Force -ErrorAction SilentlyContinue 150 | 151 | Rename-Item -Path $NewPath -NewName $FileName # Rename the file in the folder to its original name 152 | } Else { 153 | #Create directory based on file name 154 | $NewDir = New-Item -Path $DirToExtractTo -Name $OriginalFileName -Type Directory 155 | #Extract file(s) from archive if extension is already .zip 156 | Expand-Archive -LiteralPath $FileName -DestinationPath $NewDir -Force -ErrorAction SilentlyContinue 157 | } 158 | } 159 | } 160 | #TO DO: Check for errors in extraction and let user know to try extracting to root. 161 | } 162 | 163 | #Scans a folder and all sub-folders for files that can be extracted 164 | Function Scan-Files() 165 | { 166 | cls 167 | Script-Header 168 | Write-Host "/////////////////////////////////////////////////////////////////////" 169 | Write-Host "--------------------------------------------------------------------" 170 | Write-Host " Preparing for file scan.`r" 171 | Write-Host " Files identified as matches will pop up below as the scan occurs.`r" 172 | Write-Host " This can take a while if scanning a lot of files, so be patient! =)`r" 173 | Write-Host " You will be presented with options after the scan is complete.`r" 174 | Write-Host "--------------------------------------------------------------------" 175 | Write-Host "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\`n" 176 | 177 | #Get directory and all children to scan, then scan them and place all file names and paths into an array 178 | Do { 179 | $FilesToScan = Get-FolderName | Get-ChildItem -Recurse -File | Select-Object -ExpandProperty FullName 180 | If ($FilesToScan.Count -Lt 1) { 181 | cls 182 | Script-Header 183 | Write-Host "You selected an empty folder. Please select a different folder." 184 | } 185 | } While ($FilesToScan.Count -Lt 1) 186 | 187 | #Magic number check to see if each file in the array is zip-compressed or not 188 | $FilesToScan = ForEach ($FileName in $FilesToScan) { 189 | Try { 190 | $i = [System.BitConverter]::ToString((Get-Content $FileName -ReadCount 1 -TotalCount 4 -Encoding Byte)) 191 | } Catch { 192 | # Ignore errors related to empty files 193 | } 194 | Try { 195 | If ($i.startsWith("50-4B")) { 196 | $Discovered = [System.IO.Path]::GetFileName($FileName) 197 | Write-Host "File discovered: $Discovered" 198 | $Global:FileArray += ,$FileName 199 | } 200 | } Catch { 201 | # Ignore errors related to non-zip files 202 | } 203 | } 204 | 205 | #Check for empty array and send user into a rescan flow accordingly 206 | If ($FileArray.Count -Lt 1) { 207 | 208 | cls 209 | Script-Header 210 | Write-Host "No zip files found! Would you like to try again or scan another folder?" 211 | 212 | Do { 213 | $UserSelection = Read-Host "[Y] to choose a directory or [N] to start over" 214 | 215 | If ($UserSelection -Eq "Y") { 216 | Scan-Files 217 | } ElseIf ($UserSelection -Eq "N") { 218 | User-Choice 219 | } Else { 220 | Write-Host "`nWat? Please choose one of the following:" 221 | } 222 | } While ($UserSelection -Ne "Y" -And $UserSelection -Ne "N") 223 | } 224 | 225 | #Ask user if they want to extract files or start over 226 | Write-Host "`nScan completed!" 227 | Write-Host "`nPress [Enter] to select a folder to extract files to or [S] to start over" 228 | $UserSelection = Read-Host "(Tip: Press [S] to start over if you want to extract individual files from the results)" 229 | 230 | If ($UserSelection -Eq "S") { 231 | User-Choice 232 | } Else { 233 | $Global:ExtractTo = Get-FolderName "ExtractTo" 234 | Extract-Files "FromScanFiles" $FileArray $ExtractTo 235 | $Global:FileArray = @() 236 | } 237 | } 238 | 239 | #Initial user choice to scan directory or extract file 240 | Function User-Choice() 241 | { 242 | cls 243 | Script-Header 244 | Write-Host "Would you like to scan a directory for files to extract, or select a file to extract?" 245 | 246 | Do { 247 | $UserSelection = Read-Host "[S] to choose a directory to scan or [E] to choose a file to extract" 248 | 249 | If ($UserSelection -Eq "S") { 250 | Scan-Files 251 | } ElseIf ($UserSelection -Eq "E") { 252 | Extract-Files "UserChoice" 253 | } Else { 254 | Write-Host "`nWat? Please choose one of the following:" 255 | } 256 | } While ($UserSelection -Ne "S" -And $UserSelection -Ne "E") 257 | } 258 | 259 | 260 | #--------------------------# 261 | # -- SCRIPT ENTRY POINT -- # 262 | #--------------------------# 263 | 264 | 265 | $Global:StoredFilePath = "" 266 | $Global:StoredDirPath = "" 267 | $Global:FileArray = @() 268 | $Global:ExtractTo = "" 269 | User-Choice 270 | 271 | Do { 272 | $UserYesNo = Read-Host "`nExtraction complete! Start over? [Y] to start over or any other key to exit" 273 | If ($UserYesNo -Eq "Y") { 274 | Clear-Host 275 | Script-Header 276 | User-Choice 277 | } Else { 278 | Exit 279 | } 280 | } While ($UserYesNo = "Y") 281 | -------------------------------------------------------------------------------- /pngify/README.md: -------------------------------------------------------------------------------- 1 | # pngify 2 | This script is a work in progress. Currently, it scrapes through a file you designate and looks for base64-encoded PNGs, then saves those PNG files to a folder. As I continue to add functionality to this script, I'll update this section accordingly! 3 | 4 | ![ScreenShot](http://dsasmblr.com/github/img/pngify-image.png) 5 | -------------------------------------------------------------------------------- /pngify/pngify.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Script: pngify 3 | By: Stephen Chapman 4 | Site: http://dsasmblr.com/blog 5 | GitHub: http://github.com/dsasmblr 6 | #> 7 | 8 | #-----------------# 9 | # -- FUNCTIONS -- # 10 | #-----------------# 11 | 12 | # Script header 13 | Function Script-Header() 14 | { 15 | Write-Host "#------------------#`r" 16 | Write-Host " p-n-g-i-f-y `r" 17 | Write-Host " By Stephen Chapman`r" 18 | Write-Host " dsasmblr.com `r" 19 | Write-Host "#------------------#`n" 20 | } 21 | 22 | # File selector dialog box 23 | Function Get-FileName($DirToPath) 24 | { 25 | [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null 26 | 27 | $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 28 | $OpenFileDialog.initialDirectory = $DirToPath 29 | $OpenFileDialog.showDialog() | Out-Null 30 | $OpenFileDialog.filename 31 | } 32 | 33 | 34 | #--------------------------# 35 | # -- SCRIPT ENTRY POINT -- # 36 | #--------------------------# 37 | 38 | 39 | # Global variable 40 | $InputFile = "" 41 | $StoredPath = "" 42 | 43 | # Recursive anonymous function to repeat script 44 | $RunScript = { 45 | Script-Header 46 | Read-Host "Press enter to select a file for pngification" 47 | 48 | # Check if path has already been specified; if not, check if Steam path exists, else default to C:\ 49 | If (!$StoredPath) 50 | { 51 | $SteamPath = "C:\Program Files (x86)\Steam\steamapps\common" 52 | $PathTest = Test-Path $SteamPath 53 | $InputFile = If ($PathTest) {Get-FileName $SteamPath} Else {Get-FileName "C:\"} 54 | } 55 | Else 56 | { 57 | $InputFile = Get-FileName $StoredPath 58 | } 59 | 60 | # Prompt user for file again if they hit cancel 61 | While (!$InputFile) { 62 | Read-Host "Why you no choose file? Press enter to choose a file" 63 | $InputFile = Get-FileName $InputFile 64 | } 65 | 66 | # If directory doesn't exist, create using filename of specified file 67 | # If directory does exist, ask if overwrite, create another dir, or start over 68 | $global:DirName = [System.IO.Path]::GetFileNameWithoutExtension($InputFile) 69 | 70 | If (Test-Path $DirName) 71 | { 72 | Do 73 | { 74 | Write-Host "This directory already exists. What would you like to do?`r" 75 | Write-Host "[O] Overwrite files [C] Create another directory [S] Start over`n" 76 | $AlreadyExists = Read-Host "Choose one of the options above" 77 | 78 | Switch ($AlreadyExists) 79 | { 80 | "O" { 81 | Break 82 | } 83 | "C" { 84 | $dnCount = 0 85 | $CreateAnotherDir = { 86 | $dnCount += 1 87 | $DirName += $dnCount.ToString() 88 | If (Test-Path $DirName) 89 | { 90 | $DirName = $DirName.TrimEnd($dnCount.ToString()) 91 | .$CreateAnotherDir 92 | } 93 | Else 94 | { 95 | New-Item $DirName -Type directory | Out-Null 96 | $global:DirName = $DirName 97 | } 98 | } 99 | &$CreateAnotherDir 100 | } 101 | "S" { 102 | Clear-Host 103 | $StoredPath = $InputFile.TrimEnd([System.IO.Path]::GetFileName($InputFile)) 104 | .$RunScript 105 | } 106 | Default {Write-Host "Wat? O, C, or S, please...`n"} 107 | } 108 | } While ($AlreadyExists -Ne "O" -And $AlreadyExists -Ne "C" -And $AlreadyExists -Ne "S") 109 | } 110 | Else 111 | { 112 | New-Item $DirName -Type directory | Out-Null 113 | } 114 | 115 | # Scrape file for PNG data, then convert result to an array 116 | $PngString = Select-String -Path $InputFile -Pattern "url(data:image/png;base64" -SimpleMatch 117 | $PngString = $PngString -Split "\s" 118 | 119 | # Loop through each item in the array and export PNG files 120 | $Count = 0 121 | ForEach ($i in $PngString){ 122 | $i = $i.Trim() 123 | $i = $i.TrimStart("url(data:image/png;base64") 124 | $i = $i -Replace ",", "" 125 | $i = $i -Replace ";", "" 126 | $i = $i.TrimEnd(")*") 127 | If ($i.StartsWith("iVBOR")){ 128 | $Count += 1 129 | $i = [Convert]::FromBase64CharArray($i, 0, $i.Length) 130 | [io.file]::WriteAllBytes("$DirName/$Count.png", $i) 131 | } 132 | } 133 | 134 | Do 135 | { 136 | II $DirName # Open directory files were saved to 137 | $RunAgainOrExit = Read-Host "`nScript completed! Run again? [Y] to run again or [N] to exit" 138 | 139 | If ($RunAgainOrExit -Eq "Y") 140 | { 141 | cls 142 | $StoredPath = $InputFile.TrimEnd([System.IO.Path]::GetFileName($InputFile)) 143 | .$RunScript 144 | } 145 | 146 | If ($RunAgainOrExit -Eq "N") 147 | { 148 | Return 149 | } 150 | } While ($RunAgainOrExit -Ne "Y" -And $RunAgainOrExit -Ne "N") 151 | } 152 | 153 | &$RunScript 154 | --------------------------------------------------------------------------------