Ghidra is a software reverse engineering (SRE) framework
Fix rewriting of IDAT chunk(s). - check if rewriting is needed, otherwise just copy - don't copy subsequent chunks if first one was rewritten (and therefore contains data from all original chunks)
Kai Bolay12a6b23853d1
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.javaindex 264a9db7cc..653e18c779 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ios/png/CrushedPNGUtil.java@@ -145,31 +145,31 @@ public class CrushedPNGUtil {if (!(Arrays.equals(idBytes, CrushedPNGConstants.INSERTED_IOS_CHUNK))) {//If the chunk is the old IDAT chunk replace with new IDAT data- if (Arrays.equals(idBytes, CrushedPNGConstants.IDAT_CHUNK) && !wroteIDAT) {-- //Write the chunk data length- int dataLength = repackArray.length;- byte[] lengthBytes = ByteBuffer.allocate(4).putInt(dataLength).array();- outputStream.write(lengthBytes);-- //Gather ID and data together to calculate CRC32- byte[] idat = new byte[CrushedPNGConstants.IDAT_CHUNK.length + dataLength];- for (int i = 0; i < CrushedPNGConstants.IDAT_CHUNK.length; i++) {- idat[i] = CrushedPNGConstants.IDAT_CHUNK[i];- }- for (int i = 0; i < dataLength; i++) {- idat[CrushedPNGConstants.IDAT_CHUNK.length + i] = repackArray[i];- }-- //Write the chunk data- outputStream.write(idat);+ if ((repackArray != null) && Arrays.equals(idBytes, CrushedPNGConstants.IDAT_CHUNK)) {+ if (!wroteIDAT) {+ //Write the chunk data length+ int dataLength = repackArray.length;+ byte[] lengthBytes = ByteBuffer.allocate(4).putInt(dataLength).array();+ outputStream.write(lengthBytes);++ //Gather ID and data together to calculate CRC32+ byte[] idat = new byte[CrushedPNGConstants.IDAT_CHUNK.length + dataLength];+ for (int i = 0; i < CrushedPNGConstants.IDAT_CHUNK.length; i++) {+ idat[i] = CrushedPNGConstants.IDAT_CHUNK[i];+ }+ for (int i = 0; i < dataLength; i++) {+ idat[CrushedPNGConstants.IDAT_CHUNK.length + i] = repackArray[i];+ }- //Calculate and write chunk crc32- byte[] checksum = calculateCRC32(idat);- outputStream.write(checksum);+ //Write the chunk data+ outputStream.write(idat);- wroteIDAT = true;+ //Calculate and write chunk crc32+ byte[] checksum = calculateCRC32(idat);+ outputStream.write(checksum);+ wroteIDAT = true;+ }}else {