Beispiel #1
0
        // List CAB contents, MS way
        static void ListCAB(string name)
        {
            FileStream fs = null;

            try
            {
                fs = new FileStream(name, FileMode.Open, FileAccess.Read);
            }
            catch
            {
                Console.WriteLine("Unable to open '{0}' for input", name);
                Environment.Exit(1);
            }

            CFHeader cfh = new CFHeader(fs);

            Console.WriteLine("Listing of cabinet file '{0}' (size {1})", name, fs.Length);
            Console.WriteLine("   {0} file(s), {1} folder(s), set ID {2}, cabinet #{3}\n", cfh.usNumFiles, cfh.usNumFolders, cfh.usSetID, cfh.usCabIndex);

            Console.WriteLine("File name                      File size    Date       Time   Attrs");
            Console.WriteLine("-----------------------------  ---------- ---------- -------- -----");

            fs.Seek(cfh.uiFilesOffset, SeekOrigin.Begin);
            for (int i = 0; i < cfh.usNumFiles; i++)
            {
                CFFile cff = new CFFile(fs);
                Console.WriteLine("   {0,-29} {1,8} {2}  {3}", cff.FileName, cff.uiFileSize, cff.GetDateTime(), cff.GetDosAttributes());
            }

            fs.Close();
        }
Beispiel #2
0
        // Adds a file to the current folder. Returns 0 for success, or
        // 1=not exists, 2=too big (>=4GiB)
        public int AddFile(string PathName, List <string> Strip)
        {
            FileInfo finfo = new FileInfo(PathName);

            if (!finfo.Exists)
            {
                return(1);
            }

            if (finfo.Length > 0xFFFFFFFF)
            {
                return(2);
            }

            CFFile cff = new CFFile();

            cff.uiFileSize      = (uint)finfo.Length;
            cff.uiFolderOffset  = uiNextItemOffset;
            cff.usDOSAttributes = (ushort)finfo.Attributes;
            uint dt = cff.DateTimeToUInt32(finfo.LastWriteTime);

            cff.usDOSDate = (ushort)((dt & 0xFFFF0000) >> 16);
            cff.usDOSTime = (ushort)(dt & 0x0000FFFF);
            cff.SetItemName(PathName, Strip);

            cfFiles.Add(cff);

            uiNextItemOffset += (uint)finfo.Length;
            return(0);
        }
Beispiel #3
0
        public CFFile GetFile(string PathName)
        {
            foreach (CFFolder cfld in cfFolders)
            {
                CFFile cff = cfld.GetFile(PathName);

                if (cff != null)
                {
                    return(cff);
                }
            }
            return(null);
        }
Beispiel #4
0
        // Show detailed information about CAB structures, for debug purposes
        static void DumpCAB(string name)
        {
            FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);

            CFHeader cfh = new CFHeader(fs);

            Console.WriteLine("Cabinet Header");
            Console.WriteLine(cfh);

            fs.Seek(cfh.uiFilesOffset, SeekOrigin.Begin);
            for (int i = 0; i < cfh.usNumFiles; i++)
            {
                Console.Write("@{0:X8}h ", fs.Position);
                CFFile cff = new CFFile(fs);
                Console.WriteLine(cff);
            }

            fs.Seek(cfh.Length, SeekOrigin.Begin);

            Console.WriteLine("Cabinet Folders");

            for (int i = 0; i < cfh.usNumFolders; i++)
            {
                Console.Write("@{0:X8}h ", fs.Position);
                CFFolder cffld = new CFFolder(fs);
                Console.WriteLine(cffld);

                fs.Seek(cffld.uiDataOffset, SeekOrigin.Begin);

                Console.WriteLine("{0} CFDATA blocks", cffld.usBlocks);
                for (int j = 0; j < cffld.usBlocks; j++)
                {
                    Console.Write("@{0:X8}h ", fs.Position);
                    CFData cfd = new CFData(fs, bLoadData:true);
                    Console.WriteLine(cfd);
                }
            }

            fs.Close();
        }
Beispiel #5
0
        // Show detailed information about CAB structures, for debug purposes
        static void DumpCAB(string name)
        {
            FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);

            CFHeader cfh = new CFHeader(fs);

            Console.WriteLine("Cabinet Header");
            Console.WriteLine(cfh);

            fs.Seek(cfh.uiFilesOffset, SeekOrigin.Begin);
            for (int i = 0; i < cfh.usNumFiles; i++)
            {
                Console.Write("@{0:X8}h ", fs.Position);
                CFFile cff = new CFFile(fs);
                Console.WriteLine(cff);
            }

            fs.Seek(cfh.Length, SeekOrigin.Begin);

            Console.WriteLine("Cabinet Folders");

            for (int i = 0; i < cfh.usNumFolders; i++)
            {
                Console.Write("@{0:X8}h ", fs.Position);
                CFFolder cffld = new CFFolder(fs);
                Console.WriteLine(cffld);

                fs.Seek(cffld.uiDataOffset, SeekOrigin.Begin);

                Console.WriteLine("{0} CFDATA blocks", cffld.usBlocks);
                for (int j = 0; j < cffld.usBlocks; j++)
                {
                    Console.Write("@{0:X8}h ", fs.Position);
                    CFData cfd = new CFData(fs, bLoadData: true);
                    Console.WriteLine(cfd);
                }
            }

            fs.Close();
        }
