Beispiel #1
0
        public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
        {
            var fileGroups       = new List <FileGroup>();
            var fileGroupOffsets = new List <uint>();

            hdrFile      = context.Open(hdrFilename);
            this.context = context;

            // Strips archive number AND file extension
            Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
            var signature = hdrFile.ReadUInt32();

            if (signature != 0x28635349)
            {
                throw new InvalidDataException("Not an Installshield CAB package");
            }

            commonHeader  = new CommonHeader(hdrFile);
            cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
            /*    unknown   */ hdrFile.ReadBytes(14);

            for (var i = 0U; i < MaxFileGroupCount; ++i)
            {
                fileGroupOffsets.Add(hdrFile.ReadUInt32());
            }

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
            directoryTable = new List <uint>();

            for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
            {
                directoryTable.Add(hdrFile.ReadUInt32());
            }

            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
                    var descriptorOffset = hdrFile.ReadUInt32();
                    nextOffset = hdrFile.ReadUInt32();
                    hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);

                    fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
                }
            }

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
                {
                    AddFileDescriptorToList(i);
                    var fileDescriptor = fileDescriptors[i];
                    var fullFilePath   = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
                    index.Add(fullFilePath, i);
                }
            }
        }
        public InstallShieldCABCompression(Stream header, Dictionary <int, Stream> volumes)
        {
            this.volumes = volumes;

            if (header.ReadUInt32() != 0x28635349)
            {
                throw new InvalidDataException("Not an Installshield CAB package");
            }

            header.Position += 8;
            var cabDescriptorOffset = header.ReadUInt32();

            header.Position = cabDescriptorOffset + 12;
            var cabDescriptor = new CabDescriptor(header);

            header.Position += 14;

            var fileGroupOffsets = new uint[MaxFileGroupCount];

            for (var i = 0; i < MaxFileGroupCount; i++)
            {
                fileGroupOffsets[i] = header.ReadUInt32();
            }

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset;
            var directories = new DirectoryDescriptor[cabDescriptor.DirectoryCount];

            for (var i = 0; i < directories.Length; i++)
            {
                directories[i] = new DirectoryDescriptor(header, cabDescriptorOffset + cabDescriptor.FileTableOffset);
            }

            var fileGroups = new List <FileGroup>();

            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    header.Position = cabDescriptorOffset + (long)nextOffset + 4;
                    var descriptorOffset = header.ReadUInt32();
                    nextOffset      = header.ReadUInt32();
                    header.Position = cabDescriptorOffset + descriptorOffset;

                    fileGroups.Add(new FileGroup(header, cabDescriptorOffset));
                }
            }

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2;
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; i++)
                {
                    header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2 + i * 0x57;
                    var file = new FileDescriptor(header, i, cabDescriptorOffset + cabDescriptor.FileTableOffset);
                    var path = "{0}\\{1}\\{2}".F(fileGroup.Name, directories[file.DirectoryIndex].Name, file.Filename);
                    index[path] = file;
                }
            }
        }
        public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
        {
            var fileGroups = new List<FileGroup>();
            var fileGroupOffsets = new List<uint>();

            hdrFile = context.Open(hdrFilename);
            this.context = context;

            // Strips archive number AND file extension
            Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
            var signature = hdrFile.ReadUInt32();

            if (signature != 0x28635349)
                throw new InvalidDataException("Not an Installshield CAB package");

            commonHeader = new CommonHeader(hdrFile);
            cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
            /*    unknown   */ hdrFile.ReadBytes(14);

            for (var i = 0U; i < MaxFileGroupCount; ++i)
                fileGroupOffsets.Add(hdrFile.ReadUInt32());

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
            directoryTable = new List<uint>();

            for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
                directoryTable.Add(hdrFile.ReadUInt32());

            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
                    var descriptorOffset = hdrFile.ReadUInt32();
                    nextOffset = hdrFile.ReadUInt32();
                    hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);

                    fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
                }
            }

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
                {
                    AddFileDescriptorToList(i);
                    var fileDescriptor = fileDescriptors[i];
                    var fullFilePath   = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
                    index.Add(fullFilePath, i);
                }
            }
        }
        public InstallShieldCABCompression(Stream header, Dictionary<int, Stream> volumes)
        {
            this.volumes = volumes;

            if (header.ReadUInt32() != 0x28635349)
                throw new InvalidDataException("Not an Installshield CAB package");

            header.Position += 8;
            var cabDescriptorOffset = header.ReadUInt32();
            header.Position = cabDescriptorOffset + 12;
            var cabDescriptor = new CabDescriptor(header);
            header.Position += 14;

            var fileGroupOffsets = new uint[MaxFileGroupCount];
            for (var i = 0; i < MaxFileGroupCount; i++)
                fileGroupOffsets[i] = header.ReadUInt32();

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset;
            var directories = new DirectoryDescriptor[cabDescriptor.DirectoryCount];
            for (var i = 0; i < directories.Length; i++)
                directories[i] = new DirectoryDescriptor(header, cabDescriptorOffset + cabDescriptor.FileTableOffset);

            var fileGroups = new List<FileGroup>();
            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    header.Position = cabDescriptorOffset + (long)nextOffset + 4;
                    var descriptorOffset = header.ReadUInt32();
                    nextOffset = header.ReadUInt32();
                    header.Position = cabDescriptorOffset + descriptorOffset;

                    fileGroups.Add(new FileGroup(header, cabDescriptorOffset));
                }
            }

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2;
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; i++)
                {
                    header.Position = cabDescriptorOffset +	cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2 + i * 0x57;
                    var file = new FileDescriptor(header, i, cabDescriptorOffset + cabDescriptor.FileTableOffset);
                    var path = "{0}\\{1}\\{2}".F(fileGroup.Name, directories[file.DirectoryIndex].Name, file.Filename);
                    index[path] = file;
                }
            }
        }