private void Init(Stream fs, WzKeyType k) { this.KeyType = k; this.BaseOffset = 0; this.BaseStream = fs; this.DynamicRead = false; this.StringPool = new SerializeStringPool(this); }
/// <summary> </summary> public static WzFile FromFile(string path, WzKeyType key = WzKeyType.None) { WzFile file = new WzFile(Path.GetFileName(path), key); file.Stream = File.OpenRead(path); file.Size = (int)file.Stream.Length; return(file); }
/// <summary> 使用指定的加密金鑰,將加密過的<see cref="WzImage"/>資料寫入<see cref="WzFile"/>中 </summary> /// <param name="name"> <see cref="WzFile"/>的名子 </param> /// <param name="key"> 加密金鑰 </param> public WzFile ToWzFile(string name, WzKeyType key = WzKeyType.None) { WzFile file = new WzFile(name, key); WzFileStream stream = new WzFileStream(file.Stream, file.KeyType); this.Write(stream); file.Size = (int)stream.Length; stream.Dispose(false); return(file); }
/// <summary> </summary> public static byte[] GenKey(WzKeyType key, int len) { if (len == 0) { return(null); } if (key == WzKeyType.G) { return(WzAES.GenKey(IVg, len)); } if (key == WzKeyType.K) { return(WzAES.GenKey(IVk, len)); } return(null); }
/// <summary> </summary> public static void XORKey(byte[] src, int len, WzKeyType type) { if (type == WzKeyType.None) { return; } if (type == WzKeyType.K) { if (WZUtil.GlobalKey_K == null || WZUtil.GlobalKey_K.Length < len) { WZUtil.GlobalKey_K = WzAES.GenKey(WzAES.IVk, len); } XORBuffer(src, WZUtil.GlobalKey_K, len); } else if (type == WzKeyType.G) { if (WZUtil.GlobalKey_G == null || WZUtil.GlobalKey_G.Length < len) { WZUtil.GlobalKey_G = WzAES.GenKey(WzAES.IVg, len); } XORBuffer(src, WZUtil.GlobalKey_G, len); } }
/// <summary> 從指定路徑建立<see cref="WzFileStream"/>並讀取資料 </summary> public bool Open(string path, WzKeyType key) { this.Stream = new WzFileStream(path, FileMode.Open, key); return(this.Read(this.Stream)); }
/// <summary> </summary> public WzFile(string name, WzKeyType key = WzKeyType.None) : base(name, WzArchiveItemType.File) { this.KeyType = key; this.Stream = new MemoryStream(); }
/// <summary> 使用指定的資料流和金鑰建立<see cref="WzFileStream"/>實體 </summary> /// <param name="stream"> 檔案資料流 </param> /// <param name="key"> 加密金鑰 </param> public WzFileStream(Stream stream, WzKeyType key = WzKeyType.None) { this.Init(stream, key); }
/// <summary> 使用指定的模式建立<see cref="WzFileStream"/>實體 </summary> /// <param name="path"> 檔案路徑 </param> /// <param name="mode"> 開啟模式 </param> /// <param name="key"> 加密金鑰 </param> public WzFileStream(string path, FileMode mode, WzKeyType key = WzKeyType.None) { this.Init(File.Open(path, mode), key); }