fout = open(newfile, "a") fout.write(restoffile) fout.close() if progname != None: print "Playing %s..." % newfile try: playit(newfile, timeout) except KeyboardInterrupt: print "User interrupted, cleaning up." os.system("killall -9 %s" % progname) sys.exit() count = count + 1 elif filetype == "wav": oldwav = fuzzwave.open(sourcefile, "rb") oldparams = oldwav.getparams() print oldparams numframes = oldwav.getnframes() # shouldn't be a problem given a small wav file data = oldwav.readframes(numframes) oldwav.close() for i in range(reps): newfile = "output" + str(count) + ".wav" newwav = fuzzwave.open(newfile, "wb") # this mostly tends to just make things not play. # if random.randint(0,2): # print "Fuzzing channels" # newwav.setnchannels(random.randint(-10,10)) # else:
def Fuzz(iphone_player, ops, args): reps = ops.reps count = 0 logfile = ops.logfile sourcefile = ops.sourcefile timeout = ops.timeout itunes = ops.itunes filetype = ops.filetype fuzzmax = ops.fuzzmax if sourcefile == None: print "ERROR: You need to define at least the source file." print parser.print_help() sys.exit(1) if filetype == "ogg": for i in range(reps): check = random.randint(0, 2) if check == 0: print "fuzzing tags." numtofuzz = random.randint(1, fuzzmax) print "fuzzing %d tags" % numtofuzz newfile = "output" + str(count) + ".ogg" shutil.copyfile(sourcefile, newfile) # try: # newtags = ogg.vorbis.VorbisComment(fuzz_ogg_tags(vcomments, numtofuzz)) # newtags.write_to(newfile) # ignore conversion breakage # except (UnicodeEncodeError, ValueError): pass count = count + 1 else: print "fuzzing frame." newfile = "output" + str(count) + ".ogg" shutil.copyfile(sourcefile, newfile) fout = open(newfile, "wb") # newheader,restoffile = fuzz_ogg_frame(sourcefile) # keys() results are unsorted, so put them back in order page = "" # for key in sorted(newheader.keys()): # page += str(newheader[key]) page_with_crc = ogg_page_checksum_set(page) fout.write(page_with_crc) fout.close() fout = open(newfile, "a") # fout.write(restoffile) fout.close() print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() count = count + 1 elif filetype == "flac": numtags = len(comments) for i in range(reps): check = random.randint(0, 2) if check == 0: print "fuzzing tags." numtofuzz = random.randint(1, fuzzmax) print "fuzzing %d tags" % numtofuzz newfile = "output" + str(count) + ".flac" shutil.copyfile(sourcefile, newfile) fh = mutagen.flac.FLAC(newfile) newfh = fuzz_flac_tags(comments, fh, numtofuzz) try: newfh.save() print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() except: failed = True os.remove(newfile) count = count + 1 elif filetype == "mp3": numtags = len(texttags) for i in range(reps): check = random.randint(0, 2) if check == 20: print "fuzzing tags." numtofuzz = random.randint(1, fuzzmax) newfile = "output" + str(count) + ".mp3" shutil.copyfile(sourcefile, newfile) oldtags = mutagen.id3.ID3(newfile) newtags = fuzz_mp3_tags(oldtags, texttags, numtofuzz) failed = False try: newtags.save(newfile, 2) except: print "Failed to save %s" % newfile failed = True os.remove(newfile) count = count + 1 else: print "fuzzing frame." newfile = "output" + str(count) + ".mp3" shutil.copyfile(sourcefile, newfile) fout = open(newfile, "wb") newheader, restoffile = fuzz_mp3_frame(sourcefile) page = "" for key in sorted(newheader.keys()): page += str(newheader[key]) fout.write(page) fout.close() fout = open(newfile, "a") fout.write(restoffile) fout.close() print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() count = count + 1 elif filetype == "wav": oldwav = fuzzwave.open(sourcefile, "rb") oldparams = oldwav.getparams() print oldparams numframes = oldwav.getnframes() # shouldn't be a problem given a small wav file data = oldwav.readframes(numframes) oldwav.close() for i in range(reps): newfile = "output" + str(count) + ".wav" newwav = fuzzwave.open(newfile, "wb") # this mostly tends to just make things not play. # if random.randint(0,2): # print "Fuzzing channels" # newwav.setnchannels(random.randint(-10,10)) # else: newwav.setnchannels(oldwav.getnchannels()) if random.randint(0, 2): print "Fuzzing sampwidth" newwav.setsampwidth(random.randint(-1024, 1024)) else: newwav.setsampwidth(oldwav.getsampwidth()) if random.randint(0, 2): print "Fuzzing framerate" newwav.setframerate(random.randint(-1024, 50000)) else: newwav.setframerate(oldwav.getframerate()) if random.randint(0, 2): print "Fuzzing frame number" newwav.setnframes(random.randint(-1024, 50000)) else: newwav.setnframes(oldwav.getnframes()) if random.randint(0, 10): print "Fuzzing compression type" newwav.setcomptype(randstring(), randstring()) else: newwav.setcomptype(oldwav.getcomptype(), "lalala") print "Writing out data" try: newwav.writeframesraw(data) # There's potential for some divide-by-zeroes here except: print "Failed to write that one out" newwav.close() if 1: print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() count = count + 1 elif filetype == "aiff": oldaiff = fuzzaifc.open(sourcefile, "rb") oldparams = oldaiff.getparams() print oldparams numframes = oldaiff.getnframes() # shouldn't be a problem given a small file data = oldaiff.readframes(numframes) oldaiff.close() for i in range(reps): newfile = "output" + str(count) + ".aiff" newaiff = fuzzaifc.open(newfile, "wb") if random.randint(0, 2): print "Fuzzing channels" newaiff.setnchannels(random.randint(-10, 10)) else: newaiff.setnchannels(oldaiff.getnchannels()) if random.randint(0, 2): print "Fuzzing sampwidth" newaiff.setsampwidth(random.randint(-1024, 1024)) else: newaiff.setsampwidth(oldaiff.getsampwidth()) if random.randint(0, 2): print "Fuzzing framerate" newaiff.setframerate(random.randint(-1024, 50000)) else: newaiff.setframerate(oldaiff.getframerate()) if random.randint(0, 2): print "Fuzzing frame number" newaiff.setnframes(random.randint(-1024, 50000)) else: newaiff.setnframes(oldaiff.getnframes()) if random.randint(0, 10): print "Fuzzing compression type" newaiff.setcomptype(randstring(), randstring()) else: newaiff.setcomptype(oldaiff.getcomptype(), "lalala") print "Writing out data" try: newaiff.writeframesraw(data) newaiff.close() # There's potential for some divide-by-zeroes here except: print "Failed to write that one out" print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() count = count + 1 elif filetype == "spx": for i in range(reps): print "fuzzing frame." newfile = "output" + str(count) + ".spx" shutil.copyfile(sourcefile, newfile) fout = open(newfile, "wb") newheader, restoffile = fuzz_speex_frame(sourcefile) page = "" for key in sorted(newheader.keys()): page += str(newheader[key]) page_with_crc = ogg_page_checksum_set(page) fout.write(page_with_crc) fout.close() fout = open(newfile, "a") fout.write(restoffile) fout.close() if 1: print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() count = count + 1 elif filetype == "mp4": numtags = len(qtatoms) for i in range(reps): check = random.randint(0, 2) if check == 0: print "fuzzing tags." numtofuzz = random.randint(1, fuzzmax) newfile = "output" + str(count) + ".mp4" shutil.copyfile(sourcefile, newfile) oldatoms = mutagen.mp4.MP4(newfile) newatoms = fuzz_qt_atoms(oldatoms, numtofuzz) failed = False try: newatoms.save() print "Playing %s..." % newfile try: iphone_player.PlayFile(newfile) except KeyboardInterrupt: print "User interrupted, cleaning up." sys.exit() except: print "Failed to save %s" % newfile failed = True os.remove(newfile) count = count + 1
fout = open(newfile, 'a') fout.write(restoffile) fout.close() if progname != None: print "Playing %s..." % newfile try: playit(newfile, timeout) except KeyboardInterrupt: print "User interrupted, cleaning up." os.system("killall -9 %s" % progname) sys.exit() count = count + 1 elif filetype == "wav": oldwav = fuzzwave.open(sourcefile, 'rb') oldparams = oldwav.getparams() print oldparams numframes = oldwav.getnframes() # shouldn't be a problem given a small wav file data = oldwav.readframes(numframes) oldwav.close() for i in range(reps): newfile = 'output' + str(count) + '.wav' newwav = fuzzwave.open(newfile, 'wb') # this mostly tends to just make things not play. # if random.randint(0,2): # print "Fuzzing channels" # newwav.setnchannels(random.randint(-10,10)) # else: