Inheritance: System.IO.BinaryReader
コード例 #1
0
        private byte[] GetContentHelperFunc(FileStream fStream)
        {
            byte[] buffer = new byte[FileSize];            //Will contain compressed data
            fStream.Seek(FileOffset, SeekOrigin.Begin);
            fStream.Read(buffer, 0, (int)FileSize);

            try
            {
                MemoryStream      mStream = new MemoryStream(buffer);
                zlib.ZInputStream zinput  = new zlib.ZInputStream(mStream);

                List <byte> dBuffer = new List <byte>(); //decompressed buffer, arraylist to my knowledge...

                //This could be optimized in the future by reading a block and adding it to our arraylist..
                //which would be much faster, obviously
                int data;
                while ((data = zinput.Read()) != -1)
                {
                    dBuffer.Add((byte)data);
                }

                return(dBuffer.ToArray());
            }
            catch
            {
                //it's not compressed, just return original content
                return(buffer);
            }
        }
コード例 #2
0
        public static void uncompressFile(string inFile, string outFile)
        {
            int data = 0;
            int stopByte = -1;
            System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
            ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read));
            while (stopByte != (data = inZStream.Read()))
            {
                byte _dataByte = (byte)data;
                outFileStream.WriteByte(_dataByte);
            }

            inZStream.Close();
            outFileStream.Close();
        }
コード例 #3
0
        public static void DecompressFile(string inFile, string outFile)
        {
            int data;
            const int stopByte = -1;
            var outFileStream = new FileStream(outFile, FileMode.Create);
            var inZStream = new ZInputStream(File.Open(inFile, FileMode.Open, FileAccess.Read));

            while (stopByte != (data = inZStream.Read()))
            {
                var databyte = (byte) data;
                outFileStream.WriteByte(databyte);
            }

            inZStream.Close();
            outFileStream.Close();
        }
コード例 #4
0
        /// <summary>
        /// Returns the content of the actual file (extracts from raf archive)
        /// </summary>
        public byte[] GetContent()
        {
            if (inMemory)
            {
                throw new Exception("Invalid call to GetContent, this entry is only in memory, and has not been linked to the DAT file yet.");
            }
            FileStream fStream = this.raf.GetDataFileContentStream();

            byte[] buffer = new byte[this.FileSize];            //Will contain compressed data
            fStream.Seek(this.FileOffset, SeekOrigin.Begin);
            fStream.Read(buffer, 0, (int)this.FileSize);

            try
            {
                MemoryStream      mStream = new MemoryStream(buffer);
                zlib.ZInputStream zinput  = new zlib.ZInputStream(mStream);

                List <byte> dBuffer = new List <byte>(); //decompressed buffer, arraylist to my knowledge...

                //This could be optimized in the future by reading a block and adding it to our arraylist..
                //which would be much faster, obviously
                int data = 0;
                while ((data = zinput.Read()) != -1)
                {
                    dBuffer.Add((byte)data);
                }
                //ComponentAce.Compression.Libs.zlib.ZStream a = new ComponentAce.Compression.Libs.zlib.ZStream();

                //File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), dBuffer.ToArray());
                return(dBuffer.ToArray());
            }
            catch
            {
                //it's not compressed, just return original content
                return(buffer);
            }
        }
コード例 #5
0
        private byte[] GetContentHelperFunc(FileStream fStream)
        {
            var buffer = new byte[FileSize]; //Will contain compressed data
            fStream.Seek(FileOffset, SeekOrigin.Begin);
            fStream.Read(buffer, 0, (int) FileSize);

            try
            {
                var mStream = new MemoryStream(buffer);
                var zinput = new ZInputStream(mStream);

                var dBuffer = new List<byte>(); //decompressed buffer, arraylist to my knowledge...

                //This could be optimized in the future by reading a block and adding it to our arraylist..
                //which would be much faster, obviously
                int data;
                while ((data = zinput.Read()) != -1)
                    dBuffer.Add((byte) data);

                return dBuffer.ToArray();
            }
            catch
            {
                //it's not compressed, just return original content
                return buffer;
            }
        }
コード例 #6
0
     public void uncompressFile(string inFile, string outFile)
     {
         try 
         {
             int data = 0;
             int stopByte = -1;
             System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
             ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read));
             while (stopByte != (data = inZStream.Read()))
             {
                 byte _dataByte = (byte)data;
                 outFileStream.WriteByte(_dataByte);
             }
 
             inZStream.Close();
             outFileStream.Close(); 
         }
         catch 
         {
             Client.Log("Unable to find a file to uncompress");
         }
         
     }
コード例 #7
0
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd = null;

            using (MemoryStream msSinkUnCompressed = new MemoryStream())
            {
                using(ZInputStream zOut = new ZInputStream(msSinkUnCompressed))
                {
                    zOut.Read(input, 0, input.Length);
                    msSinkUnCompressed.Seek(0L, SeekOrigin.Begin);
                    osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray());
                    zOut.Close();
                }
            }

            return osd;
        }
コード例 #8
0
ファイル: RAFArchive.cs プロジェクト: anirnet/raf-manager
        /// <summary>
        /// Dumps the content of the first .raf/.raf.dat archive seen in the given directory.
        /// Outputs to the given ostream
        /// </summary>
        public static bool Dump(string directory, StreamWriter ostream)
        {
            #region output_usage_header
            ostream.WriteLine("Experimental RAF Dumper by ItzWarty @ ItzWarty.com April 28 2011 10:00pm pst");
            ostream.WriteLine("RAF dogcumentation @ bit.ly/mSyYrR ");
            ostream.WriteLine("USAGE: RAF_DUMP (Or just double click executable)");
            ostream.WriteLine("Precondition: RAF_DUMP is sitting next to a Riot Archive File.");
            ostream.WriteLine("Postcondition: 'dump' folder created.  RAF extracted into folder.");
            #endregion
            //string dumpDir = @"C:\Riot Games\League of Legends\RADS\projects\lol_game_client\filearchives\0.0.0.28\dump\";
            
            //We write the file containing "name hash" next to our program.
            string hashesFile = Environment.CurrentDirectory + "\\hashes.txt";
            string hashesLog = "";

            //We write to this file saying what we don't compress
            string notcompressedsFile = Environment.CurrentDirectory + "\\nocompress.txt";
            string notcompressedsLog = "";

            string dumpDir = Environment.CurrentDirectory + "\\dump\\";
            String[] filesInDir = Directory.GetFiles(Environment.CurrentDirectory);
            String rafName = "";
            foreach (String fileName in filesInDir)
            {
                if (fileName.Split("\\").Last().EndsWith(".raf", StringComparison.InvariantCultureIgnoreCase))
                {
                    rafName = fileName;
                }
            }
            if (rafName == "")
            {
                ostream.WriteLine("Couldn't find RAF file!!");
                //ostream.WriteLine("This executable must be in the same folder as a *.raf and *.raf.dat file!");
                //ostream.WriteLine("Exiting... Press a key (or two) to exit");
                //ostream.ReadKey();
                return false;
            }
            ostream.WriteLine("Found RAF: " + rafName);
            RAFArchive raf = new RAFArchive(rafName);
            FileStream fStream = raf.GetDataFileContentStream();
            //DeflateStream dfStream = new DeflateStream(fStream, CompressionMode.Decompress);

            //int loggingOffset = 10; //No longer applicable since we aren't logging to system.out console directly
            List<RAFFileListEntry> files = raf.GetDirectoryFile().GetFileList().GetFileEntries();
            foreach (RAFFileListEntry entry in files)
            {
                //ostream.SetCursorPosition(0, 7);
                ostream.WriteLine("Dumping: " + entry.FileName.Split("\\").Last() + " ".Repeat(40));
                //ostream.SetCursorPosition(0, 8);
                ostream.WriteLine("  Data File Offset: $" + entry.FileOffset.ToString("x") + "; Size:" + entry.FileSize + " ($" + entry.FileSize.ToString("x") + ")" + " ".Repeat(40));
                //Console.SetCursorPosition(0, 7);
                //Console.WriteLine("  Expected FileName Checksum: $" + entry.StringNameHash.ToString("x") + "; Calculated:" + Adler32(entry.GetFileName).ToString("x")/*entry.GetFileName.GetHashCode().ToString("x")*/ + " ".Repeat(40));
                //Console.WriteLine("  To: " + dumpDir + entry.GetFileName+";;");
                hashesLog += entry.FileName + "|||" + entry.StringNameHash + "\n";
                //zlib.ad
                byte[] buffer = new byte[entry.FileSize];
                fStream.Seek(entry.FileOffset, SeekOrigin.Begin);
                fStream.Read(buffer, 0, (int)entry.FileSize);

                PrepareDirectory((dumpDir + entry.FileName).Replace("/", "\\"));
                try
                {
                    MemoryStream mStream = new MemoryStream(buffer);
                    zlib.ZInputStream zinput = new zlib.ZInputStream(mStream);

                    List<byte> dBuffer = new List<byte>(); //decompressed buffer, arraylist to my knowledge...
                    int data = 0;
                    while ((data = zinput.Read()) != -1)
                        dBuffer.Add((byte)data);
                    //ComponentAce.Compression.Libs.zlib.ZStream a = new ComponentAce.Compression.Libs.zlib.ZStream();

                    File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), dBuffer.ToArray());
                }
                catch
                {
                    notcompressedsLog += entry.FileName.ToLower() + "\n";
                    //Console.SetCursorPosition(2, loggingOffset++);
                    ostream.Write("UNABLE TO DECOMPRESS FILE, WRITING DEFLATED FILE:");
                    //Console.SetCursorPosition(4, loggingOffset++);
                    ostream.Write("  " + entry.FileName);
                    File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), buffer.ToArray());
                }
            }
            //Console.SetCursorPosition(0, 0);

            ostream.WriteLine("Write hashes and nocompress file");
            File.WriteAllText(hashesFile, hashesLog);
            File.WriteAllText(notcompressedsFile, notcompressedsLog);
            ostream.WriteLine("DONE!" + " ".Repeat(30));
            //fStream.Close();
            return true;
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
コード例 #9
0
ファイル: Syscalls.cs プロジェクト: meniz/WazeWP7
    //    public static int NOPH_ZLib_compress(int i_in_path, int i_in_file_name, int i_out_path, int i_out_file_name, int compression_level)
    //{
    // String in_path = CRunTime.charPtrToString(i_in_path);
    // String in_file_name = CRunTime.charPtrToString(i_in_file_name);
    // String out_path = CRunTime.charPtrToString(i_out_path);
    // String out_file_name = CRunTime.charPtrToString(i_out_file_name);
    // net.rim.device.api.compress.GZIPOutputStream zout = null;
    // javax.microedition.io.file.FileConnection fConnIn = null;
    // javax.microedition.io.file.FileConnection fConnOut = null;
    // Stream os = null;
    // Stream iis = null;
    // try {
    //       long in_file_size;
    //       fConnIn = (javax.microedition.io.file.FileConnection)Connector.open(in_path + "/" + in_file_name);
    //    fConnOut = (javax.microedition.io.file.FileConnection)Connector.open(out_path + "/" + out_file_name);
    //    if (!fConnOut.exists())
    //     fConnOut.create(); // create the file if it doesn't exist
    //    iis = fConnIn.openInputStream();
    //    in_file_size = fConnIn.fileSize();
    //    os = fConnOut.openOutputStream();
    //    zout = new net.rim.device.api.compress.GZIPOutputStream(os, compression_level, net.rim.device.api.compress.GZIPOutputStream.MAX_LOG2_WINDOW_LENGTH);
    //    // write into file
    //    for (long i = 0; i < in_file_size; i++){
    //     zout.write(iis.read());
    //    }
    //    // flush before end
    //    zout.flush();
    //    // success
    //    return 0;
    // }
    // catch (Exception e) {
    //  UIWorker.addUIEventLog("NOPH_ZLib_compress Exception in compressing "+ e.toString());
    // }finally {
    //    // try to close stream
    //    try{
    //    if(zout!=null)
    //          zout.close();
    //       if(fConnIn!=null)
    //       fConnIn.close();
    //       if(fConnOut!=null)
    //       fConnOut.close();
    //       if(os!=null)
    //       os.close();
    //       if(iis!=null)
    //       iis.close();
    //  }catch(Exception e){
    //      Console.WriteLine("zout.close()");
    //  }
    // }
    // return 1;
    //}
    public static int NOPH_ZLib_uncompress(int uncompressedAddr, int uncompressedSizeAddr, int compressedAddr, int compressedSize)
    {
        //todomt - do better job
        int uncompressedSizeRead = 0;
        FileStream fs = null;
        try
        {
        /*            var store = IsolatedStorageFile.GetUserStoreForApplication();
            CRunTimeMemoryInputStream mis = new CRunTimeMemoryInputStream(compressedAddr, compressedSize);
            fs = new IsolatedStorageFileStream("temp.gz", FileMode.Create, FileAccess.Write, store);
            int b = mis.read();
            while (b != -1)
            {
                fs.WriteByte((byte)b);
                b = mis.read();
            }

            fs.Close();

            fs = new IsolatedStorageFileStream("temp.gz", FileMode.Open, FileAccess.Read, store);
            ZInputStream zis = new ZInputStream(fs);*/
            CRunTimeMemoryInputStream mis = new CRunTimeMemoryInputStream(compressedAddr, compressedSize);
            ZInputStream zis = new ZInputStream(mis);

            int uncompressedSizeAllocated = CRunTime.memoryReadWord(uncompressedSizeAddr);

            int val = 0;
            while (((uncompressedAddr & 0x3) != 0) && (uncompressedSizeAllocated > 0) && ((val = zis.ReadByte()) != -1))
            {
                CRunTime.memoryWriteByte(uncompressedAddr++, val);
                ++uncompressedSizeRead;
                --uncompressedSizeAllocated;
            }

            while ((val != -1) && (uncompressedSizeAllocated > 3))
            {
                int i = 0;
                for (int j = 0; j < 4; j++)
                {
                    i = i << 8;

                    // replace the below with val = zis.ReadByte() & 0xff; if changing zlib implementation
                    val = zis.Read() & 0xff;

                    i |= val;
                }

                CRunTime.memoryWriteWord(uncompressedAddr, i);
                uncompressedAddr += 4;
                uncompressedSizeRead += 4;
                uncompressedSizeAllocated -= 4;
            }

            while ((uncompressedSizeAllocated > 0) && (val = zis.ReadByte()) != -1)
            {
                CRunTime.memoryWriteByte(uncompressedAddr++, val);
                ++uncompressedSizeRead;
                --uncompressedSizeAllocated;
            }

            CRunTime.memoryWriteWord(uncompressedSizeAddr, uncompressedSizeRead);

            return 1;
        }
        catch (Exception ex)
        {
            Logger.log("Exception: " + ex.ToString());
            Logger.log("compressedSize " + compressedSize + " uncompressedSizeRead " + uncompressedSizeRead + " Exception: " + ex);

            return 0;
        }
        finally
        {
            if (fs != null)
            {
                fs.Close();
            }
        }
    }
