diff --git a/example-favicon/Makefile b/example-favicon/Makefile new file mode 100644 index 0000000..0061e45 --- /dev/null +++ b/example-favicon/Makefile @@ -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 diff --git a/example-favicon/favicons.sqlite b/example-favicon/favicons.sqlite new file mode 100644 index 0000000..ce7d18f Binary files /dev/null and b/example-favicon/favicons.sqlite differ diff --git a/example-favicon/main.go b/example-favicon/main.go new file mode 100644 index 0000000..a1dd210 --- /dev/null +++ b/example-favicon/main.go @@ -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) + } +} diff --git a/example-favicon/schema.txt b/example-favicon/schema.txt new file mode 100644 index 0000000..5386f03 --- /dev/null +++ b/example-favicon/schema.txt @@ -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) + diff --git a/example-gocui-mouse/Makefile b/example-gocui-mouse/Makefile index d8e10bd..e241440 100644 --- a/example-gocui-mouse/Makefile +++ b/example-gocui-mouse/Makefile @@ -1,4 +1,7 @@ -all: +run: + GO111MODULE="off" go run mouse.go + +install: go install prep: diff --git a/example-shell/Makefile b/example-shell/Makefile index d8e10bd..46ad815 100644 --- a/example-shell/Makefile +++ b/example-shell/Makefile @@ -1,5 +1,14 @@ all: 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: go get ${witgoget} . diff --git a/example-shell/ls.go b/example-shell/ls.go index 4d7546a..b6a0aa8 100644 --- a/example-shell/ls.go +++ b/example-shell/ls.go @@ -1,6 +1,6 @@ // +build ignore -package ls +package main import ( "io"