Ejemplo n.º 1
0
        public static bool UnmarshalPmglHeader(ref byte[] pData, ref uint pDataPos,
                                               ref uint pDataLen, ref chmPmglHeader dest)
        {
            /* we only know how to deal with a 0x14 byte structures */
            if (pDataLen != CHM_PMGL_LEN)
            {
                return(false);
            }

            InitialisePmglHeader(ref dest);

            /* unmarshal fields */
            Unmarshal.ToCharArray(ref pData, ref pDataPos, ref pDataLen, ref dest.signature, 4);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.free_space);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.unknown_0008);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.block_prev);
            Unmarshal.ToInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.block_next);

            /* check structure */
            if (new String(dest.signature, 0, 4).CompareTo(CHM_PMGL_MARKER) != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static SystemFile Read(ChmFile f)
        {
            List <SystemFileEntry> sfelst = new List <SystemFileEntry>();
            ChmUnitInfo            ui     = new ChmUnitInfo();

            byte[] buf;
            uint   pos = 0, remaining = 0;

            if (!f.ResolveObject("/#SYSTEM", ref ui))
            {
                throw new InvalidOperationException("Could not find SYSTEM file in CHM!");
            }

            buf       = new byte[ui.length];
            remaining = (uint)buf.Length;

            if (f.RetrieveObject(ui, ref buf, 0, (long)ui.length) == 0)
            {
                throw new InvalidOperationException("Could not read SYSTEM file in CHM!");
            }

            Int32 version = 0;

            Unmarshal.ToInt32(ref buf, ref pos, ref remaining, ref version);

            for ( ; pos < buf.Length;)
            {
                SystemFileEntry sfe = new SystemFileEntry();

                Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.code);
                Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.length);

                sfe.data = new byte[sfe.length];
                Array.Copy(buf, pos, sfe.data, 0, sfe.length);

                pos       += sfe.length;
                remaining -= sfe.length;

                sfelst.Add(sfe);
            }

            return(new SystemFile(version, sfelst.ToArray()));
        }
Ejemplo n.º 4
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);
        }