protected override byte FuzzValue(BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode, byte value) { byte fuzz = (byte)_random.Next(Config.MinByteValue, Config.MaxByteValue); byte ret = value; switch (mode) { case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Add: ret += fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.And: ret &= fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Or: ret |= fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Overwrite: ret = fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Xor: ret ^= fuzz; break; } return(ret); }
protected override char FuzzValue(BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode, char value) { ushort fuzz = (ushort)_random.Next(Config.MinValue, Config.MaxValue); ushort ret = (ushort)value; switch (mode) { case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Add: ret += fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.And: ret &= fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Or: ret |= fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Overwrite: ret = fuzz; break; case BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Xor: ret ^= fuzz; break; } return((char)ret); }
protected override bool FuzzValue(BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode, bool value) { return(!value); }
protected abstract U FuzzValue(BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode, U value);
protected override void OnInput(DataFrames.DataFrame frame) { DataNode[] nodes = frame.SelectNodes(SelectionPath); DataFrame preFuzz = null; bool fuzzed = false; if (nodes.Length > 0) { if (Config.LogPackets) { preFuzz = frame.CloneFrame(); } } foreach (DataNode node in nodes) { U[] data = NodeToArray(node); if (data == null) { LogVerbose(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_IgnoringData, node.Name); continue; } int fuzzLength = FuzzerUtils.GetFuzzLength(data.Length, Config.FuzzStart, Config.FuzzLength); if (fuzzLength > 0) { int points = GetPointCount(fuzzLength); if (Config.LogFuzzText) { LogVerbose(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_FuzzCount, points); } while (points > 0) { int pos = _random.Next(Config.FuzzStart, Config.FuzzStart + fuzzLength); BaseRandomArrayFuzzerConfig.FuzzCombinationMode mode = Config.CombinationMode; if (mode == BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Random) { mode = (BaseRandomArrayFuzzerConfig.FuzzCombinationMode)_random.Next((int)BaseRandomArrayFuzzerConfig.FuzzCombinationMode.Max); } if ((pos >= 0) && (pos < data.Length)) { U value = FuzzValue(mode, data[pos]); if (!value.Equals(data[pos])) { fuzzed = true; if (Config.LogFuzzText) { LogInfo(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_FuzzInfo, pos, data[pos], value); } } data[pos] = value; } points--; } node.ReplaceNode(ArrayToNode(data, node)); } } if (fuzzed) { if (Config.LogPackets) { Graph.DoLogPacket(String.Format(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_PreFuzzInfo, Name), Config.Color, preFuzz, Config.ConvertToBytes); Graph.DoLogPacket(String.Format(CANAPE.NodeLibrary.Properties.Resources.BaseRandomArrayFuzzer_PostFuzzInfo, Name), Config.Color, frame, Config.ConvertToBytes); } } WriteOutput(frame); }