Esempio n. 1
0
        private static void WriteFileEntry(FileStream stream, FileEntry entry)
        {
            if (entry.OrgName != null)
            {
                PboUtilities.WriteASIIZ(stream, entry.OrgName);
            }
            else
            {
                PboUtilities.WriteString(stream, entry.FileName);
            }
            long packing = 0x0;

            switch (entry.PackingMethod)
            {
            case PackingType.Packed:
                packing = 0x43707273;
                break;

            case PackingType.Encrypted:
                packing = 0x456e6372;
                break;
            }
            PboUtilities.WriteLong(stream, packing);
            PboUtilities.WriteLong(stream, (long)entry.OriginalSize);
            PboUtilities.WriteLong(stream, (long)entry.StartOffset);
            PboUtilities.WriteLong(stream, (long)entry.TimeStamp);
            PboUtilities.WriteLong(stream, (long)entry.DataSize);
        }
Esempio n. 2
0
 private static void WriteProductEntry(ProductEntry productEntry, FileStream stream)
 {
     PboUtilities.WriteString(stream, "sreV");
     stream.Write(new byte[15], 0, 15);
     if (!string.IsNullOrEmpty(productEntry.Name))
     {
         PboUtilities.WriteString(stream, productEntry.Name);
     }
     else
     {
         return;
     }
     if (!string.IsNullOrEmpty(productEntry.Prefix))
     {
         PboUtilities.WriteString(stream, productEntry.Prefix);
     }
     else
     {
         return;
     }
     if (!string.IsNullOrEmpty(productEntry.ProductVersion))
     {
         PboUtilities.WriteString(stream, productEntry.ProductVersion);
     }
     else
     {
         return;
     }
     foreach (var str in productEntry.Addtional)
     {
         PboUtilities.WriteString(stream, str);
     }
 }
Esempio n. 3
0
        private bool ReadHeader(FileStream stream)
        {
            // TODO FIX SO BROKEN
            string str = PboUtilities.ReadString(stream);

            if (str != "sreV")
            {
                return(false);
            }
            int count = 0;

            while (count < 15)
            {
                stream.ReadByte();
                count++;
            }

            List <string> list    = new List <string>();
            string        pboname = "";
            string        version = "";
            string        prefix  = PboUtilities.ReadString(stream);

            if (!string.IsNullOrEmpty(prefix))
            {
                pboname = PboUtilities.ReadString(stream);
                if (!string.IsNullOrEmpty(pboname))
                {
                    version = PboUtilities.ReadString(stream);

                    if (!string.IsNullOrEmpty(version))
                    {
                        while (stream.ReadByte() != 0x0)
                        {
                            stream.Position--;
                            string s = PboUtilities.ReadString(stream);
                            list.Add(s);
                        }
                    }
                }
            }

            ProductEntry = new ProductEntry(prefix, pboname, version, list);

            return(true);
        }
Esempio n. 4
0
        private bool ReadEntry(FileStream stream)
        {
            var file     = PboUtilities.ReadStringArray(stream);
            var filename = Encoding.UTF8.GetString(file).Replace("\t", "\\t");

            var packing = PboUtilities.ReadLong(stream);

            var size = PboUtilities.ReadLong(stream);

            var startOffset = PboUtilities.ReadLong(stream);

            var timestamp = PboUtilities.ReadLong(stream);
            var datasize  = PboUtilities.ReadLong(stream);
            var entry     = new FileEntry(this, filename, packing, size, timestamp, datasize, file, startOffset);

            if (entry.FileName == "")
            {
                entry.OrgName = new byte[0];
                return(false);
            }
            Files.Add(entry);
            return(true);
        }
Esempio n. 5
0
        public static bool Create(string directoryPath, string outpath, ProductEntry productEntry)
        {
            var dir = new DirectoryInfo(directoryPath);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException();
            }
            directoryPath = dir.FullName;
            var files   = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories);
            var entries = new List <FileEntry>();

            foreach (string file in files)
            {
                if (Path.GetFileName(file).StartsWith("$") && Path.GetFileName(file).EndsWith("$"))
                {
                    continue;
                }
                FileInfo info = new FileInfo(file);
                string   path = PboUtilities.GetRelativePath(info.FullName, directoryPath);
                entries.Add(new FileEntry(path, 0x0, (ulong)info.Length, (ulong)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, (ulong)info.Length));
            }
            try
            {
                using (var stream = File.Create(outpath))
                {
                    stream.WriteByte(0x0);
                    WriteProductEntry(productEntry, stream);
                    stream.WriteByte(0x0);
                    entries.Add(new FileEntry(null, "", 0, 0, 0, 0, _file));
                    foreach (var entry in entries)
                    {
                        WriteFileEntry(stream, entry);
                    }
                    entries.Remove(entries.Last());
                    foreach (var entry in entries)
                    {
                        var buffer = new byte[2949120];
                        using (var open = File.OpenRead(Path.Combine(directoryPath, entry.FileName)))
                        {
                            var read = 4324324;
                            while (read > 0)
                            {
                                read = open.Read(buffer, 0, buffer.Length);
                                stream.Write(buffer, 0, read);
                            }
                        }
                    }
                    stream.Position = 0;
                    byte[] hash;
                    using (var sha1 = new SHA1Managed())
                    {
                        hash = sha1.ComputeHash(stream);
                    }
                    stream.WriteByte(0x0);
                    stream.Write(hash, 0, 20);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
            return(true);
        }