コード例 #1
0
 /// <summary>
 /// Fuzzer constructor
 /// </summary>
 /// <param name="stream">Stream</param>
 /// <param name="config">Mutations</param>
 public FuzzingStream(Stream stream, IGetPatch config)
 {
     _RealOffset = 0;
     _Source     = stream;
     Config      = config;
     _Original   = new MemoryStream();
     _Log        = new List <PatchChange>();
     _Buffer     = new List <byte>();
     SampleId    = Guid.NewGuid();
     Variables   = new VariableCollection <string, object>();
     if (Config != null)
     {
         Config.InitFor(this);
     }
 }
コード例 #2
0
ファイル: FMain.cs プロジェクト: naylamp6/TuringMachine
        void SaveSelectedInputWith(bool toClipbard, IGetPatch config)
        {
            if (gridInput.SelectedRows.Count != 1)
            {
                return;
            }

            FuzzerStat <IFuzzingInput> inp = (FuzzerStat <IFuzzingInput>)gridInput.SelectedRows[0].DataBoundItem;

            if (inp == null)
            {
                return;
            }

            byte[] stream = inp.Source.GetStream();
            if (stream == null)
            {
                return;
            }

            if (toClipbard)
            {
                // Clipboard
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("byte[] payload = new byte[]");
                sb.Append("{");

                PatchChange[] logs = null;
                if (config != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                        using (FuzzingStream fzs = new FuzzingStream(stream, config))
                        {
                            fzs.CopyTo(ms);
                            stream = ms.ToArray();
                            logs   = fzs.Log;
                        }
                }

                for (int x = 0, off = 0, v = 0, m = stream.Length; x < m; x++, v++, off++)
                {
                    byte b = stream[x];
                    if (x != 0)
                    {
                        sb.Append(", ");
                    }

                    if (logs != null)
                    {
                        foreach (PatchChange ch in logs)
                        {
                            if (off == ch.Offset)
                            {
                                off -= ch.Remove;
                                if (ch.Append != null)
                                {
                                    off += ch.Append.Length;
                                }

                                sb.AppendLine();
                                sb.AppendLine("\t/* " +
                                              (string.IsNullOrEmpty(ch.Description) ? "" : ch.Description + " ") +
                                              (ch.Append == null ? "0" : ch.Append.Length.ToString()) + " bytes */");

                                sb.Append("\t" + "".PadLeft(6 * v, ' '));
                            }
                        }
                    }

                    if (v == 0 || v % 20 == 0)
                    {
                        sb.AppendLine();
                        sb.Append("\t");
                        v = 0;
                    }
                    sb.Append("0x" + b.ToString("x2"));
                }

                sb.AppendLine();
                sb.Append("};");
                Clipboard.SetText(sb.ToString());
                return;
            }

            // File
            using (SaveFileDialog s = new SaveFileDialog()
            {
                Filter = "Dat file|*.dat",
                DefaultExt = "*.dat",
            })
            {
                if (s.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    if (File.Exists(s.FileName))
                    {
                        File.Delete(s.FileName);
                    }

                    using (FileStream fs = File.OpenWrite(s.FileName))
                    {
                        if (config != null)
                        {
                            using (Stream fzs = new FuzzingStream(stream, config))
                                fzs.CopyTo(fs);
                        }
                        else
                        {
                            fs.Write(stream, 0, stream.Length);
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Fuzzer constructor
 /// </summary>
 /// <param name="stream">Stream</param>
 /// <param name="config">Mutations</param>
 public FuzzingStream(byte[] stream, IGetPatch config) : this(new MemoryStream(stream), config)
 {
 }