Beispiel #6
0
        public void Load(FileStream srcCab)
        {
            CabFile = srcCab;

            cfFolders = new List <CFFolder>();

            for (int i = 0; i < usNumFolders; i++)
            {
                cfFolders.Add(new CFFolder(CabFile, Length));
            }

            CabFile.Seek(uiFilesOffset, SeekOrigin.Begin);

            for (uint i = 0, lastFolder = 0, lastOffset = 0; i < usNumFiles; i++)
            {
                CFFile cff = new CFFile(CabFile);
                if (cff.uiFolderOffset < lastOffset)
                {
                    lastFolder++;
                }
                lastOffset = cff.uiFolderOffset;
                cfFolders[(int)lastFolder].AddFile(cff);
            }
        }
Beispiel #7
0
 public bool GetFile(CFFile cff)
 {
     return(cfFiles.Contains(cff));
 }
Beispiel #8
0
 public void AddFile(CFFile cff)
 {
     cfFiles.Add(cff);
 }
Beispiel #9
0
        // Adds a file to the current folder. Returns 0 for success, or
        // 1=not exists, 2=too big (>=4GiB)
        public int AddFile(string PathName, List<string> Strip)
        {
            FileInfo finfo = new FileInfo(PathName);

            if (!finfo.Exists)
                return 1;

            if (finfo.Length > 0xFFFFFFFF)
                return 2;

            CFFile cff = new CFFile();
            cff.uiFileSize = (uint)finfo.Length;
            cff.uiFolderOffset = uiNextItemOffset;
            cff.usDOSAttributes = (ushort)finfo.Attributes;
            uint dt = cff.DateTimeToUInt32(finfo.LastWriteTime);
            cff.usDOSDate = (ushort)((dt & 0xFFFF0000) >> 16);
            cff.usDOSTime = (ushort)(dt & 0x0000FFFF);
            cff.SetItemName(PathName, Strip);

            cfFiles.Add(cff);

            uiNextItemOffset += (uint)finfo.Length;
            return 0;
        }
Beispiel #10
0
 public bool GetFile(CFFile cff)
 {
     return cfFiles.Contains(cff);
 }
Beispiel #11
0
 public void AddFile(CFFile cff)
 {
     cfFiles.Add(cff);
 }
Beispiel #12
0
 static int CFFile_Compare(CFFile a, CFFile b)
 {
     return a.uiFolderOffset.CompareTo(b.uiFolderOffset);
 }
Beispiel #13
0
 static int CFFile_Compare(CFFile a, CFFile b)
 {
     return(a.uiFolderOffset.CompareTo(b.uiFolderOffset));
 }
Beispiel #14
0
        public void Load(FileStream srcCab)
        {
            CabFile = srcCab;

            cfFolders = new List<CFFolder>();

            for (int i = 0; i < usNumFolders; i++)
            {
                cfFolders.Add(new CFFolder(CabFile, Length));
            }

            CabFile.Seek(uiFilesOffset, SeekOrigin.Begin);

            for (uint i = 0, lastFolder = 0, lastOffset = 0; i < usNumFiles; i++)
            {
                CFFile cff = new CFFile(CabFile);
                if (cff.uiFolderOffset < lastOffset)
                    lastFolder++;
                lastOffset = cff.uiFolderOffset;
                cfFolders[(int)lastFolder].AddFile(cff);
            }
        }
Beispiel #15
0
        // List CAB contents, MS way
        static void ListCAB(string name)
        {
            FileStream fs = null;

            try
            {
                fs = new FileStream(name, FileMode.Open, FileAccess.Read);
            }
            catch
            {
                Console.WriteLine("Unable to open '{0}' for input", name);
                Environment.Exit(1);
            }

            CFHeader cfh = new CFHeader(fs);

            Console.WriteLine("Listing of cabinet file '{0}' (size {1})", name, fs.Length);
            Console.WriteLine("   {0} file(s), {1} folder(s), set ID {2}, cabinet #{3}\n", cfh.usNumFiles, cfh.usNumFolders, cfh.usSetID, cfh.usCabIndex);

            Console.WriteLine("File name                      File size    Date       Time   Attrs");
            Console.WriteLine("-----------------------------  ---------- ---------- -------- -----");

            fs.Seek(cfh.uiFilesOffset, SeekOrigin.Begin);
            for (int i = 0; i < cfh.usNumFiles; i++)
            {
                CFFile cff = new CFFile(fs);
                Console.WriteLine("   {0,-29} {1,8} {2}  {3}", cff.FileName, cff.uiFileSize, cff.GetDateTime(), cff.GetDosAttributes());
            }

            fs.Close();
        }