コード例 #10
0
        public void endElement(object ctx, string elementName)
        {
            CCTMXMapInfo pTMXMapInfo = this;
            byte[] buffer = pTMXMapInfo.CurrentString;

            if (elementName == "data" && (pTMXMapInfo.LayerAttribs & (int)TMXLayerAttrib.TMXLayerAttribBase64) != 0)
            {
                pTMXMapInfo.StoringCharacters = false;
                CCTMXLayerInfo layer = pTMXMapInfo.Layers.LastOrDefault();
                if ((pTMXMapInfo.LayerAttribs & ((int)(TMXLayerAttrib.TMXLayerAttribGzip) | (int)TMXLayerAttrib.TMXLayerAttribZlib)) != 0)
                {
                    using (MemoryStream ms = new MemoryStream(buffer, false))
                    {
                        //gzip compress
                        if ((pTMXMapInfo.LayerAttribs & (int)TMXLayerAttrib.TMXLayerAttribGzip) != 0)
                        {
                            using (GZipInputStream inStream = new GZipInputStream(ms))
                            {
                                using (var br = new BinaryReader(inStream))
                                {
                                    for (int i = 0; i < layer.m_pTiles.Length; i++)
                                        layer.m_pTiles[i] = br.ReadInt32();
                                }
                            }
                        }

                        //zlib
                        if ((pTMXMapInfo.LayerAttribs & (int)TMXLayerAttrib.TMXLayerAttribZlib) != 0)
                        {
                            using (ZInputStream inZStream = new ZInputStream(ms))
                            {
                                for (int i = 0; i < layer.m_pTiles.Length; i++)
                                {
                                    layer.m_pTiles[i] = inZStream.Read();
                                    inZStream.Read();
                                    inZStream.Read();
                                    inZStream.Read();
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < layer.m_pTiles.Length; i++)
                        layer.m_pTiles[i] = buffer[i * 4];
                }

                pTMXMapInfo.CurrentString = null;
            }
            else if (elementName == "map")
            {
                // The map element has ended
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyNone;
            }
            else if (elementName == "layer")
            {
                // The layer element has ended
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyNone;
            }
            else if (elementName == "objectgroup")
            {
                // The objectgroup element has ended
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyNone;
            }
            else if (elementName == "object")
            {
                // The object element has ended
                pTMXMapInfo.ParentElement = (int)TMXProperty.TMXPropertyNone;
            }
        }
コード例 #11
0
		public InflateInputStream(Stream CompressedStream)
		{
			this.ZInputStream = new ZInputStream(CompressedStream);
		}
コード例 #12
0
ファイル: BDFParser.cs プロジェクト: Danilodum/dkstools
        public void Parse()
        {
            string outdir = Path.GetFullPath("bdfout__");
              long off = 0;
              int index = 0;

              List<BDFEntry> bes = new List<BDFEntry>();

              while (off < ds.Size) {
            uint dcx = ds.ReadUInt(off);
            if (dcx == 0x44435800) {
              // dcx header found

              BDFEntry be = new BDFEntry();
              be.Index = index;
              be.Offset = (uint)off;
              be.Size = ds.ReadUInt(off + 7 * 4);
              be.ZSizeBDF = ds.ReadUInt(off + 8 * 4);
              be.Name = "__undefined__" + name + "_" + index;
              bes.Add(be);

              ++index;
              off += be.ZSizeBDF;

              // next dcx starts at 16-byte aligned offset
              off &= 0xFFFFFFF0;
            }
            else {
              // next dcx starts at 16-byte aligned offset
              off += 16;
            }
              }

              if (DB != null) {
            // try to find BDF heuristically by matching number of entries and offsets
            BDF cand = null;
            foreach (BDF bdf in DB.BDFs.Where(b => b.Entries.Count == bes.Count)) {
              bool ok = true;
              for (int i = 0; ok && i < bes.Count; ++i) {
            if (bdf.Entries[i].Offset != bes[i].Offset) {
              ok = false;
            }
            bdf.Entries[i].Size = bes[i].Size;
            bdf.Entries[i].ZSizeBDF = bes[i].ZSizeBDF;
              }
              if (ok) {
            cand = bdf;
            break;
              }
            }

            if (cand != null) {
              bes = cand.Entries;
              w.WriteLine("found match");
            }
              }

              foreach (BDFEntry be in bes) {
            Stream s = ds.Stream;
            try {
              s.Seek(be.Offset + 0x4c, SeekOrigin.Begin);
              ZInputStream zis = new ZInputStream(ds.Stream);

              int hdrsz = 0;

              string dest = be.Name;
              if (!be.Name.Contains('.')) {

            // decompress/read first 3 bytes from file for guessing extension
            hdrsz = zis.Read(fcbuffer, 0, 3);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hdrsz; ++i) {
              if (Char.IsLetterOrDigit((char)fcbuffer[i])) {
                if (sb.Length == 0) sb.Append(".");
                sb.Append((char)fcbuffer[i]);
              }
            }
            dest = dest + sb.ToString();
              }
              else if (dest.EndsWith(".dcx")) {
            dest = dest.Substring(0, dest.Length - 4);
              }

              w.WriteLine("{0,-16} {1,4} {2:X08} size={3:X08} zsbhf={4:X08} zsbdf={5:X08} ({6:X02}) {7} {8}",
            name, be.Index, be.Offset, be.Size, be.ZSizeBHF, be.ZSizeBDF, be.ZSizeBHF - be.ZSizeBDF, be.Name, dest);

              if (Extract) {

            if (dest.StartsWith("\\")) dest = dest.Substring(1);
            string filename1 = Path.Combine(outdir, dest);
            string dirname = Path.GetDirectoryName(filename1);
            if (!Directory.Exists(dirname)) {
              Directory.CreateDirectory(dirname);
            }

            int tryn=0;
            string filename = filename1;
            while (File.Exists(filename)) {
              filename = filename1 + string.Format("_ovr-{0:00}", tryn++);
            }

            using (FileStream fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write)) {
              int r = 0;
              // write first 3 bytes
              fs.Write(fcbuffer, 0, hdrsz);
              int sz = hdrsz;
              do {
                r = zis.Read(fcbuffer, 0, fcbuffer.Length);
                sz += r;

                if (sz > be.Size) {
                  r -= sz - (int)be.Size;
                  fs.Write(fcbuffer, 0, r);
                  r = 0;
                }
                else if (r > 0) {
                  fs.Write(fcbuffer, 0, r);
                }
              } while (r > 0);
              if (sz == 0) {
                Console.WriteLine("zero size");
              }
            }

              }
            }
            catch (Exception ex) {
              Console.WriteLine(ex);
            }
              }
        }
コード例 #13
0
ファイル: ResourcePack.cs プロジェクト: ishani/InSiDe
        //
        public bool Load(String filename)
        {
            Console.WriteLine("ResourcePack::Load - {0}", filename);
              using (FileStream fs = File.Open(filename, FileMode.Open))
              {
            byte[] unpackBuffer = null;

            using (BinaryReader br = new BinaryReader(fs))
            {
              UInt32 sizeUncompressed = ByteUtils.SwapUInt32(br.ReadUInt32());
              unpackBuffer = new byte[sizeUncompressed];

              byte[] packedBuf = new byte[br.BaseStream.Length - 4];
              br.Read(packedBuf, 0, packedBuf.Length);

              Console.WriteLine("  ... uncompressed size is {0}", sizeUncompressed);
              using (MemoryStream ms = new MemoryStream(packedBuf))
              {
            using (ZInputStream zStream = new ZInputStream(ms))
            {
              Int32 bOffset = 0;
              while (bOffset < sizeUncompressed)
              {
                Int32 decS = zStream.read(unpackBuffer, bOffset, (Int32)sizeUncompressed - bOffset);
                bOffset += decS;
              }
            }
              }

            }
            fs.Close();

            using (MemoryStream ms = new MemoryStream(unpackBuffer))
            {
              using (BinaryReader ir = new BinaryReader(ms))
              {
            UInt32 numChunks = ByteUtils.SwapUInt32(ir.ReadUInt32());
            Console.WriteLine("  ... processing {0} chunks", numChunks);
            for (UInt32 i = 0; i < numChunks; i++)
            {
              String componentTypeName = ByteUtils.readNullTermString11(ir);
              UID componentUID = new UID(ir.ReadBytes(6));
              String componentName = ByteUtils.readNullTermString11(ir);

              UInt32 componentDataLength = ByteUtils.SwapUInt32(ir.ReadUInt32());

              // go see if we know how to build a component from this data type
              Type typeToBuild = null;
              if (mComponentFactory.TryGetValue(componentTypeName, out typeToBuild))
              {
                // yes; so instantiate the returned type
                SiDComponent newComponent = Activator.CreateInstance(typeToBuild) as SiDComponent;
                newComponent.Name = componentName;

                // ask it to load from the bytestream
                newComponent.LoadFromByteStream(ir, (Int32)componentDataLength);

                // record it
                if (!Add(newComponent))
                {
                  Console.WriteLine("Warning! duplicate item in single resource pack? {0}", componentUID);
                }

                Console.WriteLine("    + {0}:{1}: - {2}", componentUID, SiDComponent.getResourceTypeName(typeToBuild), newComponent.Name);
              }
              else
              {
                // we don't know how to construct this type; store as a 'black box' blob
                Blob newBlob = new Blob(componentTypeName);
                newBlob.Name = componentName;

                // blobs just hold onto the data as raw bytes, ready to parrot it back out on Save
                newBlob.LoadFromByteStream(ir, (Int32)componentDataLength);

                // record it
                if (!Add(newBlob))
                {
                  Console.WriteLine("Warning! duplicate (blob) item in single resource pack? {0}", componentUID);
                }

                Console.WriteLine("    + {0}:{1}:BLOB: - {2}", componentUID, componentTypeName, componentName);
              }
            }
              }
            }

              }

              return true;
        }
コード例 #14
0
        /// <summary>
        /// Returns the content of the actual file (extracts from raf archive)
        /// </summary>
        public byte[] GetContent()
        {
            if (inMemory) throw new Exception("Invalid call to GetContent, this entry is only in memory, and has not been linked to the DAT file yet.");
            FileStream fStream = this.raf.GetDataFileContentStream();

            byte[] buffer = new byte[this.FileSize];            //Will contain compressed data
            fStream.Seek(this.FileOffset, SeekOrigin.Begin);
            fStream.Read(buffer, 0, (int)this.FileSize);

            try
            {
                MemoryStream mStream = new MemoryStream(buffer);
                zlib.ZInputStream zinput = new zlib.ZInputStream(mStream);

                List<byte> dBuffer = new List<byte>(); //decompressed buffer, arraylist to my knowledge...

                //This could be optimized in the future by reading a block and adding it to our arraylist..
                //which would be much faster, obviously
                int data = 0;
                while ((data = zinput.Read()) != -1)
                    dBuffer.Add((byte)data);
                //ComponentAce.Compression.Libs.zlib.ZStream a = new ComponentAce.Compression.Libs.zlib.ZStream();

                //File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), dBuffer.ToArray());
                return dBuffer.ToArray();
            }
            catch
            {
                //it's not compressed, just return original content
                return buffer;
            }
        }
コード例 #15
0
        /// <summary>
        /// Dumps the content of the first .raf/.raf.dat archive seen in the given directory.
        /// Outputs to the given ostream
        /// </summary>
        public static bool Dump(string directory, StreamWriter ostream)
        {
            #region output_usage_header
            ostream.WriteLine("Experimental RAF Dumper by ItzWarty @ ItzWarty.com April 28 2011 10:00pm pst");
            ostream.WriteLine("RAF dogcumentation @ bit.ly/mSyYrR ");
            ostream.WriteLine("USAGE: RAF_DUMP (Or just double click executable)");
            ostream.WriteLine("Precondition: RAF_DUMP is sitting next to a Riot Archive File.");
            ostream.WriteLine("Postcondition: 'dump' folder created.  RAF extracted into folder.");
            #endregion
            //string dumpDir = @"C:\Riot Games\League of Legends\RADS\projects\lol_game_client\filearchives\0.0.0.28\dump\";

            //We write the file containing "name hash" next to our program.
            string hashesFile = Environment.CurrentDirectory + "\\hashes.txt";
            string hashesLog  = "";

            //We write to this file saying what we don't compress
            string notcompressedsFile = Environment.CurrentDirectory + "\\nocompress.txt";
            string notcompressedsLog  = "";

            string   dumpDir    = Environment.CurrentDirectory + "\\dump\\";
            String[] filesInDir = Directory.GetFiles(Environment.CurrentDirectory);
            String   rafName    = "";
            foreach (String fileName in filesInDir)
            {
                if (fileName.Split("\\").Last().EndsWith(".raf", StringComparison.InvariantCultureIgnoreCase))
                {
                    rafName = fileName;
                }
            }
            if (rafName == "")
            {
                ostream.WriteLine("Couldn't find RAF file!!");
                //ostream.WriteLine("This executable must be in the same folder as a *.raf and *.raf.dat file!");
                //ostream.WriteLine("Exiting... Press a key (or two) to exit");
                //ostream.ReadKey();
                return(false);
            }
            ostream.WriteLine("Found RAF: " + rafName);
            RAFArchive raf     = new RAFArchive(rafName);
            FileStream fStream = raf.GetDataFileContentStream();
            //DeflateStream dfStream = new DeflateStream(fStream, CompressionMode.Decompress);

            //int loggingOffset = 10; //No longer applicable since we aren't logging to system.out console directly
            List <RAFFileListEntry> files = raf.GetDirectoryFile().GetFileList().GetFileEntries();
            foreach (RAFFileListEntry entry in files)
            {
                //ostream.SetCursorPosition(0, 7);
                ostream.WriteLine("Dumping: " + entry.FileName.Split("\\").Last() + " ".Repeat(40));
                //ostream.SetCursorPosition(0, 8);
                ostream.WriteLine("  Data File Offset: $" + entry.FileOffset.ToString("x") + "; Size:" + entry.FileSize + " ($" + entry.FileSize.ToString("x") + ")" + " ".Repeat(40));
                //Console.SetCursorPosition(0, 7);
                //Console.WriteLine("  Expected FileName Checksum: $" + entry.StringNameHash.ToString("x") + "; Calculated:" + Adler32(entry.GetFileName).ToString("x")/*entry.GetFileName.GetHashCode().ToString("x")*/ + " ".Repeat(40));
                //Console.WriteLine("  To: " + dumpDir + entry.GetFileName+";;");
                hashesLog += entry.FileName + "|||" + entry.StringNameHash + "\n";
                //zlib.ad
                byte[] buffer = new byte[entry.FileSize];
                fStream.Seek(entry.FileOffset, SeekOrigin.Begin);
                fStream.Read(buffer, 0, (int)entry.FileSize);

                PrepareDirectory((dumpDir + entry.FileName).Replace("/", "\\"));
                try
                {
                    MemoryStream      mStream = new MemoryStream(buffer);
                    zlib.ZInputStream zinput  = new zlib.ZInputStream(mStream);

                    List <byte> dBuffer = new List <byte>(); //decompressed buffer, arraylist to my knowledge...
                    int         data    = 0;
                    while ((data = zinput.Read()) != -1)
                    {
                        dBuffer.Add((byte)data);
                    }
                    //ComponentAce.Compression.Libs.zlib.ZStream a = new ComponentAce.Compression.Libs.zlib.ZStream();

                    File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), dBuffer.ToArray());
                }
                catch
                {
                    notcompressedsLog += entry.FileName.ToLower() + "\n";
                    //Console.SetCursorPosition(2, loggingOffset++);
                    ostream.Write("UNABLE TO DECOMPRESS FILE, WRITING DEFLATED FILE:");
                    //Console.SetCursorPosition(4, loggingOffset++);
                    ostream.Write("  " + entry.FileName);
                    File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), buffer.ToArray());
                }
            }
            //Console.SetCursorPosition(0, 0);

            ostream.WriteLine("Write hashes and nocompress file");
            File.WriteAllText(hashesFile, hashesLog);
            File.WriteAllText(notcompressedsFile, notcompressedsLog);
            ostream.WriteLine("DONE!" + " ".Repeat(30));
            //fStream.Close();
            return(true);
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
        }
