Skip to content

Instantly share code, notes, and snippets.

@tsulej
Created January 14, 2015 20:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsulej/6a62f6ad7f5d841ea5cc to your computer and use it in GitHub Desktop.
Save tsulej/6a62f6ad7f5d841ea5cc to your computer and use it in GitHub Desktop.
Glitching scripts
#!/bin/sh
# author: tsulej 2015 // glitching tools
# e-mail: tomeksul@gmail.com
# Script traverse through the file changes one byte and saves result. Outcome: files with changed first, second, third, ..., nth byte to choosen value
# usage:
# bash ./all_bytes.sh <filename.ext> <hex value, two letters: 0..f>
# warning: use files with small size (<20kb)
# example, suppose we have image.gif file with size 999 bytes:
# bash ./all_bytes.sh image.gif aa
# result is 999 files: 001_image.gif (first byte set to 'aa'), 002_image.gif (second byte set to 'aa'), ..., 999_image.gif (999th byte set to 'aa')
# dependencies: sed, xxd, change_byte.sh
# can be used under linux or cygwin
size=`stat -c '%s' "$1"`
name=`echo "$1" | cut -d '.' -f 1`
ext=`echo "$1" | cut -d '.' -f 2`
for i in `seq -w 1 $size`
do
echo "Processing byte $i"
bash ./change_byte.sh "$1" $i $2
mv "$name".res.$ext "$i"_"$name".$ext
done
#!/bin/sh
# author: tsulej 2015 // glitching tools
# e-mail: tomeksul@gmail.com
# bash script which changes choosen byte in the binary file to a value
# usage:
# bash ./change_byte.sh <filename.ext> <byte number> <hex value, two letters: 0..f>
# result is saved in the file "filename.res.ext"
# example, change 1000th byte to '9d' value:
# bash ./change_byte.sh image.jpg 1000 9d
# result save to image.res.jpg
# dependencies: sed, xxd
# can be used under linux or cygwin
echo -n "file $1... "
# $1 - filename to process
# get name and extention
name=`echo "$1" | cut -d '.' -f 1`
ext=`echo "$1" | cut -d '.' -f 2`
# produce pure hex, each byte in other line
# save it in the /name/.hex file
xxd -ps -c 1 < "$1" > "$name".hex
# replace bytes in line $2 with byte from $3
sed -s "$2 s/^../$3/" < "$name".hex > "$name".2.hex
# save to binary back
xxd -r -ps -c 1 < "$name".2.hex > "$name".res.$ext
# remove all tmp files
rm "$name".hex
rm "$name".2.hex
echo "processed";
#!/bin/sh
# author: tsulej 2015 // glitching tools
# e-mail: tomeksul@gmail.com
# bash script for batch byte change (see change_byte.sh)
# usage:
# bash ./process_files.sh <ext - file extension> <byte number> <hex value, two letters: 0..f>
# example, change 1000th byte to 'f3' value in all png files in directory:
# bash ./process_files.sh png 1000 f3
#
# dependencies: sed, xxd, change_byte.sh
# can be used under linux or cygwin
for i in *.$1
do
echo "Processing file: $i"
bash ./change_byte.sh "$i" $2 $3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment