Ejemplo n.º 1
0
 public override void Write(aBinaryWriter writer, string value)
 {
     aError.Check<ArgumentException>(value.Length <= Byte.MaxValue, "String value is too long for a BSTR.", "value");
     writer.Write8((byte)value.Length);
     writer.WriteString(value);
 }
Ejemplo n.º 2
0
 public override void Write(aBinaryWriter writer, string value)
 {
     base.Write(writer, value);
     writer.WriteChar('\0');
 }
Ejemplo n.º 3
0
 public override void Write(aBinaryWriter writer, string value)
 {
     aError.Check<ArgumentException>(value.Length <= UInt16.MaxValue, "String value is too long for a WSTR.", "value");
     writer.Write16((ushort)value.Length);
     writer.WriteString(value);
 }
Ejemplo n.º 4
0
 public override void Write(aBinaryWriter writer, string value)
 {
     writer.WriteString(value);
     writer.WriteChar('\0');
 }
Ejemplo n.º 5
0
 public abstract void Write(aBinaryWriter writer, string value);
Ejemplo n.º 6
0
 public override void Write(aBinaryWriter writer, string value)
 {
     if (value.Length > mMultiple) {
         value = value.Substring(0, mMultiple);
     }
     writer.WriteString(value);
     var count = mMultiple - value.Length;
     while (count-- > 0) {
         writer.WriteChar('\0');
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] arguments)
        {
            Message("doomwadcorrupter v{0} arookas", new Version(0, 1, 12));
            Separator();
            if (arguments == null || arguments.Length < 2) {
                Message("Usage: doomwadcorrupter <input.wad> <output.wad> [options]");
                Message();
                Message("Options:");
                Message("    -start <value>");
                Message("    -end <value>");
                Message("    -inc <value>");
                Message("    -mode <type> [<value>]");
                Message("    -skip <filter> [<filter> [...]]");
                Message("    -only <filter> [<filter> [...]]");
                Message("    -zdoom");
                Message();
                Message("For more detailed instructions, refer to the official repo page.");
                Pause();
                Exit(false);
            }
            var inputWAD = arguments[0];
            var outputWAD = arguments[1];
            cmd = new aCommandLine(arguments.Skip(2).ToArray());
            options = new CorrupterOptions(cmd);
            DisplayOptions(inputWAD, outputWAD);

            int lumpCount;
            var lumpsCorrupted = 0;
            var lumpsSkipped = 0;
            var bytesCorrupted = 0;
            rnd = new Random((uint)options.CorruptSeed);
            var timeTaken = Stopwatch.StartNew();
            using (var instream = OpenWAD(inputWAD)) {
                var reader = new aBinaryReader(instream, Endianness.Little, Encoding.ASCII);

                // header
                var wadType = reader.ReadString(4);

                if (wadType != "IWAD" && wadType != "PWAD") {
                    Error("Input file is not a DOOM WAD.");
                }

                lumpCount = reader.ReadS32();
                var directoryOffset = reader.ReadS32();

                // directory
                reader.Goto(directoryOffset);
                var lumps = aCollection.Initialize(lumpCount, () => new Lump(reader));

                using (var outstream = CreateWAD(outputWAD)) {
                    var writer = new aBinaryWriter(outstream, Endianness.Little, Encoding.ASCII);
                    // header
                    writer.WriteString(wadType);
                    writer.WriteS32(lumpCount);
                    writer.WriteS32(directoryOffset);

                    // data
                    var corruptBuff = new byte[options.Increment];
                    var startBuff = new byte[options.Start];
                    var ns = LumpNamespace.Global;

                    foreach (var lump in lumps) {
                        reader.Goto(lump.Start);
                        writer.Goto(lump.Start);
                        CheckNamespaceMarker(lump, ref ns);
                        if (options.Filter.IsCorruptable(lump.Name, ns) && !(options.ZDOOM && IsZDOOMLump(lump.Name))) {
                            ++lumpsCorrupted;
                            var i = options.Start;
                            var end = options.End ?? lump.Length;
                            if (i > 0) {
                                var count = (int)System.Math.Min(lump.Length, i);
                                reader.Read(startBuff, count);
                                writer.Write8s(startBuff, count);
                            }
                            while (i < lump.Length && i < end) {
                                Status("Corrupting '{0}'... (0x{1:X8} / 0x{2:X8})", lump.Name, i, lump.Length);
                                var count = (int)System.Math.Min(lump.Length - i, options.Increment);
                                reader.Read(corruptBuff, count);
                                CorruptByte(ref corruptBuff[0], options.CorruptMode, options.CorruptValue);
                                writer.Write8s(corruptBuff, count);
                                ++bytesCorrupted;
                                i += count;
                            }
                        }
                        else {
                            ++lumpsSkipped;
                            writer.Write8s(reader.Read8s(lump.Length));
                        }
                    }

                    // directory
                    writer.Goto(directoryOffset);
                    foreach (var lump in lumps) {
                        Status("Writing lump directory for '{0}'...", lump.Name);
                        lump.ToStream(writer);
                    }
                }
            }

            timeTaken.Stop();
            Status("Finished corrupting.");
            Message();
            Separator();
            Message("                       Files : {0}", lumpCount);
            Message("             Files corrupted : {0}", lumpsCorrupted);
            Message("               Files skipped : {0}", lumpsSkipped);
            Message("Bytes mercilessly sacrificed : {0}", bytesCorrupted);
            Message("                  Time taken : {0}", timeTaken.Elapsed.ToString("g"));
            Message("                 Finished at : {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Pause();
        }
Ejemplo n.º 8
0
 public void ToStream(aBinaryWriter writer)
 {
     writer.WriteS32(Start);
     writer.WriteS32(Length);
     writer.WriteString<aCSTR>(Name, 8);
 }
Ejemplo n.º 9
0
 public BmsWriter(Stream stream)
 {
     mWriter = new aBinaryWriter(stream, Endianness.Big);
 }