简体   繁体   English

如何计算 zip header 中“version by”的值?

[英]How to compute the value for `version made by` in zip header?

I'm struggling to compute the correct value for version made by in adm-zip .我正在努力计算adm-zipversion made by正确值

The Zip Spec is unclear in my opinion how to find the binary or int value to set an option (eg Option 3 Unix ) to the depending 2 Bytes in the central header .我认为Zip 规范不清楚如何找到二进制或整数值以将选项(例如Option 3 Unix )设置为中央 header中依赖的 2 个字节。

The docs from adm-zip for the header setting does not help at all.来自 adm-zip 的header设置的文档根本没有帮助。

Mapping from the zip spec (4.4.2):来自 zip 规范 (4.4.2) 的映射:

4.4.2.2 The current mappings are: 4.4.2.2 目前的映射是:

 0 - MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems) 1 - Amiga 2 - OpenVMS 3 - UNIX 4 - VM/CMS

I have found one possible solution by setting the entry.header.made property to 788 .我通过将entry.header.made属性设置为788找到了一种可能的解决方案。

(entry.header as any).made = 788;

(This value was only found by importing a zip created by another zip util.) (此值仅通过导入由另一个 zip 实用程序创建的 zip 找到。)

Can anyone explain how to compute this value 788 starting from the desired option 3?谁能解释如何从所需的选项 3 开始计算这个值788

Or how to compute this value for another option eg 10 - Windows NTFS ?或者如何为另一个选项计算此值,例如10 - Windows NTFS

Short description:简短的介绍:

According to the specification the upper byte represents the OS which created the ZIP file.根据规范,高位字节代表创建 ZIP 文件的操作系统。 The lower byte is the version of the used ZIP specification.低字节是使用的 ZIP 规范的版本。

In your example:在你的例子中:

788 = 0x0314 788 = 0x0314

OS which created the ZIP file:创建 ZIP 文件的操作系统:
0x03 (Upper Byte): UNIX 0x03 (高字节): UNIX

4.4.2.1 The upper byte indicates the compatibility of the file attribute information. 4.4.2.1 高字节表示文件属性信息的兼容性。 If the external file attributes are compatible with MS-DOS and can be read by PKZIP for DOS version 2.04g then this value will be zero.如果外部文件属性与 MS-DOS 兼容并且可以通过 PKZIP 读取 DOS 版本 2.04g,则此值将为零。 If these attributes are not compatible, then this value will identify the host system on which the attributes are compatible.如果这些属性不兼容,则此值将标识属性兼容的主机系统。 Software can use this information to determine the line record format for text files etc.软件可以使用此信息来确定文本文件等的行记录格式。

ZIP specification version: ZIP 规格版本:
0x14 (Lower Byte): Version 2.0 0x14 (低字节): 2.0 版

0x14 / 10 = 2 (Major version number) 0x14 / 10 = 2 (主要版本号)
0x14 % 10 = 0 (Minor version number) 0x14 % 10 = 0 (次版本号)

4.4.2.3 The lower byte indicates the ZIP specification version (the version of this document) supported by the software used to encode the file. 4.4.2.3 低位字节表示编码文件的软件支持的ZIP规范版本(本文档的版本)。 The value/10 indicates the major version number, and the value mod 10 is the minor version number. value/10 表示主版本号,value mod 10 是次版本号。

For Windows NTFS, the correct "version made by" value should be:对于 Windows NTFS,正确的“version made by”值应该是:

0x0A14 = 2580 0x0A14 = 2580

0x0A (Upper Byte): Windows NTFS (Win32) 0x0A (高字节): Windows NTFS (Win32)
0x14 (Lower Byte): Version 2.0 0x14 (低字节): 2.0 版

Extract from adm-zip source :adm-zip 源中提取:

var _verMade = 0x14,
        _version = 0x0A,
        _flags = 0,
        _method = 0,
        _time = 0,
        _crc = 0,
        _compressedSize = 0,
        _size = 0,
        _fnameLen = 0,
        _extraLen = 0,

        _comLen = 0,
        _diskStart = 0,
        _inattr = 0,
        _attr = 0,
        _offset = 0;

    switch(process.platform){
        case 'win32':
            _verMade |= 0x0A00;
        case 'darwin':
            _verMade |= 0x1300;
        default:
            _verMade |= 0x0300;
    }

Here you can see, that the version 2.0 ( 0x14 ) from the ZIP specification is used and there is a simple OR with the left shifted OS which created the ZIP file.在这里您可以看到,使用了 ZIP 规范中的版本2.0 ( 0x14 ),并且有一个简单的 OR 与左移操作系统创建了 ZIP 文件。

UPDATE:更新:
I wrote a few simple JavaScript example functions which returns the right value for verMade and which returns the OS, major and minor version number from verMade .我写了一些简单的 JavaScript 示例函数,它返回 verMade 的正确值,并从verMade返回操作系统、主要和次要版本verMade

Set version:设置版本:

function zip_version_set(os, spec_major, spec_minor)
{
    var ret = (parseInt(spec_major, 10) * 10) + parseInt(spec_minor, 10);
    
    switch (os) {
    case "dos":
        ret |= 0x0000;
        break;
    case "win32":
        ret |= 0x0A00;
        break;
    case "darwin":
        ret |= 0x1300;
        break;
    default:
        ret |= 0x0300;
    }
    
    return ret;
}

Usage:用法:
Argument os :参数os
Put her the OS string.把她的操作系统字符串。 Currently possible values are dos (MS-DOS), win32 (Windows NTFS), darwin (OS X) and the default is unix .当前可能的值为dos (MS-DOS)、 win32 (Windows NTFS)、 darwin (OS X),默认值为unix

Argument spec_major :参数spec_major
Put here the major version number from the used ZIP specification.将所用 ZIP 规范的主要版本号放在这里。

Argument spec_minor :参数spec_minor
Put here the minor version number from the used ZIP specification.将使用的 ZIP 规范中的次要版本号放在这里。

Return :返回
Returns verMade .返回verMade

Get OS:获取操作系统:

function zip_version_get_os(verMade)
{
    var tmp;
    var ret;
    
    tmp = (verMade & 0xFF00) >> 8;
    
    switch (tmp) {
    case 0x00:
        ret = "dos";
        break;
    case 0x03:
        ret = "unix";
        break;
    case 0x0A:
        ret = "win32";
        break;
    case 0x13:
        ret = "darwin";
        break;
    default:
        ret = "unimplemented";
    }
    
    return ret;
}

Usage:用法:
Argument verMade :参数verMade
Put here the verMade value.verMade值放在这里。

Return:返回:
Returns the OS as string.以字符串形式返回操作系统。

Get major version number (ZIP specification):获取主要版本号(ZIP 规范):

function zip_version_get_major(verMade)
{
    return ((verMade & 0xFF) / 10);
}

Usage:用法:
Argument verMade :参数verMade
Put here the verMade value.verMade值放在这里。

Return:返回:
Returns the major version from the used ZIP specification.从使用的 ZIP 规范返回主要版本。

Get minor version number (ZIP specification):获取次要版本号(ZIP 规范):

function zip_version_get_minor(verMade)
{
    return ((verMade & 0xFF) % 10);
}

Usage:用法:
Argument verMade :参数verMade
Put here the verMade value.verMade值放在这里。

Return:返回:
Returns the minor version from the used ZIP specification.从使用的 ZIP 规范返回次要版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM