INSTRUCTIONS:
Put both files in a folder, then create a subfolder named "extracted". Run readPhotoshopIcons.php to extract images then run readPhotoshopIconNames.php to rename files to their correct names.
| <?php | |
| $filepath = "/Applications/Adobe Photoshop CC 2014/Adobe Photoshop CC 2014.app/Contents/Resources/IconResources.idx"; | |
| $headerMagic = "Photoshop Icon Resource Index 1.0\n"; | |
| $fp = fopen($filepath, "r"); | |
| $magic = fread($fp, strlen($headerMagic)); | |
| if ($magic != $headerMagic) { | |
| exit("error: wrong magic"); | |
| } | |
| // low res | |
| $dat = fgets($fp); | |
| echo $dat; | |
| // high res | |
| $dat = fgets($fp); | |
| echo $dat; | |
| $list = array(); | |
| while (!feof($fp)) { | |
| $entry = fread ($fp, 208); | |
| if( strlen($entry) != 208) { | |
| break; | |
| } | |
| $name = substr($entry, 0, strpos($entry, "\0")); | |
| $list[] = $name; | |
| $offset = substr($entry, 112, 4); | |
| $hex = bin2hex($offset); | |
| $offset = unpack("V", $offset); | |
| $offset = array_pop($offset); | |
| echo "$name : $offset 0x$hex\n"; | |
| if ($offset == 0) { | |
| continue; | |
| } | |
| $original = "./extracted/$offset.png"; | |
| if (file_exists($original)) { | |
| rename($original, "./extracted/$name.png"); | |
| } | |
| } | |
| ?> |
| <?php | |
| $filepath = "/Applications/Adobe Photoshop CC 2014/Adobe Photoshop CC 2014.app/Contents/Resources/PSIconsHighRes.dat"; | |
| $fp = fopen($filepath, "r"); | |
| $pngBuffer = ""; | |
| $pngHeader = sprintf("%c%c%c%c%c%c%c%c", 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A); | |
| $pngHeaderLength = strlen($pngHeader); | |
| $count = 0; | |
| global $pngOffset; | |
| while (!feof($fp)) { | |
| $char = fread($fp, 1); | |
| // check for start of magic | |
| if ($char != chr(0x89)) { | |
| continue; | |
| } | |
| // backtrack 1 | |
| fseek($fp, -1, SEEK_CUR); | |
| printf("checking for full header\n"); | |
| // check for full header | |
| $search = fread($fp, $pngHeaderLength); | |
| if ($search == $pngHeader) { | |
| fseek ($fp, 0 - $pngHeaderLength, SEEK_CUR); | |
| $pngFile = readPNGFile($fp); | |
| } | |
| // write out file | |
| $pngfp = @fopen("extracted/$pngOffset.png", "x"); | |
| @fwrite($pngfp, $pngFile); | |
| @fclose($pngfp); | |
| $count++; | |
| } | |
| function readPNGFile($fp) { | |
| global $pngHeader, $pngHeaderLength, $pngOffset; | |
| $pos = ftell($fp); | |
| $pngOffset = $pos; | |
| echo "Reading PNG @ $pos\n"; | |
| $contents = fread($fp, $pngHeaderLength); | |
| while ( ($chunk = readChunk($fp) ) ) { | |
| $contents .= $chunk['data']; | |
| if ($chunk['name'] == "IEND") { | |
| break; | |
| } | |
| } | |
| return $contents; | |
| } | |
| function readChunk($fp) { | |
| $chunk = ""; | |
| // Read length | |
| $length = fread($fp, 4); | |
| $chunk .= $length; | |
| // turn length into int | |
| $length = unpack("N", $length); | |
| $length = array_pop($length); | |
| // Read chunk name | |
| $name = fread($fp, 4); | |
| $chunk .= $name; | |
| printf("reading chunk $name with length %d\n", $length); | |
| if ($length > 0) { | |
| $chunk .= fread($fp, $length); | |
| } | |
| $crc = fread($fp, 4); | |
| $chunk .= $crc; | |
| return array("name" => $name, "data" => $chunk); | |
| } | |
| ?> |
how to run readPhotoshopIcons.php