I need a large number of damaged
.png files in order to test my project. To that end, I need to set all bytes from the 0x054-th to the 0xa00-th to 0.
.png files contain chunks with checksums, I want to alter the image data chunk (IDAT), without updating the checksum. Furthermore, I want to damage a lot of bytes, so that a visible (black) area appears when displaying the image (provided the viewing program ignores the checksum mismatch).
Here is what I have got so far:
#!/bin/sh # This script reads all .png or .PNG files in the current folder, # sets all bytes at offsets [0x054, 0xa00] to 0 # and overwrites the files back. temp_file_ascii=outfile.txt temp_file_bin=outfile.png target_dir=. start_bytes=0x054 stop_bytes=0xa00 len_bytes=$stop_bytes-$start_bytes for file in $(find "$target_dir" -name "*.png") #TODO: -name "*.PNG") do # Copy first part of the file unchanged. xxd -p -s $start_bytes "$file" > $temp_file_ascii # Create some zero bytes, followed by 'a', # because I don't know how to add just zeroes. echo "$len_bytes: 41" | xxd -r >> $temp_file_ascii # Copy the rest of the input file. # ?? mv outfile.png "$file" done
EDIT: the finished script, using the accepted answer:
#!/bin/sh if [ "$#" != 3 ] then echo "Usage: " echo "break_png.sh <target_dir> <start_offset> <num_zeroed_bytes>" exit fi for file in $(find "$1" -name "*.png") do dd if=/dev/zero of=$file bs=1 seek=$(($2)) count=$(($3)) conv=notrunc done