Exemple #1
0
        private void DumpTables(SqliteFileParser parser)
        {
            using (var reader = new SqliteFileReader(parser))
            {
                reader.MasterTableRecordRead += (s, e) => Console.WriteLine($"'{e.Record.Type}'\t'{e.Record.Name}'\t'{e.Record.TableName}'\t{e.Record.RootPage}\t'{e.Record.Sql}'");

                reader.ReadMasterTable();
            }
        }
        protected virtual void Dispose(Boolean disposing)
        {
            if (!this._isDisposed)
            {
                if (disposing)
                {
                    this._parser.Dispose();
                    this._parser = null;
                }

                this._isDisposed = true;
            }
        }
Exemple #3
0
        private void DumpTable(SqliteFileParser parser, String tableName)
        {
            using (var reader = new SqliteFileReader(parser))
            {
                reader.TableRecordRead += (s, e) =>
                {
                    foreach (var field in e.Fields)
                    {
                        Console.Write($"'{field.Value}'\t");
                    }
                    Console.WriteLine();
                };

                reader.ReadTable(tableName);
            }
        }
Exemple #4
0
        private void DumpFilePages(SqliteFileParser parser)
        {
            parser.PageStarted += (s, e) =>
            {
                Console.WriteLine($"--- Page {e.PageNumber}");
                Console.WriteLine($"The b-tree page type:\t\t\t{e.PageHeader.PageType} ({(Int32)e.PageHeader.PageType})");
                Console.WriteLine($"The start of the first freeblock:\t{e.PageHeader.FirstFreeblockOffset}");
                Console.WriteLine($"The number of cells:\t\t\t{e.PageHeader.CellCount}");
                Console.WriteLine($"The start of the cell content area:\t{e.PageHeader.CellContentAreaOffset}");
                Console.WriteLine($"The number of fragmented free bytes:\t{e.PageHeader.FragmentedFreeBytesCount}");

                if ((PageType.IndexInterior == e.PageHeader.PageType) || (PageType.TableInterior == e.PageHeader.PageType))
                {
                    Console.WriteLine($"The right-most pointer:\t\t\t{e.PageHeader.RightMostPointer}");
                }
            };
        }
Exemple #5
0
        private static void ExtractStrings(String dbFilePath)
        {
            using (var parser = new SqliteFileParser(dbFilePath))
            {
                parser.FieldRead += (s, e) =>
                {
                    if (FieldType.String == e.Type)
                    {
                        var text = e.Value as String;
                        if (!String.IsNullOrEmpty(text))
                        {
                            Console.WriteLine(text);
                        }
                    }
                };

                parser.ParseAllPages();
            }
        }
Exemple #6
0
 private void DumpFileHeader(SqliteFileParser parser)
 {
     Console.WriteLine($"The database page size in bytes:\t\t{parser.FileHeader.PageSize}");
     Console.WriteLine($"File format write version:\t\t\t{parser.FileHeader.FileFormatWriteVersion}");
     Console.WriteLine($"File format read version:\t\t\t{parser.FileHeader.FileFormatReadVersion}");
     Console.WriteLine($"Bytes of unused space:\t\t\t\t{parser.FileHeader.PageReservedSize}");
     Console.WriteLine($"Maximum embedded payload fraction:\t\t{parser.FileHeader.MaximumEmbeddedPayloadFraction}");
     Console.WriteLine($"Minimum embedded payload fraction:\t\t{parser.FileHeader.MinimumEmbeddedPayloadFraction}");
     Console.WriteLine($"Leaf payload fraction:\t\t\t\t{parser.FileHeader.LeafPayloadFraction}");
     Console.WriteLine($"File change counter:\t\t\t\t{parser.FileHeader.FileChangeCounter}");
     Console.WriteLine($"Size of the database file in pages:\t\t{parser.FileHeader.PageCount}");
     Console.WriteLine($"Page number of the first freelist trunk page:\t{parser.FileHeader.FirstFreelistPage}");
     Console.WriteLine($"Total number of freelist pages:\t\t\t{parser.FileHeader.FreelistPageCount}");
     Console.WriteLine($"The schema cookie:\t\t\t\t{parser.FileHeader.SchemaCookie}");
     Console.WriteLine($"The schema format number:\t\t\t{parser.FileHeader.SchemaFormatNumber}");
     Console.WriteLine($"Default page cache size:\t\t\t{parser.FileHeader.DefaultPageCacheSize}");
     Console.WriteLine($"Page number of the largest root b-tree page:\t{parser.FileHeader.LargestRootBtreePageNumber}");
     Console.WriteLine($"The database text encoding:\t\t\t{parser.FileHeader.DatabaseTextEncoding}");
     Console.WriteLine($"The 'user version':\t\t\t\t{parser.FileHeader.UserVersion}");
     Console.WriteLine($"Incremental-vacuum mode:\t\t\t{parser.FileHeader.IncrementalVacuumMode}");
     Console.WriteLine($"The 'Application ID':\t\t\t\t{parser.FileHeader.ApplicationId}");
     Console.WriteLine($"The version-valid-for number:\t\t\t{parser.FileHeader.VersionValidForNumber}");
     Console.WriteLine($"SQLITE_VERSION_NUMBER:\t\t\t\t{parser.FileHeader.SqliteVersionNumber} ({parser.FileHeader.SqliteVersionNumberParsed})");
 }
 public SqliteFileReader(SqliteFileParser parser)
 {
     this._parser = parser;
 }
 public SqliteFileReader(Stream stream)
 {
     this._parser = new SqliteFileParser(stream);
 }
 public SqliteFileReader(String dbFilePath)
 {
     this._parser = new SqliteFileParser(dbFilePath);
 }
Exemple #10
0
        protected override Int32 Execute()
        {
            var command    = "";
            var dbFilePath = "";

            if (1 == this._commandLineParser.FileNames.Length)
            {
                command    = "all";
                dbFilePath = this._commandLineParser.FileNames[0];
            }
            else if (2 == this._commandLineParser.FileNames.Length)
            {
                command    = this._commandLineParser.FileNames[0];
                dbFilePath = this._commandLineParser.FileNames[1];
            }
            else
            {
                this.Help();
            }

            using (var parser = new SqliteFileParser(dbFilePath))
            {
                switch (command)
                {
                case "all":
                    this.DumpFileInfo(dbFilePath);
                    PrintLine();
                    this.DumpFileHeader(parser);
                    PrintLine();
                    this.DumpFilePages(parser);
                    break;

                case "h":
                case "header":
                    this.DumpFileHeader(parser);
                    break;

                case "p":
                case "pages":
                    this.DumpFilePages(parser);
                    break;

                case "m":
                case "master":
                    this.DumpTables(parser);
                    return(0);

                case "t":
                case "table":
                    if (this._commandLineParser.OptionHasValue("name"))
                    {
                        this.DumpTable(parser, this._commandLineParser.GetOptionString("name"));
                    }
                    else
                    {
                        this.Help();
                    }
                    return(0);

                default:
                    this.Help();
                    return(0);
                }

                parser.ParseAllPages();
            }

            return(0);

            void PrintLine() => Console.WriteLine("------------------------------------------------------------------------------");
        }