Skip to content

Commit

Permalink
chore: downgrade golang version to 1.20, support Windows 7. (#435)
Browse files Browse the repository at this point in the history
* chore: downgrade golang version to 1.20, support windows 7

* chore: Update dependencies for Go project.

- Update dependencies in go.sum
- Improvements and optimizations in various files
- Bug fixes and error handling enhancements

* chore: Update modernc.org/sqlite library versions in go.mod and go.sum files

- Update version of `modernc.org/sqlite` to `v1.31.1` in `go.mod` and `go.sum` files
- Update module hash in `go.sum` file for `modernc.org/sqlite`
- Ensure consistency between `go.mod` and `go.sum` files in relation to `modernc.org/sqlite` version

* chore: replace log/slog with standard logger (#436)

* chore: replace log/slog with standard logger

* chore: Update Go dependencies and versions

- Update Go version from `1.22.5` to `1.20` and other dependencies
- Update critical dependencies to latest versions
- Ensure compatibility with new versions of dependencies

* chore: Optimize dependency management in workflows

- Update build and lint workflows to use `go mod tidy` for getting dependencies
- Change modules download mode to `'mod'` in linters configuration
- Add step to get dependencies in lint workflow

* refactor: Update dependencies and refactor Chromium key deletion logic

- Update `modernc.org/sqlite` to `v1.31.1` in `go.mod` and `go.sum`
- Increase version number to `0.5.0` in `cmd/hack-browser-data/main.go`
- Refactor and update logic for filtering and copying items in `browser/chromium/chromium.go`

* Improve logging functionality and data type conversion

- Add `String()` method to `DataType` enum in types.go
- Update log level to Debug in logger_test.go
- Set log level to Debug in `TestLoggerDebug` and `TestLoggerDebugf` functions
  • Loading branch information
moonD4rk committed Oct 22, 2024
1 parent 3159141 commit ad020cf
Show file tree
Hide file tree
Showing 33 changed files with 695 additions and 364 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
goVer: ["1.22.x"]
goVer: ["1.20.x"]

steps:
- name: Check out code into the Go module directory
Expand Down Expand Up @@ -43,7 +43,9 @@ jobs:
diff -u <(echo -n) <(gofmt -d .)
- name: Get dependencies
run: go mod download
run: |
go mod tidy
go mod download
- name: Build
run: go build -v ./...
7 changes: 6 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ jobs:
- name: Set Golang
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
go-version: "1.20.x"
cache: false

- name: Check spelling with custom config file
uses: crate-ci/typos@master
with:
config: ./.typos.toml

- name: Get dependencies
run: |
go mod tidy
go mod download
- name: Lint
uses: golangci/golangci-lint-action@v6
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22.x'
go-version: '1.20.x'

- name: Check out code
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ "1.22.x" ]
go-version: [ "1.20.x" ]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -35,7 +35,7 @@ jobs:
if: success()
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
go-version: "1.20.x"
- name: Checkout code
uses: actions/checkout@v4
- name: Calc coverage
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ hack-browser-data

# CICD Config
!.typos.toml
!.github/*.yml
!.github/*.yml
!log/
examples/*.go
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
run:
timeout: '5m'
allow-parallel-runners: true
modules-download-mode: 'readonly'
modules-download-mode: 'mod'

linters:
enable:
Expand Down Expand Up @@ -43,11 +43,8 @@ linters:
- 'noctx'
- 'sqlclosecheck'
- 'staticcheck'
- 'structcheck'
- 'stylecheck'
- 'unused'
- 'deadcode'
- 'varcheck'
- 'paralleltest'

issues:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Installation of `HackBrowserData` is dead-simple, just download [the release for
### Building from source

only support `go 1.21+` with go generics and `log/slog` standard library.
only support `go 1.20+` with go generics.

```bash
$ git clone https://github.com/moonD4rk/HackBrowserData
Expand Down
20 changes: 10 additions & 10 deletions browser/browser.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package browser

import (
"log/slog"
"path/filepath"
"sort"
"strings"

"github.com/moond4rk/hackbrowserdata/browser/chromium"
"github.com/moond4rk/hackbrowserdata/browser/firefox"
"github.com/moond4rk/hackbrowserdata/browserdata"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
)
Expand Down Expand Up @@ -44,16 +44,16 @@ func pickChromium(name, profile string) []Browser {
if name == "all" {
for _, v := range chromiumList {
if !fileutil.IsDirExists(filepath.Clean(v.profilePath)) {
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
log.Warnf("find browser failed, profile folder does not exist, browser %s", v.name)
continue
}
multiChromium, err := chromium.New(v.name, v.storage, v.profilePath, v.dataTypes)
if err != nil {
slog.Error("new chromium error", "err", err)
log.Errorf("new chromium error %v", err)
continue
}
for _, b := range multiChromium {
slog.Warn("find browser success", "browser", b.Name())
log.Warnf("find browser success, browser %s", b.Name())
browsers = append(browsers, b)
}
}
Expand All @@ -63,14 +63,14 @@ func pickChromium(name, profile string) []Browser {
profile = c.profilePath
}
if !fileutil.IsDirExists(filepath.Clean(profile)) {
slog.Error("find browser failed, profile folder does not exist", "browser", c.name)
log.Errorf("find browser failed, profile folder does not exist, browser %s", c.name)
}
chromes, err := chromium.New(c.name, c.storage, profile, c.dataTypes)
if err != nil {
slog.Error("new chromium error", "err", err)
log.Errorf("new chromium error %v", err)
}
for _, chrome := range chromes {
slog.Warn("find browser success", "browser", chrome.Name())
log.Warnf("find browser success, browser %s", chrome.Name())
browsers = append(browsers, chrome)
}
}
Expand All @@ -89,17 +89,17 @@ func pickFirefox(name, profile string) []Browser {
}

if !fileutil.IsDirExists(filepath.Clean(profile)) {
slog.Warn("find browser failed, profile folder does not exist", "browser", v.name)
log.Warnf("find browser failed, profile folder does not exist, browser %s", v.name)
continue
}

if multiFirefox, err := firefox.New(profile, v.dataTypes); err == nil {
for _, b := range multiFirefox {
slog.Warn("find browser success", "browser", b.Name())
log.Warnf("find browser success, browser %s", b.Name())
browsers = append(browsers, b)
}
} else {
slog.Error("new firefox error", "err", err)
log.Errorf("new firefox error %v", err)
}
}

Expand Down
16 changes: 9 additions & 7 deletions browser/chromium/chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package chromium

import (
"io/fs"
"log/slog"
"os"
"path/filepath"
"slices"
"strings"

"github.com/moond4rk/hackbrowserdata/browserdata"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
Expand Down Expand Up @@ -53,9 +52,12 @@ func (c *Chromium) Name() string {

func (c *Chromium) BrowsingData(isFullExport bool) (*browserdata.BrowserData, error) {
// delete chromiumKey from dataTypes, doesn't need to export key
dataTypes := slices.DeleteFunc(c.dataTypes, func(i types.DataType) bool {
return i == types.ChromiumKey
})
var dataTypes []types.DataType
for _, dt := range c.dataTypes {
if dt != types.ChromiumKey {
dataTypes = append(dataTypes, dt)
}
}

if !isFullExport {
dataTypes = types.FilterSensitiveItems(c.dataTypes)
Expand Down Expand Up @@ -96,7 +98,7 @@ func (c *Chromium) copyItemToLocal() error {
err = fileutil.CopyFile(path, filename)
}
if err != nil {
slog.Error("copy item to local error", "path", path, "filename", filename, "err", err)
log.Errorf("copy item to local, path %s, filename %s err %v", path, filename, err)
continue
}
}
Expand Down Expand Up @@ -139,7 +141,7 @@ func chromiumWalkFunc(items []types.DataType, multiItemPaths map[string]map[type
return func(path string, info fs.FileInfo, err error) error {
if err != nil {
if os.IsPermission(err) {
slog.Warn("skipping walk chromium path permission error", "path", path, "err", err)
log.Warnf("skipping walk chromium path permission error, path %s, err %v", path, err)
return nil
}
return err
Expand Down
4 changes: 2 additions & 2 deletions browser/chromium/chromium_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"crypto/sha1"
"errors"
"fmt"
"log/slog"
"os"
"os/exec"
"strings"

"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
)

Expand Down Expand Up @@ -54,6 +54,6 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
return nil, errWrongSecurityCommand
}
c.masterKey = key
slog.Info("get master key success", "browser", c.name)
log.Debugf("get master key success, browser %s", c.name)
return key, nil
}
8 changes: 4 additions & 4 deletions browser/chromium/chromium_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ package chromium
import (
"crypto/sha1"
"fmt"
"log/slog"
"os"

"github.com/godbus/dbus/v5"
keyring "github.com/ppacher/go-dbus-keyring"

"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
)

Expand All @@ -34,7 +34,7 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
}
defer func() {
if err := session.Close(); err != nil {
slog.Error("close dbus session error", "err", err.Error())
log.Errorf("close dbus session error: %v", err)
}
}()
collections, err := svc.GetAllCollections()
Expand All @@ -50,7 +50,7 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
for _, i := range items {
label, err := i.GetLabel()
if err != nil {
slog.Warn("get label from dbus", "err", err.Error())
log.Warnf("get label from dbus: %v", err)
continue
}
if label == c.storage {
Expand All @@ -71,6 +71,6 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
// @https://source.chromium.org/chromium/chromium/src/+/master:components/os_crypt/os_crypt_linux.cc
key := crypto.PBKDF2Key(secret, salt, 1, 16, sha1.New)
c.masterKey = key
slog.Info("get master key success", "browser", c.name)
log.Debugf("get master key success, browser %s", c.name)
return key, nil
}
6 changes: 3 additions & 3 deletions browser/chromium/chromium_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ package chromium
import (
"encoding/base64"
"errors"
"log/slog"
"os"

"github.com/tidwall/gjson"

"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
)
Expand All @@ -35,9 +35,9 @@ func (c *Chromium) GetMasterKey() ([]byte, error) {
}
c.masterKey, err = crypto.DecryptWithDPAPI(key[5:])
if err != nil {
slog.Error("decrypt master key failed", "err", err)
log.Errorf("decrypt master key failed, err %v", err)
return nil, err
}
slog.Info("get master key success", "browser", c.name)
log.Debugf("get master key success, browser %s", c.name)
return c.masterKey, nil
}
4 changes: 2 additions & 2 deletions browser/firefox/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"errors"
"fmt"
"io/fs"
"log/slog"
"os"
"path/filepath"

_ "modernc.org/sqlite" // sqlite3 driver TODO: replace with chooseable driver

"github.com/moond4rk/hackbrowserdata/browserdata"
"github.com/moond4rk/hackbrowserdata/crypto"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
Expand Down Expand Up @@ -62,7 +62,7 @@ func firefoxWalkFunc(items []types.DataType, multiItemPaths map[string]map[types
return func(path string, info fs.DirEntry, err error) error {
if err != nil {
if os.IsPermission(err) {
slog.Warn("skipping walk firefox path permission error", "path", path, "err", err)
log.Warnf("skipping walk firefox path %s permission error: %v", path, err)
return nil
}
return err
Expand Down
6 changes: 3 additions & 3 deletions browserdata/bookmark/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bookmark

import (
"database/sql"
"log/slog"
"os"
"sort"
"time"
Expand All @@ -11,6 +10,7 @@ import (
_ "modernc.org/sqlite" // import sqlite3 driver

"github.com/moond4rk/hackbrowserdata/extractor"
"github.com/moond4rk/hackbrowserdata/log"
"github.com/moond4rk/hackbrowserdata/types"
"github.com/moond4rk/hackbrowserdata/utils/fileutil"
"github.com/moond4rk/hackbrowserdata/utils/typeutil"
Expand Down Expand Up @@ -111,7 +111,7 @@ func (f *FirefoxBookmark) Extract(_ []byte) error {
defer db.Close()
_, err = db.Exec(closeJournalMode)
if err != nil {
slog.Error("close journal mode error", "err", err)
log.Errorf("close journal mode error: %v", err)
}
rows, err := db.Query(queryFirefoxBookMark)
if err != nil {
Expand All @@ -124,7 +124,7 @@ func (f *FirefoxBookmark) Extract(_ []byte) error {
title, url string
)
if err = rows.Scan(&id, &url, &bt, &dateAdded, &title); err != nil {
slog.Error("scan bookmark error", "err", err)
log.Errorf("scan bookmark error: %v", err)
}
*f = append(*f, bookmark{
ID: id,
Expand Down
Loading

0 comments on commit ad020cf

Please sign in to comment.