本文整理汇总了C#中ArcView.CreateStream方法的典型用法代码示例。如果您正苦于以下问题:C# ArcView.CreateStream方法的具体用法?C# ArcView.CreateStream怎么用?C# ArcView.CreateStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArcView
的用法示例。
在下文中一共展示了ArcView.CreateStream方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadIndex
List<Entry> ReadIndex(ArcView file, int version, byte[] key)
{
var header = file.View.ReadBytes (4, 0x18);
if (0x18 != header.Length)
return null;
Decrypt (header, 0, header.Length, 4, key);
var dx = new DxHeader {
IndexSize = LittleEndian.ToUInt32 (header, 0),
BaseOffset = LittleEndian.ToUInt32 (header, 4),
IndexOffset = LittleEndian.ToUInt32 (header, 8),
FileTable = LittleEndian.ToUInt32 (header, 0x0c),
DirTable = LittleEndian.ToUInt32 (header, 0x10),
};
if (dx.DirTable >= dx.IndexSize || dx.FileTable >= dx.IndexSize)
return null;
using (var encrypted = file.CreateStream (dx.IndexOffset, dx.IndexSize))
using (var index = new EncryptedStream (encrypted, dx.IndexOffset, key))
using (var reader = new IndexReader (dx, version, index))
{
return reader.Read();
}
}
示例2: SteinsGateEncryptedStream
public SteinsGateEncryptedStream(ArcView file, long offset, uint size)
{
m_stream = file.CreateStream (offset, size);
m_should_dispose = true;
m_base_pos = 0;
}
示例3: TryOpen
public override ArcFile TryOpen(ArcView file)
{
int count = file.View.ReadInt32 (4);
if (!IsSaneCount (count))
return null;
uint index_size = file.View.ReadUInt32 (0xC);
if (index_size < 2 || index_size > file.MaxOffset)
return null;
long base_offset = 0x118 + index_size;
using (var mem = file.CreateStream (0x118, index_size))
using (var z = new ZLibStream (mem, CompressionMode.Decompress))
using (var index = new BinaryReader (z))
{
var name_buffer = new byte[0x100];
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
int name_length = index.ReadInt32();
if (name_length <= 0 || name_length > name_buffer.Length)
return null;
if (name_length != index.Read (name_buffer, 0, name_length))
return null;
var name = Encodings.cp932.GetString (name_buffer, 0, name_length);
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
entry.Offset = index.ReadUInt32() + base_offset;
uint size = index.ReadUInt32();
index.ReadUInt32();
uint flags = index.ReadUInt32();
uint packed_size = index.ReadUInt32();
entry.IsPacked = flags != 0 && packed_size != 0;
if (entry.IsPacked)
{
entry.Size = packed_size;
entry.UnpackedSize = size;
}
else
{
entry.Size = size;
entry.UnpackedSize = size;
}
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
}
示例4: TryOpen
public override ArcFile TryOpen(ArcView file)
{
int type = file.View.ReadUInt16 (4);
int count = file.View.ReadInt32 (6);
if (!IsSaneCount (count))
return null;
using (var enc = file.CreateStream())
using (var dec = new EncryptedStream (enc))
using (var index = new BinaryReader (dec))
{
dec.Position = 0x4A;
var offsets = new uint[count];
for (int i = 0; i < count; ++i)
{
offsets[i] = index.ReadUInt32();
}
var name_buffer = new byte[0x100];
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
index.BaseStream.Position = offsets[i];
uint signature = index.ReadUInt32();
if (signature != 0x41544144) // 'DATA'
continue;
int section_count = index.ReadInt32();
index.ReadInt16();
var entry = new Entry { Offset = offsets[i] };
for (int s = 0; s < section_count; ++s)
{
signature = index.ReadUInt32();
if (0x44474D49 == signature) // 'IMGD'
{
entry.Offset = index.BaseStream.Position - 4;
uint imgd_size = index.ReadUInt32();
entry.Size = imgd_size + 0x10;
index.BaseStream.Seek (imgd_size + 2, SeekOrigin.Current);
}
else if (0x454E4E46 == signature) // 'FNNE'
{
int name_length = index.ReadInt32()-2;
index.ReadInt16();
if (name_length > name_buffer.Length)
name_buffer = new byte[name_length];
index.Read (name_buffer, 0, name_length);
entry.Name = Encodings.cp932.GetString (name_buffer, 0, name_length);
entry.Type = FormatCatalog.Instance.GetTypeFromName (entry.Name);
index.ReadInt16();
}
else
{
var section_size = index.ReadUInt32();
// section not supported, skip
index.BaseStream.Seek (section_size+2, SeekOrigin.Current);
if (0x415A4F4D != signature) // 'MOZA'
Trace.WriteLine (string.Format ("Unknown section 0x{0:X8}", signature), "[WAG/IAF]");
}
}
if (entry.Size > 0 && !string.IsNullOrEmpty (entry.Name))
dir.Add (entry);
}
if (0 == dir.Count)
return null;
return new ArcFile (file, this, dir);
}
}
示例5: TryOpen
public override ArcFile TryOpen(ArcView file)
{
int count = file.View.ReadInt32 (0x18);
if (!IsSaneCount (count))
return null;
var key = QueryEncryption();
if (null == key)
return null;
var aes = Aes.Create();
try
{
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.Key = key;
aes.IV = file.View.ReadBytes (8, 0x10);
uint index_size = file.View.ReadUInt32 (0x1C);
using (var decryptor = aes.CreateDecryptor())
using (var enc_index = file.CreateStream (0x20, index_size))
using (var dec_index = new CryptoStream (enc_index, decryptor, CryptoStreamMode.Read))
using (var index = new ArcView.Reader (dec_index))
{
var dir = ReadIndex (index, count, file.MaxOffset);
if (null == dir)
return null;
var arc = new NpkArchive (file, this, dir, aes);
aes = null; // object ownership passed to NpkArchive, don't dispose
return arc;
}
}
finally
{
if (aes != null)
aes.Dispose();
}
}
示例6: DetectFileTypes
protected static void DetectFileTypes(ArcView file, List<Entry> dir)
{
byte[] signature_buffer = new byte[4];
foreach (PackedEntry entry in dir)
{
uint packed_size = file.View.ReadUInt32 (entry.Offset);
uint unpacked_size = file.View.ReadUInt32 (entry.Offset+4);
if (0 == packed_size)
packed_size = unpacked_size;
entry.IsPacked = packed_size != unpacked_size;
entry.Size = packed_size;
entry.UnpackedSize = unpacked_size;
entry.Offset += 8;
uint signature;
if (entry.IsPacked)
{
using (var input = file.CreateStream (entry.Offset, Math.Min (packed_size, 0x20u)))
using (var reader = new ShsCompression (input))
{
reader.Unpack (signature_buffer);
signature = LittleEndian.ToUInt32 (signature_buffer, 0);
}
}
else
{
signature = file.View.ReadUInt32 (entry.Offset);
}
if (0 != signature)
{
IResource res;
if (0x4D42 == (signature & 0xFFFF))
res = ImageFormat.Bmp;
else if (0x020000 == signature || 0x0A0000 == signature)
res = ImageFormat.Tga;
else
res = FormatCatalog.Instance.LookupSignature (signature).FirstOrDefault();
if (res != null)
{
entry.Type = res.Type;
var ext = res.Extensions.FirstOrDefault();
if (!string.IsNullOrEmpty (ext))
entry.Name = Path.ChangeExtension (entry.Name, ext);
}
}
}
}
示例7: TryOpen
public override ArcFile TryOpen(ArcView file)
{
List<Entry> dir = null;
bool zero_signature = 0 == file.View.ReadInt16 (0);
try
{
using (var input = file.CreateStream())
{
if (zero_signature)
input.Seek (2, SeekOrigin.Begin);
dir = ReadIndex (input);
if (null != dir)
return new ArcFile (file, this, dir);
}
}
catch { /* ignore parse errors */ }
if (zero_signature || !file.Name.EndsWith (".nsa", StringComparison.InvariantCultureIgnoreCase))
return null;
var password = QueryPassword();
if (string.IsNullOrEmpty (password))
return null;
var key = Encoding.ASCII.GetBytes (password);
using (var input = new EncryptedViewStream (file, key))
{
dir = ReadIndex (input);
if (null == dir)
return null;
return new NsaEncryptedArchive (file, this, dir, key);
}
}
示例8: DetectFileTypes
void DetectFileTypes(ArcView file, List<Entry> dir)
{
using (var input = file.CreateStream())
using (var reader = new ArcView.Reader (input))
{
var buffer = new byte[0x10];
foreach (PackedEntry entry in dir)
{
input.Position = entry.Offset;
uint packed_size = reader.ReadUInt32();
entry.UnpackedSize = reader.ReadUInt32();
entry.Offset += 8;
if (0 == packed_size)
{
entry.Size = entry.UnpackedSize;
}
else
{
entry.IsPacked = true;
entry.Size = packed_size;
}
if (entry.Size < 0x10)
continue;
uint signature;
if (entry.IsPacked)
{
UnpackEntry (input, buffer);
signature = LittleEndian.ToUInt32 (buffer, 0);
}
else
signature = reader.ReadUInt32();
IResource res;
if (0x020000 == signature || 0x0A0000 == signature)
res = ImageFormat.Tga;
else
res = AutoEntry.DetectFileType (signature);
if (null != res)
{
entry.Type = res.Type;
var ext = res.Extensions.FirstOrDefault();
if (!string.IsNullOrEmpty (ext))
entry.Name = Path.ChangeExtension (entry.Name, ext);
}
}
}
}
示例9: TryOpen
public override ArcFile TryOpen(ArcView file)
{
uint header_size = file.View.ReadUInt32 (8);
HzcMetaData image_info;
using (var header = file.CreateStream (0, 0xC+header_size))
{
image_info = Hzc.Value.ReadMetaData (header) as HzcMetaData;
if (null == image_info)
return null;
}
int count = file.View.ReadInt32 (0x20);
if (0 == count)
count = 1;
string base_name = Path.GetFileNameWithoutExtension (file.Name);
int frame_size = image_info.UnpackedSize / count;
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var entry = new Entry {
Name = string.Format ("{0}#{1:D3}.tga", base_name, i),
Type = "image",
Offset = frame_size * i,
Size = 0x12 + (uint)frame_size,
};
dir.Add (entry);
}
return new HzcArchive (file, this, dir, image_info);
}
示例10: TryOpen
public override ArcFile TryOpen(ArcView file)
{
if (!file.Name.EndsWith (".g00", StringComparison.InvariantCultureIgnoreCase))
return null;
if (file.View.ReadByte (0) != 2)
return null;
uint width = file.View.ReadUInt16 (1);
uint height = file.View.ReadUInt16 (3);
if (0 == width || width > 0x8000 || 0 == height || height > 0x8000)
return null;
int count = file.View.ReadInt16 (5);
if (count <= 1 || count > 0x100)
return null;
var base_name = Path.GetFileNameWithoutExtension (file.Name);
uint size = width * height * 4 + 0x12; // virtual TGA image size
uint index_offset = 9;
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
var entry = new G00Entry {
Name = string.Format ("{0}#{1:D3}.tga", base_name, i),
X = file.View.ReadInt32 (index_offset),
Y = file.View.ReadInt32 (index_offset+4),
IsPacked = true,
UnpackedSize = size,
};
dir.Add (entry);
index_offset += 0x18;
}
byte[] bitmap;
using (var input = file.CreateStream (index_offset))
using (var bin = new BinaryReader (input))
bitmap = G00Reader.LzDecompress (bin, 2, 1);
using (var input = new MemoryStream (bitmap))
using (var reader = new BinaryReader (input))
{
if (reader.ReadInt32() != count)
return null;
for (int i = 0; i < count; ++i)
{
dir[i].Offset = reader.ReadUInt32();
dir[i].Size = reader.ReadUInt32();
}
}
dir = dir.Where (e => e.Size != 0).ToList();
if (0 == dir.Count)
return null;
var info = new ImageMetaData { Width = width, Height = height, BPP = 32 };
return new G00Archive (file, this, dir, info, bitmap);
}
示例11: FindSec5Resr
internal static Dictionary<string, Dictionary<int, Entry>> FindSec5Resr(string arc_name)
{
string dir_name = Path.GetDirectoryName (arc_name);
var match = Directory.GetFiles (dir_name, "*.sec5");
if (0 == match.Length)
{
string parent = Path.GetDirectoryName (dir_name);
if (!string.IsNullOrEmpty (parent))
match = Directory.GetFiles (parent, "*.sec5");
}
if (0 == match.Length)
return null;
using (var sec5 = new ArcView (match[0]))
{
if (!sec5.View.AsciiEqual (0, "SEC5"))
return null;
uint offset = 8;
while (offset < sec5.MaxOffset)
{
string id = sec5.View.ReadString (offset, 4, Encoding.ASCII);
if ("ENDS" == id)
break;
uint section_size = sec5.View.ReadUInt32 (offset+4);
offset += 8;
if ("RESR" == id)
{
using (var resr = sec5.CreateStream (offset, section_size))
return ReadResrSection (resr);
}
if ("RES2" == id)
{
using (var res2 = sec5.CreateStream (offset, section_size))
return ReadRes2Section (res2);
}
offset += section_size;
}
}
return null;
}
示例12: TryOpen
public override ArcFile TryOpen(ArcView file)
{
if (!file.View.AsciiEqual (8, "AlicArch"))
return null;
if (!file.View.AsciiEqual (0x1C, "INFO"))
return null;
int version = file.View.ReadInt32 (0x10);
long base_offset = file.View.ReadUInt32 (0x18);
uint packed_size = file.View.ReadUInt32 (0x20);
int unpacked_size = file.View.ReadInt32 (0x24);
int count = file.View.ReadInt32 (0x28);
if (!IsSaneCount (count))
return null;
var dir = new List<Entry> (count);
var name_buf = new byte[0x40];
using (var input = file.CreateStream (0x2C, packed_size))
using (var zstream = new ZLibStream (input, CompressionMode.Decompress))
using (var index = new BinaryReader (zstream))
{
for (int i = 0; i < count; ++i)
{
int name_length = index.ReadInt32();
int index_step = index.ReadInt32();
if (name_length <= 0 || name_length > index_step || index_step > unpacked_size)
return null;
if (index_step > name_buf.Length)
name_buf = new byte[index_step];
if (index_step != index.Read (name_buf, 0, index_step))
return null;
var name = Encodings.cp932.GetString (name_buf, 0, name_length);
var entry = FormatCatalog.Instance.Create<Entry> (name);
index.ReadInt32();
index.ReadInt32();
if (version < 2)
index.ReadInt32();
entry.Offset = index.ReadUInt32() + base_offset;
entry.Size = index.ReadUInt32();
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
}
return new ArcFile (file, this, dir);
}
}
示例13: OpenV2
ArcFile OpenV2(ArcView file, int count, int entry_size, int index_size)
{
int index_offset = 0x10;
int filenames_offset = index_offset + entry_size * count;
int filenames_length = file.View.ReadInt32 (filenames_offset);
char[] filenames;
using (var fn_stream = file.CreateStream (filenames_offset+8, (uint)filenames_length*2))
using (var fn_reader = new BinaryReader (fn_stream, Encoding.Unicode))
filenames = fn_reader.ReadChars (filenames_length);
var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i)
{
int name_offset = file.View.ReadInt32 (index_offset);
if (name_offset < 0 || name_offset >= filenames.Length)
return null;
var name = GetName (filenames, name_offset);
if (0 == name.Length)
return null;
var entry = FormatCatalog.Instance.Create<PackedEntry> (name);
entry.Offset = file.View.ReadUInt32 (index_offset+0xA);
entry.Size = file.View.ReadUInt32 (index_offset+0xE);
entry.UnpackedSize = file.View.ReadUInt32 (index_offset+0x12);
entry.IsPacked = 0 != file.View.ReadByte (index_offset+0x16);
if (!entry.CheckPlacement (file.MaxOffset))
return null;
dir.Add (entry);
index_offset += entry_size;
}
return new ArcFile (file, this, dir);
}