Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This destroys SEGA Genesis games by writing random bytes over the code.
def randomchar
$rand.rand((0..255)).chr
end
def wreck!(data,iterations)
randrange = Range.new(400,data.length)
iterations.times do |i|
data[$rand.rand(randrange)] = randomchar
end
end
def valforbyte(data,byteindex)
data.byteslice(byteindex).unpack('C')[0]
end
def chksum(data)
sum=0
256.upto(data.length/2-1) do |word|
byte=word*2
sum+=valforbyte(data,byte)<<8
sum+=valforbyte(data,byte+1)
end
sum & 0xffff
end
def fix_chksum!(data)
chk = chksum(data)
data[398] = (chk >> 8).chr
data[399] = (chk & 0xff).chr
end
if ARGV.count < 2
puts 'Usage: ruby genesis-filewreck.rb infile outfile [iterations=200] [nofix]'
exit
end
$rand = Random.new
infile = ARGV[0]
outfile = ARGV[1]
iterations = ARGV.count > 2 ? ARGV[2].to_i : 200
data = IO.binread(infile)
wreck!(data,iterations)
fix_chksum!(data) unless ARGV.count > 3 && ARGV[3]=='nofix'
IO.binwrite(outfile,data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.