public void ReadCompressedZip(string filepath)
        {
            while (BackgroundWriting) ;

            ZipInputStream instream = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();
            instream.GetNextEntry();
            searchDump = new TCPTCPGecko.Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream));
            instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress));

            instream.GetNextEntry();
            resultsList = (System.Collections.Generic.List<UInt32>)formatter.Deserialize(instream);

            instream.Close();
            instream.Dispose();
        }
Exemplo n.º 2
0
        public List<UInt32> LoadSearchList(string filepath)
        {
            // spin while background writing to prevent us from reading a file that has yet to be written
            while (BackgroundWriting) ;

            ZipInputStream instream = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();

            // First entry is the dump
            instream.GetNextEntry();

            // Second entry is the list
            instream.GetNextEntry();

            List<UInt32> searchList = (List<UInt32>)formatter.Deserialize(instream);

            instream.Close();
            instream.Dispose();
        
            return searchList;
        }
Exemplo n.º 3
0
        public Dump LoadSearchDump(string filepath)
        {
            // spin while background writing to prevent us from reading a file that has yet to be written
            while (BackgroundWriting) ;

            ZipInputStream instream = new ZipInputStream(filepath);
            BinaryFormatter formatter = new BinaryFormatter();

            // First entry is the dump
            instream.GetNextEntry();
            Dump searchDump = new Dump((uint)formatter.Deserialize(instream), (uint)formatter.Deserialize(instream));
            instream.Read(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress));

            instream.Close();
            instream.Dispose();

            return searchDump;
        }
Exemplo n.º 4
0
        internal ZipPackage(Stream stream)
        {
            bool hasContentTypeXml = false;
            if (stream == null || stream.Length == 0)
            {
                AddNew();
            }
            else
            {
                var rels = new Dictionary<string, string>();
                stream.Seek(0, SeekOrigin.Begin);                
                using (ZipInputStream zip = new ZipInputStream(stream))
                {
                    var e = zip.GetNextEntry();
                    while (e != null)
                    {
                        if (e.UncompressedSize > 0)
                        {
                            var b = new byte[e.UncompressedSize];
                            var size = zip.Read(b, 0, (int)e.UncompressedSize);
                            if (e.FileName.Equals("[content_types].xml", StringComparison.InvariantCultureIgnoreCase))
                            {
                                AddContentTypes(Encoding.UTF8.GetString(b));
                                hasContentTypeXml = true;
                            }
                            else if (e.FileName.Equals("_rels/.rels", StringComparison.InvariantCultureIgnoreCase)) 
                            {
                                ReadRelation(Encoding.UTF8.GetString(b), "");
                            }
                            else
                            {
                                if (e.FileName.EndsWith(".rels", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    rels.Add(GetUriKey(e.FileName), Encoding.UTF8.GetString(b));
                                }
                                else
                                {
                                    var part = new ZipPackagePart(this, e);
                                    part.Stream = new MemoryStream();
                                    part.Stream.Write(b, 0, b.Length);
                                    Parts.Add(GetUriKey(e.FileName), part);
                                }
                            }
                        }
                        else
                        {
                        }
                        e = zip.GetNextEntry();
                    }

                    foreach (var p in Parts)
                    {
                        string name = Path.GetFileName(p.Key);
                        string extension = Path.GetExtension(p.Key);
                        string relFile = string.Format("{0}_rels/{1}.rels", p.Key.Substring(0, p.Key.Length - name.Length), name);
                        if (rels.ContainsKey(relFile))
                        {
                            p.Value.ReadRelation(rels[relFile], p.Value.Uri.OriginalString);
                        }
                        if (_contentTypes.ContainsKey(p.Key))
                        {
                            p.Value.ContentType = _contentTypes[p.Key].Name;
                        }
                        else if (extension.Length > 1 && _contentTypes.ContainsKey(extension.Substring(1)))
                        {
                            p.Value.ContentType = _contentTypes[extension.Substring(1)].Name;
                        }
                    }
                    if (!hasContentTypeXml)
                    {
                        throw (new InvalidDataException("The file is not an valid Package file. If the file is encrypted, please supply the password in the constructor."));
                    }
                    if (!hasContentTypeXml)
                    {
                        throw (new InvalidDataException("The file is not an valid Package file. If the file is encrypted, please supply the password in the constructor."));
                    }
                    zip.Close();
                }
            }
        }
Exemplo n.º 5
0
		/// <summary>
		/// Initializes a new instance of the <see cref="WF.Compiler.Parser"/> class.
		/// Checks also, if the gwz could be found, and if it contains a lua file
		/// </summary>
		/// <param name='filename'>
		/// Filename.
		/// </param>
		public Parser ( string filename )
		{
			// Check if fileName exists
			if ( !File.Exists ( filename ) )
			{
				// Try, if we could append a .gwz to the filename to get the file than
				if ( !File.Exists ( filename + ".gwz" ) )
					throw new FileNotFoundException ( "File not found", filename );
				else
					this.filenameGwz = filename + ".gwz";
			}
			else
			{
				// Save fileName
				this.filenameGwz = filename;
			}

			// Now open gwz file and read all relevant data
			ZipInputStream zipInput = new ZipInputStream ( File.OpenRead ( filename ) );

			ZipEntry zipEntry;

			while ( ( zipEntry = zipInput.GetNextEntry () ) != null ) 
			{
				switch ( Path.GetExtension ( zipEntry.FileName ).ToLower () )
				{
					case ".lua":
						filenameLua = zipEntry.FileName;
						break;
					case ".gwi":
						filenameInfo = zipEntry.FileName;
						break;
					default:
						files.Add ( zipEntry.FileName.ToLower () );
						break;
				}
			}

			zipInput.Close ();

			// Is gwz file a valid gwz file
			if ( filenameLua == null )
				throw new FileNotFoundException ( "Lua file not found", filename );
		}