Phase 0 of the refactor: settle the design record and pin the CLI flag surface and wire names before any code moves.
9.3 KiB
RFC-002: Package Layout
The tree
Everything except the command entrypoint lives under internal/. The entrypoint stays thin — the frozen cobra command tree and a call into app.
cmd/hack-browser-data/ main; cobra commands and flags (the frozen CLI surface); flags → app.Request
internal/
app/ Validate, Discover, NewPlan, Execute, Report; dispatches on browser.Base to the base packages
browser/ Def, Base, Platform (Supported, Lookup); UserDataDir, DirID, Profile, DiscoverOptions;
Source, Extractor, ProfileSnapshot, Collector
chromium/ Chromium discovery, extractors, key input, archive sources, per-fork overrides (Yandex, Opera family)
firefox/ Firefox discovery, extractors, per-profile key derivation
safari/ Safari discovery and extractors
category/ Category: the data categories (the -c values and the output file names)
record/ record types (Login, Cookie, …), the sealed Record, Stamp; field names frozen by the output contract
masterkey/ Chromium key Set, Retriever, RetrieveAll, keys.json Dump; OS secret stores by build tag
crypto/ pure decrypt primitives over bytes (AES-CBC/GCM, 3DES, PBKDF2, ASN.1 PBE)
snapshot/ snapshot Dir and Snapshot, Capture, manifest, zip transport, the copier
export/ Writer; csv / json / cookie-editor encoders; --zip packaging
sqlitex/ thin modernc.org/sqlite helpers (open read-only by path, query)
timeconv/ browser epoch conversions (Chromium/WebKit, Unix, Firefox, Core Data)
winapi/ Windows only: syscall wrappers, DPAPI, locked-file copy, executable lookup
abe/ Windows only: App-Bound Encryption bridge — move DEFERRED, see below
keychain/ macOS only: the user's login keychain — one handle per run, opened on first use
log/ leveled logging (Debugf/Infof/Warnf)
The technique internals (the ABE payload, reflective injection, DPAPI and keychain specifics) sit behind masterkey, keychain, winapi, and the ABE unit by build tag. Their mechanics are documented in the format and technique RFCs (013–021) and are out of scope for the design RFCs — here they are just packages with a contract (RFC-006).
The ABE unit stays where it is (DEFERRED). Today's crypto/windows/ — the first-party C sources, the generated bootstrap layout package, and the payload package that embeds the built .bin — and utils/injector keep their paths in this rewrite, and so do Makefile.frag, make payload, and make gen-layout. Moving them changes the payload build, which needs its own validation on Windows, so only their importers change here. When the unit moves to internal/abe/, it moves as one: //go:embed only reaches files in the embedding package's directory or below, so the Makefile writes the payload there (RFC-012).
Dependency direction
Dependencies point downward and are listed exhaustively; anything not listed is forbidden.
| Package | May import (project-internal) |
|---|---|
cmd/hack-browser-data |
app, plus browser and category for help-text vocabulary (-b IDs, -c categories), log |
app |
every package below |
browser/chromium, browser/firefox, browser/safari |
browser, category, record, masterkey, crypto, snapshot, sqlitex, timeconv, log |
export |
category, record, log |
browser |
category, record, masterkey, snapshot |
masterkey |
crypto, winapi, abe, keychain, log |
snapshot |
winapi, log |
abe |
winapi, log |
record |
category |
sqlitex, winapi |
log |
category, crypto, timeconv, keychain, log |
nothing |
abe stands for the ABE unit — utils/injector and crypto/windows/payload — until it moves.
Four rules keep the graph acyclic and its seams honest:
- The base dispatch lives in
app. The base packages importbrowserforDef,UserDataDir, andExtractor, sobrowsercannot call them back;appswitches onDef.Base. Init-time self-registration is ruled out by thegochecknoinitslinter, and an explicit switch reads better on stage anyway. snapshotspeaks strings. Asnapshot.Filenames its user data dir by ID (DirID, a plain string) and its path relative to that directory; it never holds abrowser.UserDataDir, becausebrowser.ProfileSnapshotholds asnapshot.Snapshot.cryptotakes bytes. Primitives receive raw keys and blobs; they never see amasterkey.Set, becausemasterkeyis the package that calls them.- Interfaces live with their consumer.
browserdeclares theCollectorits extractors use, andappimplements it;masterkeyandbrowser/safarieach declare the one-methodLoginKeychainthey read. Constructors elsewhere return concrete types (*snapshot.Dir,*export.Writer).
Review keeps the table, not a tool: a change that needs an edge the table does not list — say, crypto importing browser — updates the table first, in the same pull request.
Why internal/ and nothing else (DECIDED)
The current tree keeps packages at the module root (browser/, crypto/, filemanager/, log/, masterkey/, output/, types/, utils/...) and the project CLAUDE.md says "no pkg/ + internal/." This RFC reverses that single decision, for the rewrite only, and keeps the "keep it simple" spirit by using internal/ instead of a split, not in addition to one.
Reasons:
- No Go-API burden. Anything importable by path becomes a de-facto public API that external users pin to. HBD has no intended library consumers — it is a CLI.
internal/makes that explicit and compiler-enforced, so we can rename and reshape freely across the whole rewrite. The CLI contract (RFC-000) is the only compatibility obligation, and it is unaffected. - A clear seam.
cmd/is the only thing outsideinternal/. The boundary between "the program's entrypoint" and "the program" is visible in the tree. - It is still flat. We are not introducing
pkg/as well. There is exactly one home for library code, and it isinternal/.
Trade-off accepted: the module stops being importable as a library. The module path stays github.com/moond4rk/hackbrowserdata and releases continue as v1.x; there is no v2 (DECIDED).
Package sizing and naming rules
- A package exists because it owns a concept, not because a file got long.
timeconvandcategoryare tiny on purpose. A package with nothing to own is not created — there is nocli(flags belong tocmd, rules toapp) and notextenc(the CSV BOM is three bytes inexport). - A concept with per-OS implementations lives in one package with
_windows.go/_darwin.go/_linux.gofiles; callers import one package and get the right implementation at build time. A concept that exists on only one OS — the locked-file copy, the ABE bridge, the macOS login keychain — lives in its own package whose files are all built for that OS:winapi,abe, andkeychain. winapi, notplatform/windows: a package namedwindowswould collide withgolang.org/x/sys/windows, which it imports, so every file would need an alias.logandcryptokeep today's names although the standard library has packages of the same names: both are internal, and no file needs both.- No
utilsgrab-bag. The old tree is redistributed to named homes:utils/sqliteutil→sqlitex;utils/fileutilandfilemanager→snapshot(copy, zip transport) andexport(--zip);utils/{winapi,winutil}→winapi;utils/injectorandcrypto/windows/stay in place (theabemove is DEFERRED);types→category,record, andbrowser;output→export;log→internal/log.