SQLite in mobile apps
Most apps keep local data in SQLite: caches, offline copies of the user's data, analytics queues, tokens, and the stores behind Room (Android), Core Data (iOS), Realm-compatibility layers and many SDKs. The tool reads the file format directly, with no SQL engine, so it also opens databases it can't write to and shows changes that are still in the WAL file. Everything runs in your browser and nothing is uploaded.
- Android:
/data/data/<package>/databases/ on a device; sometimes shipped pre-filled under assets/ in the APK.
- iOS: the app's
Library/Application Support, Documents or Library/Caches; Core Data stores end in .sqlite.
Contents
- The file format
- WAL files
- Encrypted databases
- Browsing
- Values and dates
- Deleted rows
- Limits
- The SQLite library
2WAL files
In write-ahead-log mode (the default for Room and Core Data), changes are first appended to <name>-wal and copied into the database only at a checkpoint. A database copied without its WAL can be minutes or days behind. Select both files when opening, and the tool applies every committed frame on top of the database, so the newest version of each page wins. Frames after the last commit are left out and counted. The -shm file is only an index and isn't needed.
When the header says WAL mode and no WAL file was given, the Overview warns about it.
3Encrypted databases
SQLCipher, and SQLite's own encryption extensions, encrypt every page including the first, so the file has no readable header and looks like random bytes. The tool recognises this and says so. Reading it needs the key, which the app passes to sqlite3_key, PRAGMA key or the SQLCipher open call (in .NET apps, the SQLiteConnectionString / SQLitePCLRaw setup). Find it in the code, or capture it at run time, then decrypt with SQLCipher and open the result here.
4Browsing
- Tables (left) lists tables, views, indexes and triggers. Row counts fill in as they're counted. Views and triggers show their SQL; indexes can be browsed like tables (their columns, then the rowid of the row they point to).
- The grid shows every row, including tables with millions of them: only the rows on screen are drawn, and they're read as you scroll. The first column is the row's position; for rowid tables the next is the rowid (named after the
INTEGER PRIMARY KEY column if there is one).
- Filter rows keeps the rows where any value contains the text (or whose rowid equals it), and highlights the matches.
- Search all looks for the text in every value of every table, which is a quick way to find tokens, e-mail addresses, URLs or keys. Click a hit to go to that cell.
- Schema shows the table's
CREATE statement. CSV and JSON download the whole table (blobs as hex).
- Use the arrow keys to move between cells.
Esc closes the cell inspector.
5Values and dates
Click a cell to inspect it in full. Text is shown whole (JSON is pretty-printed). Blobs show their size, a guess at their kind (binary plist, PNG, JPEG, gzip, zip, an embedded SQLite database…), any readable text and a hex dump. A blob can be downloaded, opened in the Plist tool, or opened as a database.
Apps store dates as plain numbers, so for numbers the inspector lists the plausible readings between 1990 and 2045: Unix seconds, milliseconds or microseconds, Core Data's seconds since 2001, WebKit/Chrome microseconds since 1601, .NET ticks and Julian days.
6Deleted rows
SQLite doesn't wipe what it deletes (unless secure_delete is on). A deleted row's cell becomes a freeblock on its page, whose first 4 bytes are overwritten with the freeblock's own bookkeeping; when the page is rearranged the old bytes stay in its unused space; a page left empty goes to the freelist with its cells intact. Updates leave the old version of a row behind the same way.
After the tables are counted, the tool reads records from those places: each table's pages (including interior pages that were once leaves), and the free pages. A record is kept only when it parses exactly, has the table's number of columns, stores the INTEGER PRIMARY KEY column as NULL as SQLite does, and its text looks like text. In a freeblock, the overwritten bytes held the record's length and rowid (and sometimes the start of its header), so those rows come back without their rowid; the rest of the header is rebuilt when the lost part can only be one thing, and the record must end exactly where the next one begins. Rows on free pages are matched to a table by their columns' types. Copies identical to a live row are left out; a different version of a live row is marked as an older version.
They are listed under Recovered (deleted rows), one entry per table, with a found in column (the page and where on it). They can be filtered, inspected and exported like any table. What was overwritten since is gone: vacuuming, or new rows reusing the space, destroys deleted data.
7Limits
- There's no SQL engine. You can browse, filter and search, but not run queries. Views show their definition, not their rows.
- Recovery skips rows that spilled onto overflow pages, WITHOUT ROWID tables and index entries, and rows still in a rollback journal or an old WAL frame.
- Rollback journals (
-journal) are not applied.
- The file is read into memory, up to 1 GB per file.
8The SQLite library
The reader is lib/sqlite.js, a JavaScript module with no dependencies and no user interface. It exports SqliteDatabase: an instance is an opened database, and the static methods are helpers. It also runs in a Web Worker (the tool uses it in sqlite/sqlite-worker.js, started with new WorkerClient(new URL("./sqlite-worker.js", import.meta.url)) from lib/worker-channel.js) or in jsc.
import { SqliteDatabase } from "../lib/sqlite.js";
| Method / property | What it does |
| SqliteDatabase.open(bytes, walBytes) | Opens a database from an ArrayBuffer or Uint8Array, applying the committed frames of the optional -wal file. Throws an Error with code "encrypted" or "notsqlite" and the entropy of the first 4 KB. |
| database.header | pageSize, pageCount, encoding (1 UTF-8, 2 UTF-16le, 3 UTF-16be), journal ("WAL" or "rollback"), wal ({ frames, committed, uncommitted, pages } or null), userVersion, applicationId, sqliteVersion, freelistTrunk, freelistCount, fileSize and the other header fields. |
| database.schema() | Every object, sqlite_schema itself first: { type, name, tableName, rootPage, sql, columns: [{ name, type, primaryKey }], rowidColumn, withoutRowid, virtual }. rowidColumn is the index of the INTEGER PRIMARY KEY column, or -1. |
| database.locate(object) | Where the rows of a table or index are, in rowid or key order: { pages, cells, count }. Cached. |
| database.row(object, location, index, full) | { rowid, values } for the row at that position. Values are null, numbers, BigInts (beyond 253), strings, { real } for REAL values, { blob: Uint8Array }, or, with full false, { text, cut } for a text over 4096 bytes. The INTEGER PRIMARY KEY column is filled with the rowid. |
| database.recover(progress) | Deleted rows and older versions of changed rows (see Deleted rows): a Map from table name to [{ table, rowid, values, where, page, offset, partial, types, note }]. rowid is null when it was overwritten; note is "", "rowid lost" or "older version of a live row". progress(done, total) is optional. |
| database.freelist() | The numbers of the free pages (trunks and leaves). |
| database.page(n), database.btree(n) | Page n's bytes (the WAL version if there is one), and a b-tree page's header: { bytes, type, cellCount, pointersStart, rightChild, cell(i) }. |
| database.text(bytes), database.problems | Bytes decoded in the database's encoding; the problems met while reading, as sentences. |
| SqliteDatabase.isSqlite(bytes), SqliteDatabase.entropy(bytes) | Whether the bytes start with the SQLite header; bits per byte of the first 4 KB (close to 8 for an encrypted file). |
| SqliteDatabase.varint(bytes, offset) | A SQLite varint: [value, next offset]. |
| SqliteDatabase.parseCreate(sql, type) | The columns of a CREATE TABLE statement: { columns, rowidColumn, withoutRowid, virtual }. |
<script type="module">
import { SqliteDatabase } from "../lib/sqlite.js";
const database = SqliteDatabase.open(databaseBytes, walBytes);
const users = database.schema().find(object => object.name === "users");
const location = database.locate(users);
for (let index = 0; index < location.count; index++) {
const row = database.row(users, location, index, true);
console.log(row.rowid, row.values);
}
for (const [table, rows] of database.recover()) {
console.log(table, rows.length, "deleted rows");
}
</script>