add something to dump the mozilla favicon file

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-20 00:34:18 -06:00
parent 33f46be98b
commit 0a0f11d4f1
7 changed files with 208 additions and 2 deletions

5
example-favicon/Makefile Normal file
View File

@ -0,0 +1,5 @@
build:
# export GO111MODULE="off"; go get -v -x .
export GO111MODULE="off"; go build
ls -l ~/.mozilla/firefox/*/favicons.sqlite
./example-favicon

Binary file not shown.

169
example-favicon/main.go Normal file
View File

@ -0,0 +1,169 @@
package main
import (
"database/sql"
"log"
"fmt"
_ "github.com/mattn/go-sqlite3"
)
func parseFaviconsSQLite(filePath string) {
// Open the SQLite database
db, err := sql.Open("sqlite3", "favicons.sqlite")
if err != nil {
log.Fatal(err)
}
defer db.Close()
rowId, err := db.Query("SELECT id, icon_url, icon_data FROM moz_icons")
if err == nil {
for rowId.Next() {
var id int
var url string
var data any
err = rowId.Scan(&id, &url, &data)
log.Printf("Data:", id, url, data)
}
}
return
// Query the favicons table
rows, err := db.Query("SELECT * FROM moz_icons")
if err != nil {
log.Println("open worked, err =", err)
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var col1, col2, col3, col4, col5, col6, col7, col8 any // Define variables according to the column data types
err = rows.Scan(&col1, &col2, &col3, &col4, &col5, &col6, &col7, &col8)
if err != nil {
log.Fatal(err)
}
// Process the data
log.Printf("Data: %v, %v, %v, %v, %v, %v, %v, %v\n", col1, col2, col3, col4, col5, col6, col7, col8)
}
/*
log.Println("about to for rows.Next()")
// Iterate through the rows
for rows.Next() {
var id int
var iconURL string
var iconData []byte
var var1 any
var var2 any
var var3 []byte
log.Println("row.Scan()")
err = rows.Scan(&id, &iconURL, &iconData)
if err != nil {
log.Fatal(err)
}
// Process the favicon data (example: just print it)
fmt.Printf("ID: %d, URL: %s, Data: %x\n", id, iconURL, iconData)
}
*/
// Check for errors from iterating over rows
err = rows.Err()
if err != nil {
log.Fatal(err)
}
}
func main() {
// Replace with the path to your favicons.sqlite file
filePath := "./"
parseFaviconsSQLite(filePath)
fmt.Println()
fmt.Println("SHOW tables:")
listTablesSQLite(filePath)
fmt.Println()
fmt.Println("SHOW schema:")
dumpTableSchemas(filePath)
}
func listTablesSQLite(filePath string) {
// Open the SQLite database
db, err := sql.Open("sqlite3", "favicons.sqlite")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Query the sqlite_master table for all table names
rows, err := db.Query("SELECT name FROM sqlite_master WHERE type='table'")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
// Iterate through the rows
for rows.Next() {
var tableName string
err = rows.Scan(&tableName)
if err != nil {
log.Fatal(err)
}
// Print each table name
fmt.Println(tableName)
}
// Check for errors from iterating over rows
err = rows.Err()
if err != nil {
log.Fatal(err)
}
}
func dumpTableSchemas(filePath string) {
// Open the SQLite database
db, err := sql.Open("sqlite3", "favicons.sqlite")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Query for the SQL create statements of each table
rows, err := db.Query("SELECT name, sql FROM sqlite_master WHERE type='table'")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
// Iterate through the rows
for rows.Next() {
var tableName, createStatement string
err = rows.Scan(&tableName, &createStatement)
if err != nil {
log.Fatal(err)
}
// Print the table name and its create statement
fmt.Printf("Table: %s\n", tableName)
fmt.Printf("Create Statement:\n%s\n\n", createStatement)
}
// Check for errors from iterating over rows
err = rows.Err()
if err != nil {
log.Fatal(err)
}
// moz_pages_w_icons ( id INTEGER PRIMARY KEY, page_url TEXT
rowId, err := db.Query("SELECT id, page_url FROM moz_pages_w_icons")
for rowId.Next() {
var id int
var url string
rowId.Scan(&id, &url)
// if err != nil {
log.Println("row =", id, url)
}
}

View File

@ -0,0 +1,20 @@
moz_icons
moz_pages_w_icons
moz_icons_to_pages
sqlite_stat1
Table: moz_icons
Create Statement:
CREATE TABLE moz_icons ( id INTEGER PRIMARY KEY, icon_url TEXT NOT NULL, fixed_icon_url_hash INTEGER NOT NULL, width INTEGER NOT NULL DEFAULT 0, root INTEGER NOT NULL DEFAULT 0, color INTEGER, expire_ms INTEGER NOT NULL DEFAULT 0, data BLOB )
Table: moz_pages_w_icons
Create Statement:
CREATE TABLE moz_pages_w_icons ( id INTEGER PRIMARY KEY, page_url TEXT NOT NULL, page_url_hash INTEGER NOT NULL )
Table: moz_icons_to_pages
Create Statement:
CREATE TABLE moz_icons_to_pages ( page_id INTEGER NOT NULL, icon_id INTEGER NOT NULL, expire_ms INTEGER NOT NULL DEFAULT 0, PRIMARY KEY (page_id, icon_id), FOREIGN KEY (page_id) REFERENCES moz_pages_w_icons ON DELETE CASCADE, FOREIGN KEY (icon_id) REFERENCES moz_icons ON DELETE CASCADE ) WITHOUT ROWID
Table: sqlite_stat1
Create Statement:
CREATE TABLE sqlite_stat1(tbl,idx,stat)

View File

@ -1,4 +1,7 @@
all: run:
GO111MODULE="off" go run mouse.go
install:
go install go install
prep: prep:

View File

@ -1,5 +1,14 @@
all: all:
go install go install
bash:
GO111MODULE="off" go run bash.go
env:
GO111MODULE="off" go run env.go
ls:
GO111MODULE="off" go run -v ls.go
prep: prep:
go get ${witgoget} . go get ${witgoget} .

View File

@ -1,6 +1,6 @@
// +build ignore // +build ignore
package ls package main
import ( import (
"io" "io"