protected internal virtual LhaEntry ReadHeader_Lv2(byte[] @base) { LhaEntry e = new LhaEntry(); e.SetMethod(encoding.GetString(@base, HDR2_OFF_METHOD, 5)); e.SetCompressedSize(Get32(@base, HDR2_OFF_COMPSIZE)); e.SetOriginalSize(Get32(@base, HDR2_OFF_ORIGSIZE)); e.SetHeaderTimeStamp(Get32(@base, HDR2_OFF_TIMESTAMP)); calcCRC.Update(@base, 0, @base.Length); byte[] buf = new byte[2]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read crc value)")); } e.SetCRC(Get16(buf, 0)); calcCRC.Update(buf, 0, buf.Length); buf = new byte[1]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read os signature)")); } e.SetOS(buf[0]); calcCRC.Update(buf, 0, buf.Length); buf = new byte[2]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read ext)")); } calcCRC.Update(buf, 0, buf.Length); for (int next = Get16(buf, 0); next > 0; next = ReadExHeader(e, next)) { ; } e.SetPath(dirName + fileName); return(e); }
protected internal virtual LhaEntry ReadHeader_Lv1(byte[] @base) { LhaEntry e = new LhaEntry(); flagSum = true; srcSum = @base[HDR1_OFF_SUM]; if (srcSum < 0) { srcSum += 256; } e.SetMethod(encoding.GetString(@base, HDR1_OFF_METHOD, 5)); e.SetOriginalSize(Get32(@base, HDR1_OFF_ORIGSIZE)); e.SetDosTimeStamp(Get32(@base, HDR1_OFF_TIMESTAMP)); if (@base[HDR1_OFF_19] != 0x20) { throw (new LhaException("Lha header is broken (offset 19 is not 0x20)")); } calcSum.Update(@base, 2, @base.Length - 2); calcCRC.Update(@base, 0, @base.Length); byte[] buf = new byte[1]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read name size)")); } int nameSize = buf[0]; calcSum.Update(buf, 0, buf.Length); calcCRC.Update(buf, 0, buf.Length); string name = ""; if (nameSize > 0) { buf = new byte[nameSize]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read name)")); } name = encoding.GetString(buf); calcSum.Update(buf, 0, buf.Length); calcCRC.Update(buf, 0, buf.Length); } buf = new byte[2]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read crc value)")); } e.SetCRC(Get16(buf, 0)); calcSum.Update(buf, 0, buf.Length); calcCRC.Update(buf, 0, buf.Length); buf = new byte[1]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read os signature)")); } e.SetOS(buf[0]); calcSum.Update(buf, 0, buf.Length); calcCRC.Update(buf, 0, buf.Length); long extSize = 0; buf = new byte[2]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read ext)")); } calcSum.Update(buf, 0, buf.Length); calcCRC.Update(buf, 0, buf.Length); for (int next = Get16(buf, 0); next > 0; next = ReadExHeader(e, next)) { extSize += next; } e.SetCompressedSize(Get32(@base, HDR0_OFF_COMPSIZE) - extSize); if (fileName.Length > 0) { name = dirName + fileName; } else { name = ConvertFilePath(name, e.GetOS()); } e.SetPath(name); return(e); }
protected internal virtual LhaEntry ReadHeader_Lv0(byte[] @base) { LhaEntry e = new LhaEntry(); flagSum = true; int headerSize = @base[HDRU_OFF_HEADERSIZE]; srcSum = @base[HDR0_OFF_SUM]; if (srcSum < 0) { srcSum += 256; } e.SetMethod(encoding.GetString(@base, HDR0_OFF_METHOD, 5)); e.SetCompressedSize(Get32(@base, HDR0_OFF_COMPSIZE)); e.SetOriginalSize(Get32(@base, HDR0_OFF_ORIGSIZE)); e.SetDosTimeStamp(Get32(@base, HDR0_OFF_TIMESTAMP)); calcSum.Update(@base, 2, @base.Length - 2); byte[] buf = new byte[1]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (header size does'nt match)")); } int nameSize = buf[0]; calcSum.Update(buf, 0, buf.Length); buf = new byte[nameSize]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read name)")); } string name = encoding.GetString(buf); calcSum.Update(buf, 0, buf.Length); int diff = headerSize - nameSize; if ((diff != 20) && (diff != 22) && (diff < 23)) { throw (new LhaException("Lha header is broken (header size does'nt match)")); } e.SetOS(LhaEntry.OSID_SIG_GENERIC); if (diff >= 22) { buf = new byte[2]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read crc value)")); } e.SetCRC(Get16(buf, 0)); calcSum.Update(buf, 0, buf.Length); } if (diff >= 23) { buf = new byte[1]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read os signature)")); } e.SetOS(buf[0]); calcSum.Update(buf, 0, buf.Length); } if (diff > 23) { buf = new byte[diff - 24]; if (binaryReader.Read(buf, 0, buf.Length) != buf.Length) { throw (new LhaException("Lha header is broken (cannot read ext)")); } calcSum.Update(buf, 0, buf.Length); } e.SetPath(ConvertFilePath(name, e.GetOS())); return(e); }