Exemplo n.º 1
0
        public static bool UnmarshalItpfHeader(ref byte[] pData, ref uint pDataPos,
                                               ref uint pDataLen, ref chmItspHeader dest)
        {
            /* we only know how to deal with a 0x54 byte structures */
            if (pDataLen != CHM_ITSP_V1_LEN)
            {
                return(false);
            }

            InitialiseItspHeader(ref dest);

            /* unmarshal fields */
            Unmarshal.ToCharArray(ref pData, ref pDataPos, ref pDataLen, ref dest.signature, 4);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.version);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.header_len);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_000c);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.block_len);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.blockidx_intvl);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.index_depth);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.index_root);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.index_head);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_0024);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.num_blocks);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_002c);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.lang_id);
            Unmarshal.ToUuid(ref pData, ref pDataPos, ref pDataLen, ref dest.system_uuid);
            Unmarshal.ToByteArray(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_0044, 16);

            /* error check the data */
            if (new String(dest.signature).CompareTo("ITSP\0") != 0)
            {
                return(false);
            }
            if (dest.version != 1)
            {
                return(false);
            }
            if (dest.header_len != CHM_ITSP_V1_LEN)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static bool UnmarshalItsfHeader(ref byte[] pData, ref uint pDataPos,
                                               ref uint pDataLen, ref chmItsfHeader dest)
        {
            /* we only know how to deal with the 0x58 and 0x60 byte structures */
            if (pDataLen != CHM_ITSF_V2_LEN && pDataLen != CHM_ITSF_V3_LEN)
            {
                return(false);
            }

            InitialiseItsfHeader(ref dest);

            /* unmarshal common fields */
            Unmarshal.ToCharArray(ref pData, ref pDataPos, ref pDataLen, ref dest.signature, 4);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.version);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.header_len);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_000c);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.last_modified);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.lang_id);
            Unmarshal.ToUuid(ref pData, ref pDataPos, ref pDataLen, ref dest.dir_uuid);
            Unmarshal.ToUuid(ref pData, ref pDataPos, ref pDataLen, ref dest.stream_uuid);
            Unmarshal.ToUInt64(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_offset);
            Unmarshal.ToUInt64(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_len);
            Unmarshal.ToUInt64(ref pData, ref pDataPos, ref pDataLen, ref dest.dir_offset);
            Unmarshal.ToUInt64(ref pData, ref pDataPos, ref pDataLen, ref dest.dir_len);

            /* error check the data */

            /* XXX: should also check UUIDs, probably, though with a version 3 file,
             * current MS tools do not seem to use them.
             */
            if (new String(dest.signature).CompareTo("ITSF") != 0)
            {
                return(false);
            }
            if (dest.version == 2)
            {
                if (dest.header_len < CHM_ITSF_V2_LEN)
                {
                    return(false);
                }
            }
            else if (dest.version == 3)
            {
                if (dest.header_len < CHM_ITSF_V3_LEN)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }

            /* now, if we have a V3 structure, unmarshal the rest.
             * otherwise, compute it
             */
            if (dest.version == 3)
            {
                if (pDataLen != 0)
                {
                    Unmarshal.ToUInt64(ref pData, ref pDataPos, ref pDataLen, ref dest.data_offset);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                dest.data_offset = dest.dir_offset + dest.dir_len;
            }

            return(true);
        }