本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipExtraData.Find方法的典型用法代码示例。如果您正苦于以下问题:C# ZipExtraData.Find方法的具体用法?C# ZipExtraData.Find怎么用?C# ZipExtraData.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipExtraData
的用法示例。
在下文中一共展示了ZipExtraData.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestLocalHeader
private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
{
lock (this.baseStream_)
{
bool flag = (tests & HeaderTest.Header) != 0;
bool flag2 = (tests & HeaderTest.Extract) != 0;
this.baseStream_.Seek(this.offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
if (this.ReadLEUint() != 0x4034b50)
{
throw new ZipException(string.Format("Wrong local header signature @{0:X}", this.offsetOfFirstEntry + entry.Offset));
}
short num = (short) this.ReadLEUshort();
short flags = (short) this.ReadLEUshort();
short num3 = (short) this.ReadLEUshort();
short num4 = (short) this.ReadLEUshort();
short num5 = (short) this.ReadLEUshort();
uint num6 = this.ReadLEUint();
long num7 = this.ReadLEUint();
long num8 = this.ReadLEUint();
int num9 = this.ReadLEUshort();
int num10 = this.ReadLEUshort();
byte[] buffer = new byte[num9];
StreamUtils.ReadFully(this.baseStream_, buffer);
byte[] buffer2 = new byte[num10];
StreamUtils.ReadFully(this.baseStream_, buffer2);
ZipExtraData data = new ZipExtraData(buffer2);
if (data.Find(1))
{
num8 = data.ReadLong();
num7 = data.ReadLong();
if ((flags & 8) != 0)
{
if ((num8 != -1L) && (num8 != entry.Size))
{
throw new ZipException("Size invalid for descriptor");
}
if ((num7 != -1L) && (num7 != entry.CompressedSize))
{
throw new ZipException("Compressed size invalid for descriptor");
}
}
}
else if ((num >= 0x2d) && ((((uint) num8) == uint.MaxValue) || (((uint) num7) == uint.MaxValue)))
{
throw new ZipException("Required Zip64 extended information missing");
}
if (flag2 && entry.IsFile)
{
if (!entry.IsCompressionMethodSupported())
{
throw new ZipException("Compression method not supported");
}
if ((num > 0x33) || ((num > 20) && (num < 0x2d)))
{
throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", num));
}
if ((flags & 0x3060) != 0)
{
throw new ZipException("The library does not support the zip version required to extract this entry");
}
}
if (flag)
{
if (((((num <= 0x3f) && (num != 10)) && ((num != 11) && (num != 20))) && (((num != 0x15) && (num != 0x19)) && ((num != 0x1b) && (num != 0x2d)))) && ((((num != 0x2e) && (num != 50)) && ((num != 0x33) && (num != 0x34))) && (((num != 0x3d) && (num != 0x3e)) && (num != 0x3f))))
{
throw new ZipException(string.Format("Version required to extract this entry is invalid ({0})", num));
}
if ((flags & 0xc010) != 0)
{
throw new ZipException("Reserved bit flags cannot be set.");
}
if (((flags & 1) != 0) && (num < 20))
{
throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num));
}
if ((flags & 0x40) != 0)
{
if ((flags & 1) == 0)
{
throw new ZipException("Strong encryption flag set but encryption flag is not set");
}
if (num < 50)
{
throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num));
}
}
if (((flags & 0x20) != 0) && (num < 0x1b))
{
throw new ZipException(string.Format("Patched data requires higher version than ({0})", num));
}
if (flags != entry.Flags)
{
throw new ZipException("Central header/local header flags mismatch");
}
if (entry.CompressionMethod != ((CompressionMethod) num3))
{
throw new ZipException("Central header/local header compression method mismatch");
}
if (entry.Version != num)
{
//.........这里部分代码省略.........
示例2: BasicOperations
public void BasicOperations()
{
ZipExtraData zed = new ZipExtraData(null);
Assert.AreEqual(0, zed.Length);
zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 });
Assert.AreEqual(4, zed.Length, "A length should be 4");
ZipExtraData zed2 = new ZipExtraData();
Assert.AreEqual(0, zed2.Length);
zed2.AddEntry(1, new byte[] { });
byte[] data = zed.GetEntryData();
for (int i = 0; i < data.Length; ++i) {
Assert.AreEqual(zed2.GetEntryData()[i], data[i]);
}
Assert.AreEqual(4, zed2.Length, "A1 length should be 4");
bool findResult = zed.Find(2);
Assert.IsFalse(findResult, "A - Shouldnt find tag 2");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "A - Should find tag 1");
Assert.AreEqual(0, zed.ValueLength, "A- Length of entry should be 0");
Assert.AreEqual(-1, zed.ReadByte());
Assert.AreEqual(0, zed.GetStreamForTag(1).Length, "A - Length of stream should be 0");
zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3 });
Assert.AreEqual(7, zed.Length, "Expected a length of 7");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "B - Should find tag 1");
Assert.AreEqual(3, zed.ValueLength, "B - Length of entry should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, zed.ReadByte());
}
Assert.AreEqual(-1, zed.ReadByte());
Stream s = zed.GetStreamForTag(1);
Assert.AreEqual(3, s.Length, "B.1 Stream length should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, s.ReadByte());
}
Assert.AreEqual(-1, s.ReadByte());
zed = new ZipExtraData(new byte[] { 1, 0, 3, 0, 1, 2, 3, 2, 0, 1, 0, 56 });
Assert.AreEqual(12, zed.Length, "Expected a length of 12");
findResult = zed.Find(1);
Assert.IsTrue(findResult, "C.1 - Should find tag 1");
Assert.AreEqual(3, zed.ValueLength, "C.1 - Length of entry should be 3");
for (int i = 1; i <= 3; ++i) {
Assert.AreEqual(i, zed.ReadByte());
}
Assert.AreEqual(-1, zed.ReadByte());
findResult = zed.Find(2);
Assert.IsTrue(findResult, "C.2 - Should find tag 2");
Assert.AreEqual(1, zed.ValueLength, "C.2 - Length of entry should be 1");
Assert.AreEqual(56, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
s = zed.GetStreamForTag(2);
Assert.AreEqual(1, s.Length);
Assert.AreEqual(56, s.ReadByte());
Assert.AreEqual(-1, s.ReadByte());
zed = new ZipExtraData();
zed.AddEntry(7, new byte[] { 33, 44, 55 });
findResult = zed.Find(7);
Assert.IsTrue(findResult, "Add.1 should find new tag");
Assert.AreEqual(3, zed.ValueLength, "Add.1 length should be 3");
Assert.AreEqual(33, zed.ReadByte());
Assert.AreEqual(44, zed.ReadByte());
Assert.AreEqual(55, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
zed.AddEntry(7, null);
findResult = zed.Find(7);
Assert.IsTrue(findResult, "Add.2 should find new tag");
Assert.AreEqual(0, zed.ValueLength, "Add.2 length should be 0");
zed.StartNewEntry();
zed.AddData(0xae);
zed.AddNewEntry(55);
findResult = zed.Find(55);
Assert.IsTrue(findResult, "Add.3 should find new tag");
Assert.AreEqual(1, zed.ValueLength, "Add.3 length should be 1");
Assert.AreEqual(0xae, zed.ReadByte());
Assert.AreEqual(-1, zed.ReadByte());
zed = new ZipExtraData();
zed.StartNewEntry();
zed.AddLeLong(0);
zed.AddLeLong(-4);
zed.AddLeLong(-1);
zed.AddLeLong(long.MaxValue);
//.........这里部分代码省略.........
示例3: TestLocalHeader
/// <summary>
/// Test a local header against that provided from the central directory
/// </summary>
/// <param name="entry">
/// The entry to test against
/// </param>
/// <param name="tests">The type of <see cref="HeaderTest">tests</see> to carry out.</param>
/// <returns>The offset of the entries data in the file</returns>
long TestLocalHeader(ZipEntry entry, HeaderTest tests)
{
lock(baseStream_)
{
bool testHeader = (tests & HeaderTest.Header) != 0;
bool testData = (tests & HeaderTest.Extract) != 0;
baseStream_.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
if ((int)ReadLEUint() != ZipConstants.LocalHeaderSignature) {
throw new ZipException(string.Format("Wrong local header signature @{0:X}", offsetOfFirstEntry + entry.Offset));
}
short extractVersion = ( short ) (ReadLEUshort() & 0x00ff);
short localFlags = ( short )ReadLEUshort();
short compressionMethod = ( short )ReadLEUshort();
short fileTime = ( short )ReadLEUshort();
short fileDate = ( short )ReadLEUshort();
uint crcValue = ReadLEUint();
long compressedSize = ReadLEUint();
long size = ReadLEUint();
int storedNameLength = ReadLEUshort();
int extraDataLength = ReadLEUshort();
byte[] nameData = new byte[storedNameLength];
StreamUtils.ReadFully(baseStream_, nameData);
byte[] extraData = new byte[extraDataLength];
StreamUtils.ReadFully(baseStream_, extraData);
ZipExtraData localExtraData = new ZipExtraData(extraData);
// Extra data / zip64 checks
if (localExtraData.Find(1))
{
// 2010-03-04 Forum 10512: removed checks for version >= ZipConstants.VersionZip64
// and size or compressedSize = MaxValue, due to rogue creators.
size = localExtraData.ReadLong();
compressedSize = localExtraData.ReadLong();
if ((localFlags & (int)GeneralBitFlags.Descriptor) != 0)
{
// These may be valid if patched later
if ( (size != -1) && (size != entry.Size)) {
throw new ZipException("Size invalid for descriptor");
}
if ((compressedSize != -1) && (compressedSize != entry.CompressedSize)) {
throw new ZipException("Compressed size invalid for descriptor");
}
}
}
else
{
// No zip64 extra data but entry requires it.
if ((extractVersion >= ZipConstants.VersionZip64) &&
(((uint)size == uint.MaxValue) || ((uint)compressedSize == uint.MaxValue)))
{
throw new ZipException("Required Zip64 extended information missing");
}
}
if ( testData ) {
if ( entry.IsFile ) {
if ( !entry.IsCompressionMethodSupported() ) {
throw new ZipException("Compression method not supported");
}
if ( (extractVersion > ZipConstants.VersionMadeBy)
|| ((extractVersion > 20) && (extractVersion < ZipConstants.VersionZip64)) ) {
throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", extractVersion));
}
if ( (localFlags & ( int )(GeneralBitFlags.Patched | GeneralBitFlags.StrongEncryption | GeneralBitFlags.EnhancedCompress | GeneralBitFlags.HeaderMasked)) != 0 ) {
throw new ZipException("The library does not support the zip version required to extract this entry");
}
}
}
if (testHeader)
{
if ((extractVersion <= 63) && // Ignore later versions as we dont know about them..
(extractVersion != 10) &&
(extractVersion != 11) &&
(extractVersion != 20) &&
(extractVersion != 21) &&
(extractVersion != 25) &&
(extractVersion != 27) &&
(extractVersion != 45) &&
(extractVersion != 46) &&
(extractVersion != 50) &&
(extractVersion != 51) &&
//.........这里部分代码省略.........
示例4: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
var extraData = new ZipExtraData(this.extra);
if (extraData.Find(0x0001)) {
// Version required to extract is ignored here as some archivers dont set it correctly
// in theory it should be version 45 or higher
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if (extraData.ValueLength < 4) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
// (localHeader ||) was deleted, because actually there is no specific difference with reading sizes between local header & central directory
// https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
// ...
// 4.4 Explanation of fields
// ...
// 4.4.8 compressed size: (4 bytes)
// 4.4.9 uncompressed size: (4 bytes)
//
// The size of the file compressed (4.4.8) and uncompressed,
// (4.4.9) respectively. When a decryption header is present it
// will be placed in front of the file data and the value of the
// compressed file size will include the bytes of the decryption
// header. If bit 3 of the general purpose bit flag is set,
// these fields are set to zero in the local header and the
// correct values are put in the data descriptor and
// in the central directory. If an archive is in ZIP64 format
// and the value in this field is 0xFFFFFFFF, the size will be
// in the corresponding 8 byte ZIP64 extended information
// extra field. When encrypting the central directory, if the
// local header is not in ZIP64 format and general purpose bit
// flag 13 is set indicating masking, the value stored for the
// uncompressed size in the Local Header will be zero.
//
// Othewise there is problem with minizip implementation
if (size == uint.MaxValue) {
size = (ulong)extraData.ReadLong();
}
if (compressedSize == uint.MaxValue) {
compressedSize = (ulong)extraData.ReadLong();
}
if (!localHeader && (offset == uint.MaxValue)) {
offset = extraData.ReadLong();
}
// Disk number on which file starts is ignored
} else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
DateTime = GetDateTime(extraData);
if (method == CompressionMethod.WinZipAES) {
ProcessAESExtraData(extraData);
}
}
示例5: PutNextEntry
//.........这里部分代码省略.........
WriteLeInt(-1);
}
else
{
WriteLeInt(0); // Compressed size
WriteLeInt(0); // Uncompressed size
}
}
byte[] name = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
if (name.Length > 0xFFFF)
{
throw new ZipException("Entry name too long.");
}
var ed = new ZipExtraData(entry.ExtraData);
if (entry.LocalHeaderRequiresZip64)
{
ed.StartNewEntry();
if (headerInfoAvailable)
{
ed.AddLeLong(entry.Size);
ed.AddLeLong(entry.CompressedSize);
}
else
{
ed.AddLeLong(-1);
ed.AddLeLong(-1);
}
ed.AddNewEntry(1);
if (!ed.Find(1))
{
throw new ZipException("Internal error cant find extra data");
}
if (patchEntryHeader)
{
sizePatchPos = ed.CurrentReadIndex;
}
}
else
{
ed.Delete(1);
}
#if !NET_1_1 && !NETCF_2_0
if (entry.AESKeySize > 0)
{
AddExtraDataAES(entry, ed);
}
#endif
byte[] extra = ed.GetEntryData();
WriteLeShort(name.Length);
WriteLeShort(extra.Length);
if (name.Length > 0)
{
baseOutputStream_.Write(name, 0, name.Length);
}
if (entry.LocalHeaderRequiresZip64 && patchEntryHeader)
{
示例6: ProcessExtraData
/// <summary>
/// Process extra data fields updating the entry based on the contents.
/// </summary>
/// <param name="localHeader">True if the extra data fields should be handled
/// for a local header, rather than for a central header.
/// </param>
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
// Version required to extract is ignored here as some archivers dont set it correctly
// in theory it should be version 45 or higher
// The recorded size will change but remember that this is zip64.
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
if ( !localHeader && (offset == uint.MaxValue) ) {
offset = extraData.ReadLong();
}
// Disk number on which file starts is ignored
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
dateTime = GetDateTime(extraData);
if (method == CompressionMethod.WinZipAES) {
ProcessAESExtraData(extraData);
}
}
示例7: TestLocalHeader
long TestLocalHeader(ZipEntry entry, HeaderTest tests)
{
lock(baseStream_)
{
bool testHeader = (tests & HeaderTest.Header) != 0;
bool testData = (tests & HeaderTest.Extract) != 0;
baseStream_.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin);
if ((int)ReadLEUint() != ZipConstants.LocalHeaderSignature) {
throw new ZipException(string.Format("Wrong local header signature @{0:X}", offsetOfFirstEntry + entry.Offset));
}
short extractVersion = ( short )ReadLEUshort();
short localFlags = ( short )ReadLEUshort();
short compressionMethod = ( short )ReadLEUshort();
short fileTime = ( short )ReadLEUshort();
short fileDate = ( short )ReadLEUshort();
uint crcValue = ReadLEUint();
long compressedSize = ReadLEUint();
long size = ReadLEUint();
int storedNameLength = ReadLEUshort();
int extraDataLength = ReadLEUshort();
byte[] nameData = new byte[storedNameLength];
StreamUtils.ReadFully(baseStream_, nameData);
byte[] extraData = new byte[extraDataLength];
StreamUtils.ReadFully(baseStream_, extraData);
ZipExtraData localExtraData = new ZipExtraData(extraData);
if (localExtraData.Find(1))
{
if (extractVersion < ZipConstants.VersionZip64)
{
throw new ZipException(
string.Format("Extra data contains Zip64 information but version {0}.{1} is not high enough",
extractVersion / 10, extractVersion % 10));
}
if (((uint)size != uint.MaxValue) && ((uint)compressedSize != uint.MaxValue))
{
throw new ZipException("Entry sizes not correct for Zip64");
}
size = localExtraData.ReadLong();
compressedSize = localExtraData.ReadLong();
if ((localFlags & (int)GeneralBitFlags.Descriptor) != 0)
{
if ( (size != -1) && (size != entry.Size)) {
throw new ZipException("Size invalid for descriptor");
}
if ((compressedSize != -1) && (compressedSize != entry.CompressedSize)) {
throw new ZipException("Compressed size invalid for descriptor");
}
}
}
else
{
if ((extractVersion >= ZipConstants.VersionZip64) &&
(((uint)size == uint.MaxValue) || ((uint)compressedSize == uint.MaxValue)))
{
throw new ZipException("Required Zip64 extended information missing");
}
}
if ( testData ) {
if ( entry.IsFile ) {
if ( !entry.IsCompressionMethodSupported() ) {
throw new ZipException("Compression method not supported");
}
if ( (extractVersion > ZipConstants.VersionMadeBy)
|| ((extractVersion > 20) && (extractVersion < ZipConstants.VersionZip64)) ) {
throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", extractVersion));
}
if ( (localFlags & ( int )(GeneralBitFlags.Patched | GeneralBitFlags.StrongEncryption | GeneralBitFlags.EnhancedCompress | GeneralBitFlags.HeaderMasked)) != 0 ) {
throw new ZipException("The library does not support the zip version required to extract this entry");
}
}
}
if (testHeader)
{
if ((extractVersion <= 63) &&
(extractVersion != 10) &&
(extractVersion != 11) &&
(extractVersion != 20) &&
(extractVersion != 21) &&
(extractVersion != 25) &&
(extractVersion != 27) &&
(extractVersion != 45) &&
(extractVersion != 46) &&
(extractVersion != 50) &&
(extractVersion != 51) &&
(extractVersion != 52) &&
(extractVersion != 61) &&
//.........这里部分代码省略.........
示例8: Skipping
public void Skipping()
{
ZipExtraData zed = new ZipExtraData(new byte[] { 1, 0, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
Assert.AreEqual(11, zed.Length, "Length should be 11");
Assert.IsTrue(zed.Find(1), "Should find tag 1");
Assert.AreEqual(7, zed.UnreadCount);
Assert.AreEqual(4, zed.CurrentReadIndex);
zed.ReadByte();
Assert.AreEqual(6, zed.UnreadCount);
Assert.AreEqual(5, zed.CurrentReadIndex);
zed.Skip(1);
Assert.AreEqual(5, zed.UnreadCount);
Assert.AreEqual(6, zed.CurrentReadIndex);
zed.Skip(-1);
Assert.AreEqual(6, zed.UnreadCount);
Assert.AreEqual(5, zed.CurrentReadIndex);
zed.Skip(6);
Assert.AreEqual(0, zed.UnreadCount);
Assert.AreEqual(11, zed.CurrentReadIndex);
bool exceptionCaught = false;
try {
zed.Skip(1);
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Should fail to skip past end");
Assert.AreEqual(0, zed.UnreadCount);
Assert.AreEqual(11, zed.CurrentReadIndex);
zed.Skip(-7);
Assert.AreEqual(7, zed.UnreadCount);
Assert.AreEqual(4, zed.CurrentReadIndex);
exceptionCaught=false;
try
{
zed.Skip(-1);
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Should fail to skip before beginning");
}
示例9: ProcessAESExtraData
private void ProcessAESExtraData(ZipExtraData extraData)
{
if (!extraData.Find(0x9901))
{
throw new ZipException("AES Extra Data missing");
}
this.versionToExtract = 0x33;
this.Flags |= 0x40;
int valueLength = extraData.ValueLength;
if (valueLength < 7)
{
throw new ZipException("AES Extra Data Length " + valueLength + " invalid.");
}
int num2 = extraData.ReadShort();
extraData.ReadShort();
int num3 = extraData.ReadByte();
int num4 = extraData.ReadShort();
this._aesVer = num2;
this._aesEncryptionStrength = num3;
this.method = (ICSharpCode.SharpZipLib.Zip.CompressionMethod) num4;
}
示例10: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if (extraData.Find(1))
{
this.forceZip64_ = true;
if (extraData.ValueLength < 4)
{
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if (localHeader || (this.size == 0xffffffffL))
{
this.size = (ulong) extraData.ReadLong();
}
if (localHeader || (this.compressedSize == 0xffffffffL))
{
this.compressedSize = (ulong) extraData.ReadLong();
}
if (!localHeader && (this.offset == 0xffffffffL))
{
this.offset = extraData.ReadLong();
}
}
else if (((this.versionToExtract & 0xff) >= 0x2d) && ((this.size == 0xffffffffL) || (this.compressedSize == 0xffffffffL)))
{
throw new ZipException("Zip64 Extended information required but is missing.");
}
if (extraData.Find(10))
{
if (extraData.ValueLength < 4)
{
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while (extraData.UnreadCount >= 4)
{
int num = extraData.ReadShort();
int amount = extraData.ReadShort();
if (num == 1)
{
if (amount >= 0x18)
{
long fileTime = extraData.ReadLong();
extraData.ReadLong();
extraData.ReadLong();
this.DateTime = System.DateTime.FromFileTime(fileTime);
}
break;
}
extraData.Skip(amount);
}
}
else if (extraData.Find(0x5455))
{
int valueLength = extraData.ValueLength;
if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5))
{
int seconds = extraData.ReadInt();
System.DateTime time = new System.DateTime(0x7b2, 1, 1, 0, 0, 0);
this.DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime();
}
}
if (this.method == ICSharpCode.SharpZipLib.Zip.CompressionMethod.WinZipAES)
{
this.ProcessAESExtraData(extraData);
}
}
示例11: ProcessExtraData
internal void ProcessExtraData(bool localHeader)
{
ZipExtraData extraData = new ZipExtraData(this.extra);
if ( extraData.Find(0x0001) ) {
if ( (versionToExtract & 0xff) < ZipConstants.VersionZip64 ) {
throw new ZipException("Zip64 Extended information found but version is not valid");
}
forceZip64_ = true;
if ( extraData.ValueLength < 4 ) {
throw new ZipException("Extra data extended Zip64 information length is invalid");
}
if ( localHeader || (size == uint.MaxValue) ) {
size = (ulong)extraData.ReadLong();
}
if ( localHeader || (compressedSize == uint.MaxValue) ) {
compressedSize = (ulong)extraData.ReadLong();
}
if ( !localHeader && (offset == uint.MaxValue) ) {
offset = extraData.ReadLong();
}
}
else {
if (
((versionToExtract & 0xff) >= ZipConstants.VersionZip64) &&
((size == uint.MaxValue) || (compressedSize == uint.MaxValue))
) {
throw new ZipException("Zip64 Extended information required but is missing.");
}
}
if ( extraData.Find(10) ) {
if ( extraData.ValueLength < 8 ) {
throw new ZipException("NTFS Extra data invalid");
}
extraData.ReadInt();
while ( extraData.UnreadCount >= 4 ) {
int ntfsTag = extraData.ReadShort();
int ntfsLength = extraData.ReadShort();
if ( ntfsTag == 1 ) {
if ( ntfsLength >= 24 ) {
long lastModification = extraData.ReadLong();
long lastAccess = extraData.ReadLong();
long createTime = extraData.ReadLong();
DateTime = System.DateTime.FromFileTime(lastModification);
}
break;
}
else {
extraData.Skip(ntfsLength);
}
}
}
else if ( extraData.Find(0x5455) ) {
int length = extraData.ValueLength;
int flags = extraData.ReadByte();
if ( ((flags & 1) != 0) && (length >= 5) ) {
int iTime = extraData.ReadInt();
DateTime = (new System.DateTime ( 1970, 1, 1, 0, 0, 0 ).ToUniversalTime() +
new TimeSpan ( 0, 0, 0, iTime, 0 )).ToLocalTime();
}
}
}
示例12: PutNextEntry
//.........这里部分代码省略.........
WriteLeShort((byte)method);
WriteLeInt((int)entry.DosTime);
if (headerInfoAvailable == true) {
WriteLeInt((int)entry.Crc);
if ( entry.LocalHeaderRequiresZip64 ) {
WriteLeInt(-1);
WriteLeInt(-1);
}
else {
WriteLeInt(entry.IsCrypted ? (int)entry.CompressedSize + ZipConstants.CryptoHeaderSize : (int)entry.CompressedSize);
WriteLeInt((int)entry.Size);
}
} else {
if (patchEntryHeader == true) {
crcPatchPos = baseOutputStream_.Position;
}
WriteLeInt(0);
if ( patchEntryHeader ) {
sizePatchPos = baseOutputStream_.Position;
}
if ( entry.LocalHeaderRequiresZip64 || patchEntryHeader ) {
WriteLeInt(-1);
WriteLeInt(-1);
}
else {
WriteLeInt(0);
WriteLeInt(0);
}
}
byte[] name = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
if (name.Length > 0xFFFF) {
throw new ZipException("Entry name too long.");
}
ZipExtraData ed = new ZipExtraData(entry.ExtraData);
if (entry.LocalHeaderRequiresZip64) {
ed.StartNewEntry();
if (headerInfoAvailable) {
ed.AddLeLong(entry.Size);
ed.AddLeLong(entry.CompressedSize);
}
else {
ed.AddLeLong(-1);
ed.AddLeLong(-1);
}
ed.AddNewEntry(1);
if ( !ed.Find(1) ) {
throw new ZipException("Internal error cant find extra data");
}
if ( patchEntryHeader ) {
sizePatchPos = ed.CurrentReadIndex;
}
}
else {
ed.Delete(1);
}
byte[] extra = ed.GetEntryData();
WriteLeShort(name.Length);
WriteLeShort(extra.Length);
if ( name.Length > 0 ) {
baseOutputStream_.Write(name, 0, name.Length);
}
if ( entry.LocalHeaderRequiresZip64 && patchEntryHeader ) {
sizePatchPos += baseOutputStream_.Position;
}
if ( extra.Length > 0 ) {
baseOutputStream_.Write(extra, 0, extra.Length);
}
offset += ZipConstants.LocalHeaderBaseSize + name.Length + extra.Length;
curEntry = entry;
crc.Reset();
if (method == CompressionMethod.Deflated) {
deflater_.Reset();
deflater_.SetLevel(compressionLevel);
}
size = 0;
if (entry.IsCrypted == true) {
if (entry.Crc < 0) {
WriteEncryptionHeader(entry.DosTime << 16);
} else {
WriteEncryptionHeader(entry.Crc);
}
}
}
示例13: WriteLocalEntryHeader
private void WriteLocalEntryHeader(ZipUpdate update)
{
ZipEntry outEntry = update.OutEntry;
outEntry.Offset = this.baseStream_.Position;
if (update.Command != UpdateCommand.Copy)
{
if (outEntry.CompressionMethod == CompressionMethod.Deflated)
{
if (outEntry.Size == 0L)
{
outEntry.CompressedSize = outEntry.Size;
outEntry.Crc = 0L;
outEntry.CompressionMethod = CompressionMethod.Stored;
}
}
else if (outEntry.CompressionMethod == CompressionMethod.Stored)
{
outEntry.Flags &= -9;
}
if (this.HaveKeys)
{
outEntry.IsCrypted = true;
if (outEntry.Crc < 0L)
{
outEntry.Flags |= 8;
}
}
else
{
outEntry.IsCrypted = false;
}
switch (this.useZip64_)
{
case ICSharpCode.SharpZipLib.Zip.UseZip64.On:
outEntry.ForceZip64();
break;
case ICSharpCode.SharpZipLib.Zip.UseZip64.Dynamic:
if (outEntry.Size < 0L)
{
outEntry.ForceZip64();
}
break;
}
}
this.WriteLEInt(0x4034b50);
this.WriteLEShort(outEntry.Version);
this.WriteLEShort(outEntry.Flags);
this.WriteLEShort((byte) outEntry.CompressionMethod);
this.WriteLEInt((int) outEntry.DosTime);
if (!outEntry.HasCrc)
{
update.CrcPatchOffset = this.baseStream_.Position;
this.WriteLEInt(0);
}
else
{
this.WriteLEInt((int) outEntry.Crc);
}
if (outEntry.LocalHeaderRequiresZip64)
{
this.WriteLEInt(-1);
this.WriteLEInt(-1);
}
else
{
if ((outEntry.CompressedSize < 0L) || (outEntry.Size < 0L))
{
update.SizePatchOffset = this.baseStream_.Position;
}
this.WriteLEInt((int) outEntry.CompressedSize);
this.WriteLEInt((int) outEntry.Size);
}
byte[] buffer = ZipConstants.ConvertToArray(outEntry.Flags, outEntry.Name);
if (buffer.Length > 0xffff)
{
throw new ZipException("Entry name too long.");
}
ZipExtraData data = new ZipExtraData(outEntry.ExtraData);
if (outEntry.LocalHeaderRequiresZip64)
{
data.StartNewEntry();
data.AddLeLong(outEntry.Size);
data.AddLeLong(outEntry.CompressedSize);
data.AddNewEntry(1);
}
else
{
data.Delete(1);
}
outEntry.ExtraData = data.GetEntryData();
this.WriteLEShort(buffer.Length);
this.WriteLEShort(outEntry.ExtraData.Length);
if (buffer.Length > 0)
{
this.baseStream_.Write(buffer, 0, buffer.Length);
}
if (outEntry.LocalHeaderRequiresZip64)
{
if (!data.Find(1))
//.........这里部分代码省略.........
示例14: ReadOverrunLong
public void ReadOverrunLong()
{
ZipExtraData zed = new ZipExtraData(new byte[] { 1, 0, 0, 0 });
Assert.AreEqual(4, zed.Length, "Length should be 4");
Assert.IsTrue(zed.Find(1), "Should find tag 1");
// Empty Tag
bool exceptionCaught = false;
try {
zed.ReadLong();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
// seven bytes
zed = new ZipExtraData(new byte[] { 1, 0, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
Assert.IsTrue(zed.Find(1), "Should find tag 1");
exceptionCaught = false;
try {
zed.ReadLong();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
zed = new ZipExtraData(new byte[] { 1, 0, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
Assert.IsTrue(zed.Find(1), "Should find tag 1");
zed.ReadLong();
exceptionCaught = false;
try {
zed.ReadLong();
}
catch (ZipException) {
exceptionCaught = true;
}
Assert.IsTrue(exceptionCaught, "Expected EOS exception");
}
示例15: WriteLocalEntryHeader
//.........这里部分代码省略.........
}
else if (entry.CompressionMethod == CompressionMethod.Stored) {
entry.Flags &= ~(int)GeneralBitFlags.Descriptor;
}
if (HaveKeys) {
entry.IsCrypted = true;
if (entry.Crc < 0) {
entry.Flags |= (int)GeneralBitFlags.Descriptor;
}
}
else {
entry.IsCrypted = false;
}
switch (useZip64_) {
case UseZip64.Dynamic:
if (entry.Size < 0) {
entry.ForceZip64();
}
break;
case UseZip64.On:
entry.ForceZip64();
break;
case UseZip64.Off:
break;
}
}
WriteLEInt(ZipConstants.LocalHeaderSignature);
WriteLEShort(entry.Version);
WriteLEShort(entry.Flags);
WriteLEShort((byte)entry.CompressionMethod);
WriteLEInt(( int )entry.DosTime);
if ( !entry.HasCrc ) {
update.CrcPatchOffset = baseStream_.Position;
WriteLEInt(( int )0);
}
else {
WriteLEInt(unchecked(( int )entry.Crc));
}
if (entry.LocalHeaderRequiresZip64) {
WriteLEInt(-1);
WriteLEInt(-1);
}
else {
if ( (entry.CompressedSize < 0) || (entry.Size < 0) ) {
update.SizePatchOffset = baseStream_.Position;
}
WriteLEInt(( int )entry.CompressedSize);
WriteLEInt(( int )entry.Size);
}
byte[] name = ZipConstants.ConvertToArray(entry.Flags, entry.Name);
if ( name.Length > 0xFFFF ) {
throw new ZipException("Entry name too long.");
}
ZipExtraData ed = new ZipExtraData(entry.ExtraData);
if ( entry.LocalHeaderRequiresZip64 ) {
ed.StartNewEntry();
ed.AddLeLong(entry.Size);
ed.AddLeLong(entry.CompressedSize);
ed.AddNewEntry(1);
}
else {
ed.Delete(1);
}
entry.ExtraData = ed.GetEntryData();
WriteLEShort(name.Length);
WriteLEShort(entry.ExtraData.Length);
if ( name.Length > 0 ) {
baseStream_.Write(name, 0, name.Length);
}
if ( entry.LocalHeaderRequiresZip64 ) {
if ( !ed.Find(1) ) {
throw new ZipException("Internal error cannot find extra data");
}
update.SizePatchOffset = baseStream_.Position + ed.CurrentReadIndex;
}
if ( entry.ExtraData.Length > 0 ) {
baseStream_.Write(entry.ExtraData, 0, entry.ExtraData.Length);
}
}