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 unknown = PboUtilities.ReadLong(stream); var timestamp = PboUtilities.ReadLong(stream); var datasize = PboUtilities.ReadLong(stream); var entry = new FileEntry(this, filename, packing, size, timestamp, datasize, file, unknown); if (entry.FileName == "") { entry.OrgName = new byte[0]; return false; } Files.Add(entry); return true; }
private Stream GetFileStream(FileEntry fileEntry) { if (_stream != null) { _stream.Position = (long)GetFileStreamPos(fileEntry); return _stream; } var mem = File.OpenRead(PboPath); mem.Position = (long)GetFileStreamPos(fileEntry); return mem; }
private ulong GetFileStreamPos(FileEntry fileEntry) { var start = (ulong)DataStart; return Files.TakeWhile(entry => entry != fileEntry).Aggregate(start, (current, entry) => current + entry.DataSize); }
// returns a stream /// <summary> /// Returns a filestream to the ENTIRE pbo set at the file entry pos. /// </summary> /// <param name="fileEntry"></param> /// <returns></returns> public Stream Extract(FileEntry fileEntry) { return GetFileStream(fileEntry); }
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; } PboUtilities.WriteLong(stream, packing); PboUtilities.WriteLong(stream, (long)entry.OriginalSize); PboUtilities.WriteLong(stream, 0x0); // reserved PboUtilities.WriteLong(stream, (long)entry.TimeStamp); PboUtilities.WriteLong(stream, (long)entry.DataSize); }
private bool ReadEntry(FileStream stream) { var filename = PboUtilities.ReadString(stream); var packing = PboUtilities.ReadLong(stream); var size = PboUtilities.ReadLong(stream); var unknown = PboUtilities.ReadLong(stream); var timestamp = PboUtilities.ReadLong(stream); var datasize = PboUtilities.ReadLong(stream); var entry = new FileEntry(this, filename, packing, size, timestamp, datasize, unknown); if (entry.FileName == "") return false; Files.Add(entry); return true; }
public Boolean Extract(FileEntry fileEntry, string outpath) { if(String.IsNullOrEmpty(outpath)) throw new NullReferenceException("Is null or empty"); Stream mem = GetFileStream(fileEntry); if (mem == null) throw new Exception("WTF no stream"); if (!Directory.Exists(Path.GetDirectoryName(outpath))) Directory.CreateDirectory(Path.GetDirectoryName(outpath)); var totalread = fileEntry.DataSize; using (var outfile = File.OpenWrite(outpath)) { var buffer = new byte[2949120]; while (totalread > 0) { var read = mem.Read(buffer, 0, (int)Math.Min(2949120, totalread)); outfile.Write(buffer, 0, read); totalread -= (ulong)read; } } mem.Close(); return true; }
private long GetFileMemPos(FileEntry fileEntry) { ulong start = Files.TakeWhile(entry => entry != fileEntry).Aggregate<FileEntry, ulong>(0, (current, entry) => current + entry.DataSize); return (long)start; }
private Stream GetFileStream(FileEntry fileEntry) { Stream mem; if (_memory != null) mem = ExtractMemory(fileEntry); else { mem = File.OpenRead(PboPath); mem.Position = (long)GetFileStreamPos(fileEntry); } return mem; }
// returns a stream public Stream Extract(FileEntry fileEntry) { var stream = GetFileStream(fileEntry); if (stream is MemoryStream) return stream; using (stream) { var mem = new MemoryStream((int)fileEntry.DataSize); var buffer = new byte[fileEntry.DataSize]; stream.Read(buffer, 0, buffer.Length); mem.Write(buffer, 0, buffer.Length); mem.Position = 0; return mem; } }
private Stream ExtractMemory(FileEntry fileEntry) { var buffer = new byte[fileEntry.DataSize]; _memory.Position = GetFileMemPos(fileEntry); _memory.Read(buffer, 0, buffer.Length); _memory.Position = 0; return new MemoryStream(buffer); }
public Boolean Extract(FileEntry fileEntry, string outpath) { if(String.IsNullOrEmpty(outpath)) throw new NullReferenceException("Is null or empty"); Stream mem = GetFileStream(fileEntry); if (mem == null) throw new Exception("WTF no stream"); if (!Directory.Exists(Path.GetDirectoryName(outpath))) Directory.CreateDirectory(Path.GetDirectoryName(outpath)); using (var write = File.Create(outpath)) { var buffer = new byte[fileEntry.DataSize]; mem.Read(buffer, 0, buffer.Length); write.Write(buffer, 0, buffer.Length); } mem.Close(); return true; }
private ulong GetFileStreamPos(FileEntry fileEntry) { ulong start = (ulong) _dataStart; foreach (var entry in Files) { if (entry == fileEntry) break; start += entry.DataSize; } return start; }
private long GetFileMemPos(FileEntry fileEntry) { ulong start = 0; foreach (var entry in Files) { if (entry == fileEntry) break; start += entry.DataSize; } return (long) start; }
public Boolean Extract(FileEntry fileEntry, string outpath) { Stream mem = GetFileStream(fileEntry); if(mem == null) throw new Exception("WTF no stream"); try { try { using (var write = File.Create(outpath)) { var buffer = new byte[fileEntry.DataSize]; mem.Read(buffer, 0, buffer.Length); write.Write(buffer, 0, buffer.Length); } } catch (Exception) { throw; } } catch (Exception) { throw; } mem.Close(); return true; }
public static Boolean Create(string directoryPath,string outpath, ProductEntry productEntry) { var files = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories); var entries = new List<FileEntry>(); foreach (var file in files) { var info = new FileInfo(file); var path = PboUtilities.GetRelativePath(info.FullName, directoryPath); var entry = new FileEntry(path, 0x0, 0x0, (ulong) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds, (ulong) info.Length); entries.Add(entry); } 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, 0)); foreach (var entry in entries) { WriteFileEntry(stream, entry); } entries.Remove(entries.Last()); foreach (var entry in entries) { var buffer = new byte[1024]; 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; }