Last active
November 3, 2020 12:47
-
-
Save JohnCoates/ece63fa29abee3276a4c to your computer and use it in GitHub Desktop.
extract PSIconsHighRes.dat & IconResources.idx - filetype:| Photoshop Icon Resource Index 1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$filepath = "/Applications/Adobe Photoshop CC 2017/Adobe Photoshop CC 2017.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; | |
// XLowRes : 80 extra bytes | |
$dat = fgets($fp); | |
echo $dat; | |
// XHighRes : 80 extra bytes | |
$dat = fgets($fp); | |
echo $dat; | |
$list = array(); | |
$entryLength = 368; | |
function readOffsetFromEntry($entry, $position = 112) { | |
$name = substr($entry, 0, strpos($entry, "\0")); | |
$offset = substr($entry, $position, 4); | |
$hex = bin2hex($offset); | |
$offset = unpack("V", $offset); | |
$offset = array_pop($offset); | |
echo "$name : $offset 0x$hex\n"; | |
return $offset; | |
} | |
while (!feof($fp)) { | |
$entry = fread ($fp, $entryLength); | |
if( strlen($entry) != $entryLength) { | |
break; | |
} | |
$name = substr($entry, 0, strpos($entry, "\0")); | |
$list[] = $name; | |
$offset = readOffsetFromEntry($entry, 144); | |
if ($offset == 0) { | |
continue; | |
} | |
$original = "./extracted/$offset.png"; | |
// exit; | |
if (file_exists($original)) { | |
rename($original, "./extracted/$name.png"); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment