public void TestFuzz()
        {
            string xml = @"
<Peach>
	<DataModel name='TheDataModel'>
		<Number name='num' size='32' signed='false' endian='big'>
			<Relation type='offset' of='blob'/>
		</Number>
		<String name='str'/>
		<Blob name='blob'/>
	</DataModel>

	<StateModel name='TheState' initialState='Initial'>
		<State name='Initial'>
			<Action type='output'>
				<DataModel ref='TheDataModel'/>
			</Action>
		</State>
	</StateModel>

	<Test name='Default'>
		<StateModel ref='TheState'/>
		<Publisher class='Null'/>
		<Strategy class='Sequential'/>
	</Test>
</Peach>";

            PitParser parser = new PitParser();

            Dom.Dom dom = parser.asParser(null, new MemoryStream(ASCIIEncoding.ASCII.GetBytes(xml)));
            dom.tests[0].includedMutators = new List <string>();
            dom.tests[0].includedMutators.Add("StringMutator");

            RunConfiguration config = new RunConfiguration();

            Engine e = new Engine(null);

            e.startFuzzing(dom, config);

            Assert.AreEqual(2380, dataModels.Count);

            foreach (var dm in dataModels)
            {
                var val = dm.Value;
                var len = val.LengthBits;
                Assert.GreaterOrEqual(len, 32);

                val.Seek(0, SeekOrigin.Begin);
                var rdr = new BitReader(val);
                rdr.BigEndian();
                uint offset = rdr.ReadUInt32();

                Assert.AreEqual(len, offset * 8);
            }
        }
Example #2
0
        public void ReadWriteNumbersOddOffset()
        {
            BitStream bs = new BitStream();
            BitWriter w  = new BitWriter(bs);
            BitReader r  = new BitReader(bs);

            w.LittleEndian();
            r.LittleEndian();

            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);

            Assert.AreEqual(3, bs.LengthBits);
            Assert.AreEqual(3, bs.PositionBits);

            //Max
            w.WriteSByte(sbyte.MaxValue);

            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(0, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());
            Assert.AreEqual(1, r.ReadBit());

            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MaxValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MaxValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(67305985);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(67305985, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MaxValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MaxValue, r.ReadInt64());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteByte(byte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(byte.MaxValue, r.ReadByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt16(ushort.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(ushort.MaxValue, r.ReadUInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt32(UInt32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt32.MaxValue, r.ReadUInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt64(UInt64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt64.MaxValue, r.ReadUInt64());


            //Min
            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteSByte(sbyte.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MinValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MinValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MinValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MinValue, r.ReadInt64());

            // BIG ENDIAN //////////////////////////////////////////

            bs.SetLength(0);
            r.BigEndian();
            w.BigEndian();

            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);

            //Max
            w.WriteSByte(sbyte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MaxValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MaxValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(67305985);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(67305985, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MaxValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MaxValue, r.ReadInt64());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteByte(byte.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(byte.MaxValue, r.ReadByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt16(ushort.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(ushort.MaxValue, r.ReadUInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt32(UInt32.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt32.MaxValue, r.ReadUInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteUInt64(UInt64.MaxValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(UInt64.MaxValue, r.ReadUInt64());

            //Min
            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteSByte(sbyte.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(sbyte.MinValue, r.ReadSByte());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt16(short.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(short.MinValue, r.ReadInt16());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt32(Int32.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int32.MinValue, r.ReadInt32());

            bs.SetLength(0);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteBit(1);
            w.WriteInt64(Int64.MinValue);
            bs.SeekBits(3, System.IO.SeekOrigin.Begin);
            Assert.AreEqual(Int64.MinValue, r.ReadInt64());
        }