Skip to content

javierhonduco/corruption_monkey

Repository files navigation

Corruption monkey Build Status Gem Version

TL;DR: do 🔬 with backups (and 🐒)

This Ruby library (and CLI) provides an easy way to flip bits in a provided file.

It was built in order to corrupt database backups and test if our current and future tools work and calculate their coverage.

Local installation

$ gem install corruption_monkey

or

$ git clone https://github.com/Shopify/corruption_monkey && cd corruption_monkey
$ rake install

CLI

# flip a bit in a specific bit index
$ flip <file> <position>

# flip a bit in some part of the file
$ flip <file> <percent>%

# flip a bit... somewhere ¯\_(ツ)_/¯
$ flip <file> chaos

# show help message with this examples
$ flip [help]

API

require 'tempfile'
require 'logger'
require 'corruption_monkey'

file = Tempfile.new('whatever')
file_path = file.path
logger = Logger.new(nil)

# flip a bit in a specific bit index
BitFlipper.random_bit_flip(file_path, bit: 40, logger: logger)

# flip a bit in some part of thefile
BitFlipper.flip_in_range(file_path, percentile: 4, logger: logger)

# flip a bit... somewhere ¯\_(ツ)_/¯
BitFlipper.random_bit_flip(file_path, logger: logger)

Extra

You can generate png glitch art, too. image

(From https://en.wikipedia.org/wiki/Portable_Network_Graphics)

⚠️Caution!

This lib may improve your bit flipping skills.