コード例 #16
0
ファイル: Compress.cs プロジェクト: zhutaorun/unitygame
        /// <summary>
        /// 解压
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        static public void DecompressByteZipNet(byte[] inBytes, uint startPos, uint inLen, ref byte[] outBytes, ref uint outLen)
        {
            MemoryStream outStream = new MemoryStream();
            MemoryStream outms = new MemoryStream();
            outms.Write(inBytes, (int)startPos, (int)inLen);
            outms.Position = 0;
            ZInputStream outzipStream = new ZInputStream(outms);

            byte[] writeData = new byte[1024];

            try
            {
                int size = 0;

                while ((size = outzipStream.read(writeData, 0, writeData.Length)) > 0)
                {
                    if (size > 0)
                    {
                        outStream.Write(writeData, 0, size);
                    }
                    else
                    {
                        Ctx.m_instance.m_logSys.log("ZipNet Decompress Error");
                    }
                }

                outzipStream.Close();  // 一定要先 Close ZipOutputStream ,然后再获取 ToArray ,如果不关闭, ToArray 将不能返回正确的值

                outBytes = outStream.ToArray();
                outLen = (uint)outBytes.Length;

                outStream.Close();
                outms.Close();
            }
            catch
            {
                Ctx.m_instance.m_logSys.log("DecompressByteZipNet error");
            }
        }