示例#1
0
        internal void ProcessEndBlock(bool verbose, bool extract, bool summary)
        {
            if (inFile)
            {   // End of a file
                if (extract && loadIt)
                {
                    writeStream.Close();
                }
                if (summary)
                {
                    Console.WriteLine(" {0, 12} bytes", totalFileSize);
                }
                totalFileSize = 0;
                inFile        = false;
            }
            else
            {   // "End of a Directory" i.e. move up to superior one
                // don't move above start dir for safety...
                if (workingDir != baseDir)
                {
                    workingDir = Directory.GetParent(workingDir).ToString();
                }
                if (verbose)
                {
                    Console.WriteLine(" Popped dir - new dir is: " + workingDir);
                }
            }

            if (verbose)
            {
                Console.WriteLine("End Block Processed");
            }
        }
示例#2
0
        internal void ProcessDataBlock(RecordHeader recHdr, bool verbose, bool extract)
        {
            var     baBytes = ReadBlob(4);
            DgDword ba      = (DgDword)baBytes[0] << 24;

            ba |= (DgDword)baBytes[1] << 16;
            ba |= (DgDword)baBytes[2] << 8;
            ba |= (DgDword)baBytes[3];

            var     blBytes = ReadBlob(4);
            DgDword bl      = (DgDword)blBytes[0] << 24;

            bl |= (DgDword)blBytes[1] << 16;
            bl |= (DgDword)blBytes[2] << 8;
            bl |= (DgDword)blBytes[3];

            var aln = ReadWord();

            if (verbose)
            {
                Console.WriteLine(" Data Block: {0} (bytes)", bl);
            }

            // skip any alignment bytes (usually zero or one, could be more in theory)
            if (aln > 0)
            {
                if (verbose)
                {
                    Console.WriteLine("  Skipping {0} alignment byte(s)", aln);
                }
                _ = ReadBlob(aln);
            }

            var dataBlob = ReadBlob((int)bl);

            if (extract)
            {
                try
                {
                    // large areas of NULLs may be skipped over by DUMP_II/III
                    // this is achieved by simply advancing the block address so
                    // we must pad out if block address is beyond end of last block
                    if (ba > totalFileSize + 1)
                    {
                        var paddingSize   = ba - totalFileSize;
                        var paddingBlocks = paddingSize / DgDiskBlockBytes;
                        var paddingBlock  = new byte[DgDiskBlockBytes];
                        for (int p = 0; p < paddingBlocks; p++)
                        {
                            if (verbose)
                            {
                                Console.WriteLine("  Padding with one block");
                            }
                            writeStream.Write(paddingBlock);
                            totalFileSize += DgDiskBlockBytes;
                        }
                    }
                    writeStream.Write(dataBlob);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: Could not write data to file - {0}", e.Message);
                    System.Environment.Exit(1);
                }
            }
            totalFileSize += bl;
            inFile         = true;
        }