/// <summary> /// Init for /// </summary> /// <param name="stream">Stream</param> internal void InitFor(FuzzingStream stream, int index) { var s = new Step { // Max changes MaxChanges = MaxChanges == null ? 1 : Math.Max(1, (int)MaxChanges.Get()) }; if (FuzzPercentType == EFuzzingPercentType.PeerStream) { // Fill indexes var length = stream.Length; var changes = Math.Min(s.MaxChanges, (long)(length * (FuzzPercent == null ? 100D : FuzzPercent.Get()) / 100.0)); while (changes > s.FuzzIndex.Count) { long value; do { value = RandomHelper.GetRandom(0, length); }while (s.FuzzIndex.Contains(value) || ValidOffset?.ItsValid(value) == false); s.FuzzIndex.Add(value); } s.FuzzIndex.Sort(); } stream.Variables[index] = s; }
/// <summary> /// Get next mutation change (if happend) /// </summary> /// <param name="stream">Stream</param> /// <param name="offset">Offset</param> /// <param name="index">Index</param> public MutationalChange Get(FuzzingStream stream, long offset, int index) { if (ValidOffset?.ItsValid(offset) == false) { return(null); } switch (FuzzPercentType) { case EFuzzingPercentType.PeerByte: { // Check Max changes if (MaxChanges != null && stream.Log.Length >= MaxChanges.Get()) { return(null); } // Check Percent if (FuzzPercent != null) { var value = FuzzPercent.Get(); if (!RandomHelper.IsRandomPercentOk(value)) { return(null); } } // Get Item return(Changes.Get()); } case EFuzzingPercentType.PeerStream: { // Check Max changes var s = (Step)stream.Variables[index]; if (stream.Log.Length >= s.MaxChanges) { return(null); } if (!s.FuzzIndex.Contains(offset)) { return(null); } // Get Item return(Changes.Get()); } default: { throw new ArgumentException(nameof(FuzzPercentType)); } } }