public void LoadFile(string fileName, Wz_Node node, bool useBaseWz) { Wz_File file; try { file = new Wz_File(fileName, this); file.TextEncoding = this.TextEncoding; if (!this.encryption.encryption_detected) { this.encryption.DetectEncryption(file); } this.wz_files.Add(file); node.Value = file; file.Node = node; file.FileStream.Position = 62; file.GetDirTree(node, useBaseWz); file.DetectWzType(); file.DetectWzVersion(); } catch { throw; } }
public void LoadFileImg(string fileName, Wz_Node node) { Wz_File file; try { file = new Wz_File(fileName, this); file.TextEncoding = this.TextEncoding; var imgNode = new Wz_Node(node.Text); //跳过checksum检测 var img = new Wz_Image(node.Text, (int)file.FileStream.Length, 0, 0, 0, file) { OwnerNode = imgNode, Offset = 0, IsChecksumChecked = true }; imgNode.Value = img; node.Nodes.Add(imgNode); this.wz_files.Add(file); } catch { throw; } }
public Wz_Png(int w, int h, int data_length, int form, int offs, Wz_File wz_f) { this.w = w; this.h = h; this.data_length = data_length; this.form = form; this.offs = offs; this.wz_f = wz_f; }
public Wz_Sound(int offset, int length, byte[] header, int ms, Wz_File wz_f) { this.offset = offset; this.dataLength = length; this.header = header; this.ms = ms; this.wz_f = wz_f; TryDecryptHeader(); }
public Wz_Image(string name, int size, int cs32, uint hashOff, uint hashPos, Wz_File wz_f) { this.Name = name; this.WzFile = wz_f; this.Size = size; this.Checksum = cs32; this.HashedOffset = hashOff; this.HashedOffsetPosition = hashPos; this.Node = new Wz_ImageNode(name, this); this.extr = false; this.chec = false; this.checEnc = false; }
/// <summary> /// 搜索node所属的wz_file,若搜索不到则返回null。 /// </summary> /// <param Name="node">要搜索的wznode。</param> /// <returns></returns> public static Wz_File GetNodeWzFile(this Wz_Node node) { Wz_File wzfile = null; Wz_Image wzImg = null; while (node != null) { if ((wzfile = node.Value as Wz_File) != null) { break; } if ((wzImg = node.Value as Wz_Image) != null || (wzImg = (node as Wz_Image.Wz_ImageNode)?.Image) != null) { wzfile = wzImg.WzFile; break; } node = node.ParentNode; } return(wzfile); }
public void DetectEncryption(Wz_File f) { int old_off = (int)f.FileStream.Position; f.FileStream.Position = 62; if (f.ReadInt32() <= 0) //只有文件头 无法预判 { return; } f.FileStream.Position++; int len = (int)(-f.BReader.ReadSByte()); byte[] bytes = f.BReader.ReadBytes(len); for (int i = 0; i < len; i++) { bytes[i] ^= (byte)(0xAA + i); } StringBuilder sb = new StringBuilder(); if (!this.encryption_detected) { //测试bms sb.Clear(); for (int i = 0; i < len; i++) { sb.Append((char)(keys_bms[i] ^ bytes[i])); } if (IsLegalNodeName(sb.ToString())) { this.EncType = Wz_CryptoKeyType.BMS; this.encryption_detected = true; goto lbl_end; } //测试kms sb.Clear(); for (int i = 0; i < len; i++) { sb.Append((char)(keys_kms[i] ^ bytes[i])); } if (IsLegalNodeName(sb.ToString())) { this.EncType = Wz_CryptoKeyType.KMS; this.encryption_detected = true; goto lbl_end; } //测试gms sb.Clear(); for (int i = 0; i < len; i++) { sb.Append((char)(keys_gms[i] ^ bytes[i])); } if (IsLegalNodeName(sb.ToString())) { this.EncType = Wz_CryptoKeyType.GMS; this.encryption_detected = true; goto lbl_end; } } lbl_end: f.FileStream.Position = old_off; }