public IoElement Decode(IBitReader reader)
        {
            byte num = reader != null?reader.ReadByte() : throw new ArgumentNullException(nameof(reader));

            IoProperty[] ioPropertyArray1 = Encoding8.Decode(reader);
            IoProperty[] ioPropertyArray2 = Encoding16.Decode(reader);
            IoProperty[] ioPropertyArray3 = Encoding32.Decode(reader);
            IoProperty[] ioPropertyArray4 = Encoding64.Decode(reader);
            return(new IoElement(num, ((IEnumerable <IoProperty>)ioPropertyArray1).Concat(ioPropertyArray2).Concat(ioPropertyArray3).Concat(ioPropertyArray4)));
        }
 public static T Decode <T>(this IEncoding <T> encoding, byte[] buffer)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer, false))
         return(encoding.Decode(memoryStream));
 }
 public static T Decode <T>(this IEncoding <T> encoding, Stream stream)
 {
     using (IBitReader suitableBitReader = stream.CreateSuitableBitReader())
         return(encoding.Decode(suitableBitReader));
 }
Esempio n. 4
0
        public int Compile()
        {
            Stream s = null;

            OutputFile = Path.GetFullPath(OutputFile);
            string directory = Path.GetDirectoryName(OutputFile);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            if (Decode && Archive)
            {
                if (!Directory.Exists(OutputFile) || args.Length != 1)
                {
                    Console.Error.WriteLine("Usage: KeyCompiler.exe -decode -archive -out <directory> <archive>");

                    return(1);
                }

                s = File.Open(args [0], FileMode.Open, FileAccess.Read);

                try {
                    return(UnpackArchive(s, OutputFile));
                } finally {
                    s.Close();
                }
            }
            else if (Decode)
            {
                if (args.Length != 1)
                {
                    Console.Error.WriteLine("Usage: KeyCompiler.exe -decode -out <file.skm> <file.sk>");

                    return(1);
                }

                s = File.Open(args [0], FileMode.Open, FileAccess.Read);
                encoding.Decode(out keymask, out statebit,
                                out defaultMap, out shiftedMap, s);
                s.Close();

                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                Decompile(s);
                s.Close();
            }
            else if (Archive)
            {
                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                CreateArchive(s, args);
                s.Close();
            }
            else
            {
                int parseResult;

                this.source = args [0];
                parseResult = Parse(this.source);

                if (parseResult != 0)
                {
                    Console.Error.WriteLine("Failed to parse file `{0}'", this.source);
                    return(parseResult);
                }

                Console.WriteLine("Encoding to `{0}'...", OutputFile);

                s = File.Open(OutputFile, FileMode.Create, FileAccess.Write);
                encoding.Encode(keymask, statebit, defaultMap, shiftedMap, s);
            }

            return(0);
        }