chrome-tools 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,41 +1,42 @@
1
- import{existsSync as k,readdirSync as tt,readFileSync as ot,statSync as an}from"node:fs";import{basename as nt,join as A}from"node:path";import{createDecipheriv as ue}from"node:crypto";var Br=Buffer.alloc(16," "),U=12,K=16;function ee(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e),o=r.subarray(0,3).toString("utf-8");if(o!=="v10"&&o!=="v11")return"<unsupported encryption format>";let n=r.subarray(3);try{let s=ue("aes-128-cbc",t,Br),i=s.update(n);return i=Buffer.concat([i,s.final()]),i}catch{return"<decryption failed>"}}function Ae(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e),o=r.subarray(0,3).toString("utf-8");if(o!=="v10"&&o!=="v11")return"<unsupported encryption format>";if(r.length<3+U+K)return"<decryption failed>";let n=r.subarray(3,3+U),s=r.subarray(r.length-K),i=r.subarray(3+U,r.length-K);try{let c=ue("aes-256-gcm",t,n);return c.setAuthTag(s),Buffer.concat([c.update(i),c.final()])}catch{return"<decryption failed>"}}function re(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e);if(r.subarray(0,3).toString("utf-8")!=="v20")return"<unsupported encryption format>";if(r.length<3+U+K)return"<decryption failed>";let n=r.subarray(3,3+U),s=r.subarray(r.length-K),i=r.subarray(3+U,r.length-K);try{let c=ue("aes-256-gcm",t,n);return c.setAuthTag(s),Buffer.concat([c.update(i),c.final()])}catch{return"<decryption failed>"}}function E(e){if(e==null)return"N/A";try{let t=BigInt(e);if(t===0n)return"N/A";let r=t-11644473600000000n,o=Number(r/1000n),n=new Date(o);return isNaN(n.getTime())?"N/A":n.toLocaleString()}catch{return"N/A"}}var h=class extends Error{constructor(r,o,n){super(o,n);this.code=r}code};function w(e,t,r,o){if(!e)return;let n=o instanceof h?o.code:o?.code==="ENOENT"?"missing_store":"unreadable";e({profile:t,store:r,code:n,message:o instanceof Error?o.message:String(o)})}import{homedir as Ar}from"node:os";import{join as Tr}from"node:path";import{execFileSync as vr}from"node:child_process";import{pbkdf2Sync as xr}from"node:crypto";var br=1003,Dr=16,Pr=Buffer.from("saltysalt"),ge="Chrome Safe Storage",pe={ITEM_NOT_FOUND:44,INTERACTION_NOT_ALLOWED:36,AUTH_FAILED:45,USER_CANCELED:128},X=class extends Error{service;kind;constructor(t,r,o){super(t),this.name="KeychainAccessError",this.service=r,this.kind=o}get isAccessDenied(){return this.kind==="access-denied"}};var de=new Map,me=new Map;function Cr(){return!!(process.env.SSH_CONNECTION||process.env.SSH_TTY)||!process.env.TERM_PROGRAM}function Rr(e){let t=e;return{status:typeof t?.status=="number"?t.status:null,stderr:(t?.stderr??"").toString().trim()}}function kr(e,t,r){let o="See docs/remote-keychain-access.md for non-interactive / SSH setup.",n,s;t===pe.ITEM_NOT_FOUND||/could not be found/i.test(r)?(n="not-found",s=`No '${e}' item found in the Keychain.
2
- Run this browser at least once on this machine so it creates the key.`):t===pe.INTERACTION_NOT_ALLOWED||/interaction.*not allowed/i.test(r)?(n="access-denied",s="The Keychain needs a GUI authorization prompt that can't be shown here "+(Cr()?`(you appear to be on a remote/SSH session).
1
+ import{existsSync as k,readdirSync as at,readFileSync as ct,statSync as pn}from"node:fs";import{basename as ft,join as L}from"node:path";import{createDecipheriv as pe}from"node:crypto";var vr=Buffer.alloc(16," "),M=12,K=16;function re(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e),o=r.subarray(0,3).toString("utf-8");if(o!=="v10"&&o!=="v11")return"<unsupported encryption format>";let n=r.subarray(3);try{let i=pe("aes-128-cbc",t,vr),s=i.update(n);return s=Buffer.concat([s,i.final()]),s}catch{return"<decryption failed>"}}function $e(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e),o=r.subarray(0,3).toString("utf-8");if(o!=="v10"&&o!=="v11")return"<unsupported encryption format>";if(r.length<3+M+K)return"<decryption failed>";let n=r.subarray(3,3+M),i=r.subarray(r.length-K),s=r.subarray(3+M,r.length-K);try{let c=pe("aes-256-gcm",t,n);return c.setAuthTag(i),Buffer.concat([c.update(s),c.final()])}catch{return"<decryption failed>"}}function te(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e);if(r.subarray(0,3).toString("utf-8")!=="v20")return"<unsupported encryption format>";if(r.length<3+M+K)return"<decryption failed>";let n=r.subarray(3,3+M),i=r.subarray(r.length-K),s=r.subarray(3+M,r.length-K);try{let c=pe("aes-256-gcm",t,n);return c.setAuthTag(i),Buffer.concat([c.update(s),c.final()])}catch{return"<decryption failed>"}}function B(e){if(e==null)return"N/A";try{let t=BigInt(e);if(t===0n)return"N/A";let r=t-11644473600000000n,o=Number(r/1000n),n=new Date(o);return isNaN(n.getTime())?"N/A":n.toLocaleString()}catch{return"N/A"}}var h=class extends Error{constructor(r,o,n){super(o,n);this.code=r}code};function S(e,t,r,o){if(!e)return;let n=o instanceof h?o.code:o?.code==="ENOENT"?"missing_store":"unreadable";e({profile:t,store:r,code:n,message:o instanceof Error?o.message:String(o)})}import{homedir as Tr}from"node:os";import{join as Ir}from"node:path";import{execFileSync as xr}from"node:child_process";import{pbkdf2Sync as br}from"node:crypto";var Pr=1003,Dr=16,Cr=Buffer.from("saltysalt"),ye="Chrome Safe Storage",de={ITEM_NOT_FOUND:44,INTERACTION_NOT_ALLOWED:36,AUTH_FAILED:45,USER_CANCELED:128},X=class extends Error{service;kind;constructor(t,r,o){super(t),this.name="KeychainAccessError",this.service=r,this.kind=o}get isAccessDenied(){return this.kind==="access-denied"}};var me=new Map,ge=new Map;function Rr(){return!!(process.env.SSH_CONNECTION||process.env.SSH_TTY)||!process.env.TERM_PROGRAM}function kr(e){let t=e;return{status:typeof t?.status=="number"?t.status:null,stderr:(t?.stderr??"").toString().trim()}}function Or(e,t,r){let o="See docs/remote-keychain-access.md for non-interactive / SSH setup.",n,i;t===de.ITEM_NOT_FOUND||/could not be found/i.test(r)?(n="not-found",i=`No '${e}' item found in the Keychain.
2
+ Run this browser at least once on this machine so it creates the key.`):t===de.INTERACTION_NOT_ALLOWED||/interaction.*not allowed/i.test(r)?(n="access-denied",i="The Keychain needs a GUI authorization prompt that can't be shown here "+(Rr()?`(you appear to be on a remote/SSH session).
3
3
  `:`.
4
4
  `)+`Authorize once from a GUI Terminal (click "Always Allow"), then unlock the
5
5
  keychain in this session:
6
6
  security unlock-keychain ~/Library/Keychains/login.keychain-db
7
- `+o):t===pe.AUTH_FAILED?(n="access-denied",s=`Keychain authorization failed (wrong password or denied).
7
+ `+o):t===de.AUTH_FAILED?(n="access-denied",i=`Keychain authorization failed (wrong password or denied).
8
8
  Try: security unlock-keychain ~/Library/Keychains/login.keychain-db
9
- ${o}`):(n="access-denied",s=`macOS showed a Keychain access prompt that was denied or dismissed.
9
+ ${o}`):(n="access-denied",i=`macOS showed a Keychain access prompt that was denied or dismissed.
10
10
  Re-run the command and click "Allow" (or "Always Allow"), or authorize once with:
11
11
  security find-generic-password -w -s "${e}"
12
- ${o}`);let i=[t!==null?`exit ${t}`:null,r||null].filter(Boolean).join(": ");return new X(`Could not retrieve ${e} key from macOS Keychain.
13
- ${s}`+(i?`
14
- (security: ${i})`:""),e,n)}var te=null;function ye(){return te}function Lr(e){te=e}function he(e=ge){let t=de.get(e);if(t!==void 0)return t;let r;if(te)r=te(e);else try{r=vr("security",["find-generic-password","-w","-s",e],{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()}catch(o){let{status:n,stderr:s}=Rr(o);throw kr(e,n,s)}if(!r)throw new X(`Keychain returned an empty ${e} key.
15
- The item may exist with no password. Re-run the browser to recreate it.`,e,"empty");return de.set(e,r),r}function Or(){return he(ge)}function Te(e=ge,t){let r=me.get(e);if(r!==void 0)return r;let o=t||he(e);if(!o)throw new Error("Keychain password cannot be empty for key derivation.");let n=xr(o,Pr,br,Dr,"sha1");return me.set(e,n),n}function we(){de.clear(),me.clear()}var Z={chrome:{id:"chrome",name:"Google Chrome",aliases:["google-chrome","google chrome"],safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome",win32:"Google/Chrome/User Data",linux:"google-chrome"}},"chrome-beta":{id:"chrome-beta",name:"Google Chrome Beta",safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome Beta",win32:"Google/Chrome Beta/User Data",linux:"google-chrome-beta"}},"chrome-canary":{id:"chrome-canary",name:"Google Chrome Canary",aliases:["canary"],safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome Canary",win32:"Google/Chrome SxS/User Data",linux:"google-chrome-unstable"}},chromium:{id:"chromium",name:"Chromium",safeStorageLabel:"Chromium Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Chromium",win32:"Chromium/User Data",linux:"chromium"}},edge:{id:"edge",name:"Microsoft Edge",aliases:["msedge","microsoft-edge","microsoft edge"],safeStorageLabel:"Microsoft Edge Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Microsoft Edge",win32:"Microsoft/Edge/User Data",linux:"microsoft-edge"}},brave:{id:"brave",name:"Brave",aliases:["brave-browser"],safeStorageLabel:"Brave Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"BraveSoftware/Brave-Browser",win32:"BraveSoftware/Brave-Browser/User Data",linux:"BraveSoftware/Brave-Browser"}},comet:{id:"comet",name:"Comet",aliases:["perplexity","perplexity-comet"],safeStorageLabel:"Comet Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Comet",win32:"Perplexity/Comet/User Data",linux:"comet"}},vivaldi:{id:"vivaldi",name:"Vivaldi",safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Vivaldi",win32:"Vivaldi/User Data",linux:"vivaldi"}},opera:{id:"opera",name:"Opera",safeStorageLabel:"Opera Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"com.operasoftware.Opera",win32:"Opera Software/Opera Stable",win32Base:"roaming",linux:"opera"}}},Ie="chrome";function $(){return Object.values(Z)}function Se(e){if(!e)return null;let t=e.trim().toLowerCase();for(let r of $())if(r.id.toLowerCase()===t||r.name.toLowerCase()===t||r.aliases?.some(o=>o.toLowerCase()===t))return r;return null}function M(e){let t=Se(e);if(t)return t;throw new Error(`Unknown browser "${e}". Supported: ${$().map(r=>r.id).join(", ")}.`)}var Q=Z[Ie];function v(){return Q}function Ne(e){return!e||!e.trim()?(Q=Z[Ie],Q):(Q=M(e),Q)}var Me={name:"darwin",getDefaultChromeDir(e=v()){return Tr(Ar(),"Library","Application Support",...e.dirs.darwin.split("/"))},getDecryptionKey(e,t=v()){return Te(t.safeStorageLabel)},decrypt(e,t){return ee(e,t)},clearCache(){we()}};import{execFileSync as $e}from"node:child_process";import{randomUUID as Ir}from"node:crypto";import{constants as Nr,copyFileSync as Mr,existsSync as H,mkdirSync as Fr,readFileSync as Fe,rmSync as Ur,rmdirSync as Kr}from"node:fs";import{dirname as He,join as C,resolve as $r}from"node:path";var _e=Buffer.from("DPAPI","ascii"),Ee=Buffer.from("APPB","ascii"),Be=new Map,ve=new Map,xe=new WeakMap,Hr=new Set(["chrome","chrome-beta","brave","edge"]);function Gr(e){let t=["$ErrorActionPreference='Stop';","Add-Type -AssemblyName System.Security;","$b=[Console]::In.ReadToEnd().Trim();","$enc=[Convert]::FromBase64String($b);","$dec=[System.Security.Cryptography.ProtectedData]::Unprotect($enc,$null,[System.Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($dec));"].join(" "),r;try{r=$e("powershell.exe",["-NoProfile","-NonInteractive","-Command",t],{input:e.toString("base64"),encoding:"utf-8"})}catch(o){throw new Error(`DPAPI decryption via PowerShell failed.
12
+ ${o}`);let s=[t!==null?`exit ${t}`:null,r||null].filter(Boolean).join(": ");return new X(`Could not retrieve ${e} key from macOS Keychain.
13
+ ${i}`+(s?`
14
+ (security: ${s})`:""),e,n)}var oe=null;function he(){return oe}function Ar(e){oe=e}function Se(e=ye){let t=me.get(e);if(t!==void 0)return t;let r;if(oe)r=oe(e);else try{r=xr("security",["find-generic-password","-w","-s",e],{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()}catch(o){let{status:n,stderr:i}=kr(o);throw Or(e,n,i)}if(!r)throw new X(`Keychain returned an empty ${e} key.
15
+ The item may exist with no password. Re-run the browser to recreate it.`,e,"empty");return me.set(e,r),r}function Lr(){return Se(ye)}function Ne(e=ye,t){let r=ge.get(e);if(r!==void 0)return r;let o=t||Se(e);if(!o)throw new Error("Keychain password cannot be empty for key derivation.");let n=br(o,Cr,Pr,Dr,"sha1");return ge.set(e,n),n}function we(){me.clear(),ge.clear()}var Z={chrome:{id:"chrome",name:"Google Chrome",aliases:["google-chrome","google chrome"],safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome",win32:"Google/Chrome/User Data",linux:"google-chrome"}},"chrome-beta":{id:"chrome-beta",name:"Google Chrome Beta",safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome Beta",win32:"Google/Chrome Beta/User Data",linux:"google-chrome-beta"}},"chrome-canary":{id:"chrome-canary",name:"Google Chrome Canary",aliases:["canary"],safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Google/Chrome Canary",win32:"Google/Chrome SxS/User Data",linux:"google-chrome-unstable"}},chromium:{id:"chromium",name:"Chromium",safeStorageLabel:"Chromium Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Chromium",win32:"Chromium/User Data",linux:"chromium"}},edge:{id:"edge",name:"Microsoft Edge",aliases:["msedge","microsoft-edge","microsoft edge"],safeStorageLabel:"Microsoft Edge Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Microsoft Edge",win32:"Microsoft/Edge/User Data",linux:"microsoft-edge"}},brave:{id:"brave",name:"Brave",aliases:["brave-browser"],safeStorageLabel:"Brave Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"BraveSoftware/Brave-Browser",win32:"BraveSoftware/Brave-Browser/User Data",linux:"BraveSoftware/Brave-Browser"}},comet:{id:"comet",name:"Comet",aliases:["perplexity","perplexity-comet"],safeStorageLabel:"Comet Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"Comet",win32:"Perplexity/Comet/User Data",linux:"comet"}},vivaldi:{id:"vivaldi",name:"Vivaldi",safeStorageLabel:"Chrome Safe Storage",linuxSecretApp:"chrome",dirs:{darwin:"Vivaldi",win32:"Vivaldi/User Data",linux:"vivaldi"}},opera:{id:"opera",name:"Opera",safeStorageLabel:"Opera Safe Storage",linuxSecretApp:"chromium",dirs:{darwin:"com.operasoftware.Opera",win32:"Opera Software/Opera Stable",win32Base:"roaming",linux:"opera"}}},Fe="chrome";function W(){return Object.values(Z)}function Ee(e){if(!e)return null;let t=e.trim().toLowerCase();for(let r of W())if(r.id.toLowerCase()===t||r.name.toLowerCase()===t||r.aliases?.some(o=>o.toLowerCase()===t))return r;return null}function N(e){let t=Ee(e);if(t)return t;throw new Error(`Unknown browser "${e}". Supported: ${W().map(r=>r.id).join(", ")}.`)}var Q=Z[Fe];function _(){return Q}function Ue(e){return!e||!e.trim()?(Q=Z[Fe],Q):(Q=N(e),Q)}var Me={name:"darwin",getDefaultChromeDir(e=_()){return Ir(Tr(),"Library","Application Support",...e.dirs.darwin.split("/"))},getDecryptionKey(e,t=_()){return Ne(t.safeStorageLabel)},decrypt(e,t){return re(e,t)},clearCache(){we()}};import{execFileSync as De}from"node:child_process";import{randomUUID as $r}from"node:crypto";import{constants as Nr,copyFileSync as Fr,existsSync as H,mkdirSync as Ur,readFileSync as Ke,rmSync as Mr,rmdirSync as Kr}from"node:fs";import{dirname as He,join as b,resolve as Wr}from"node:path";var Be=Buffer.from("DPAPI","ascii"),_e=Buffer.from("APPB","ascii"),ve=new Map,xe=new Map,ee=new Map,be=new WeakMap,Hr=new Set(["chrome","chrome-beta","brave","edge"]),jr=new Set(["EPERM","EACCES"]),Gr=['const fs = require("node:fs");','const net = require("node:net");','const crypto = require("node:crypto");','const { spawn } = require("node:child_process");',"const [helper, dir, browserId] = process.argv.slice(1);",'const encB64 = fs.readFileSync(0, "utf8").trim();','const pipeName = "chrome-tools-abe-" + crypto.randomUUID();','const pipePath = "\\\\\\\\.\\\\pipe\\\\" + pipeName;',"const token = crypto.randomUUID();",'const cfgB64 = Buffer.from(JSON.stringify({ helper, dir, browserId, pipeName, token }), "utf8").toString("base64");',"const ps = [",` "$ErrorActionPreference = 'Stop'",`,` "$ProgressPreference = 'SilentlyContinue'",`,` "$cfg = [System.Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('" + cfgB64 + "')) | ConvertFrom-Json",`,` "$staged = Join-Path $cfg.dir ('chrome-tools-' + [guid]::NewGuid().ToString() + '.exe')",`,' "$created = $false",',' "$copied = $false",',' "$pipe = $null",',' "try {",',` " $pipe = [System.IO.Pipes.NamedPipeClientStream]::new('.', $cfg.pipeName, [System.IO.Pipes.PipeDirection]::InOut)",`,' " $pipe.Connect(15000)",',' " $reader = [System.IO.StreamReader]::new($pipe, [System.Text.Encoding]::ASCII, $false, 1024, $true)",',' " $writer = [System.IO.StreamWriter]::new($pipe, [System.Text.Encoding]::ASCII, 1024, $true)",',' " $writer.AutoFlush = $true",',' " $writer.WriteLine($cfg.token)",',' " $encB64 = $reader.ReadLine()",',' " if (-not (Test-Path -LiteralPath $cfg.dir)) {",',' " [void](New-Item -ItemType Directory -Path $cfg.dir -Force)",',' " $created = $true",',' " }",',' " [System.IO.File]::Copy($cfg.helper, $staged, $false)",',' " $copied = $true",',' " $psi = [System.Diagnostics.ProcessStartInfo]::new($staged, $cfg.browserId)",',' " $psi.WorkingDirectory = $cfg.dir",',' " $psi.UseShellExecute = $false",',' " $psi.CreateNoWindow = $true",',' " $psi.RedirectStandardInput = $true",',' " $psi.RedirectStandardOutput = $true",',' " $psi.RedirectStandardError = $true",',' " $proc = [System.Diagnostics.Process]::Start($psi)",',' " $proc.StandardInput.Write($encB64)",',' " $proc.StandardInput.Close()",',' " $out = $proc.StandardOutput.ReadToEnd()",',' " $err = $proc.StandardError.ReadToEnd()",',' " $proc.WaitForExit(10000) | Out-Null",',' " if ($proc.ExitCode -eq 0 -and $out) {",',` " $writer.WriteLine('OK:' + $out.Trim())",`,' " } else {",',` " $msg = if ($err) { $err.Trim() -replace '[\\\\r\\\\n]+', ' ' } else { 'exit ' + $proc.ExitCode }",`,` " $writer.WriteLine('ERR:' + $msg)",`,' " }",',' "} finally {",',' " if ($pipe) { try { $pipe.Dispose() } catch {} }",',' " if ($copied) { try { Remove-Item -LiteralPath $staged -Force -ErrorAction SilentlyContinue } catch {} }",',' " if ($created) {",',' " try {",',' " if ((Get-ChildItem -LiteralPath $cfg.dir -Force | Measure-Object).Count -eq 0) {",',' " Remove-Item -LiteralPath $cfg.dir -Force -ErrorAction SilentlyContinue",',' " }",',' " } catch {}",',' " }",',' "}",','].join("\\n");','const psEncoded = Buffer.from(ps, "utf16le").toString("base64");','let keyOut = "";','let errOut = "";','let psStderr = "";',"let done = false;","const finish = (code, msg) => {"," if (done) return;"," done = true;"," try { server.close(); } catch {}"," if (code === 0) process.stdout.write(msg);"," else process.stderr.write(msg);"," process.exit(code);","};","const server = net.createServer((socket) => {",' let buf = "";'," let authed = false;",' socket.on("data", (chunk) => {',' buf += chunk.toString("utf8");'," let nl;",' while ((nl = buf.indexOf("\\n")) !== -1) {'," const line = buf.slice(0, nl).trim();"," buf = buf.slice(nl + 1);"," if (!authed) {"," if (line !== token) { socket.destroy(); return; }"," authed = true;",' socket.write(encB64 + "\\n");'," } else {",' if (line.startsWith("OK:")) keyOut = line.slice(3);',' else if (line.startsWith("ERR:")) errOut = line.slice(4);'," socket.end();"," }"," }"," });",' socket.on("error", () => {});',"});","server.listen(pipePath, () => {",` const cmd = "$ProgressPreference='SilentlyContinue'; Start-Process -FilePath 'powershell.exe' -ArgumentList @('-NoProfile','-NonInteractive','-WindowStyle','Hidden','-EncodedCommand','" + psEncoded + "') -Verb RunAs -Wait";`,' const child = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", cmd], { windowsHide: true, stdio: ["ignore", "ignore", "pipe"] });',' child.stderr.on("data", (d) => { psStderr += d.toString("utf8"); });',' child.on("error", (err) => finish(1, err.message));',' child.on("close", () => {'," if (keyOut) finish(0, keyOut);",' else finish(1, errOut || psStderr.trim() || "Elevation cancelled or failed.");'," });","});"].join(`
16
+ `);function Vr(e){let t=["$ErrorActionPreference='Stop';","Add-Type -AssemblyName System.Security;","$b=[Console]::In.ReadToEnd().Trim();","$enc=[Convert]::FromBase64String($b);","$dec=[System.Security.Cryptography.ProtectedData]::Unprotect($enc,$null,[System.Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($dec));"].join(" "),r;try{r=De("powershell.exe",["-NoProfile","-NonInteractive","-Command",t],{input:e.toString("base64"),encoding:"utf-8"})}catch(o){throw new Error(`DPAPI decryption via PowerShell failed.
16
17
  The encrypted_key can only be unprotected by the same Windows user that created it. Run as that user on the same machine.
17
- (powershell: ${o?.message??o})`)}return Buffer.from(r.trim(),"base64")}function Ue(e){let t=$r(e),r=He(t);return H(C(t,"Local State"))?t:r!==t&&H(C(r,"Local State"))?r:t}function Ke(e,t,r){try{let o=$e(e,[r],{input:t.toString("base64"),encoding:"utf8",timeout:1e4,windowsHide:!0,stdio:["pipe","pipe","pipe"],cwd:He(e)}),n=Buffer.from(o.trim(),"base64");return n.length===32?n:void 0}catch{return}}function Wr(e,t){if(!Hr.has(t.id))return;let r=import.meta.dirname,o=[C(r,"chrome_abe_decrypt.exe"),C(r,"../../native/windows/chrome_abe_decrypt.exe")].find(H);if(!o)return;let n=Ke(o,e,t.id);if(n)return n;let s=t.dirs.win32.split("/").slice(0,-1),i=t.id==="edge"?"msedge.exe":t.id==="brave"?"brave.exe":"chrome.exe",c=new Set([process.env.ProgramW6432,process.env.ProgramFiles,process.env["ProgramFiles(x86)"],process.env.LOCALAPPDATA]);for(let a of c){if(!a)continue;let f=C(a,...s);if(!H(C(f,"Application",i)))continue;let l=C(f,"Temp"),p=C(l,`chrome-tools-${Ir()}.exe`),u=!1,g=!1;try{u=Fr(l,{recursive:!0})!==void 0,Mr(o,p,Nr.COPYFILE_EXCL),g=!0;let m=Ke(p,e,t.id);if(m)return m}catch{}finally{if(g)try{Ur(p)}catch{}if(u)try{Kr(l)}catch{}}}}var Ge={name:"win32",getDefaultChromeDir(e=v()){let r=e.dirs.win32Base==="roaming"?process.env.APPDATA||(process.env.USERPROFILE?C(process.env.USERPROFILE,"AppData","Roaming"):""):process.env.LOCALAPPDATA||(process.env.USERPROFILE?C(process.env.USERPROFILE,"AppData","Local"):"");if(!r)throw new Error("Could not resolve the Windows application-data directory.");return C(r,...e.dirs.win32.split("/"))},getDecryptionKey(e,t=v()){let r=e||this.getDefaultChromeDir(t),o=Ue(r),n=JSON.stringify([o,t.id]),s=Be.get(n);if(s)return s;let i=C(o,"Local State");if(!H(i))throw new Error(`Could not find Chrome's "Local State" at ${i}.
18
- Run Google Chrome at least once so it creates the encryption key.`);let c;try{let l=Fe(i,"utf-8");c=JSON.parse(l)?.os_crypt?.encrypted_key}catch(l){throw new Error(`Failed to read os_crypt.encrypted_key from Local State: ${l.message}`)}if(!c)throw new Error(`No os_crypt.encrypted_key found in Local State.
19
- This profile may predate Chrome's encrypted-key scheme.`);let a=Buffer.from(c,"base64");if(!a.subarray(0,_e.length).equals(_e))throw new Error('Unexpected encrypted_key format (missing "DPAPI" prefix).');let f=Gr(a.subarray(_e.length));return Be.set(n,f),xe.set(f,{chromeDir:o,browser:t}),f},getAppBoundKey(e,t=v()){let r=Ue(e||this.getDefaultChromeDir(t)),o=JSON.stringify([r,t.id]),n=ve.get(o);if(n)return n;let s=C(r,"Local State");if(!H(s))return;let i;try{let f=Fe(s,"utf-8");i=JSON.parse(f)?.os_crypt?.app_bound_encrypted_key}catch{return}if(!i)return;let c=Buffer.from(i,"base64");if(!c.subarray(0,Ee.length).equals(Ee))return;let a=Wr(c.subarray(Ee.length),t);if(a)return ve.set(o,a),a},decrypt(e,t){if(e.subarray(0,3).toString()==="v20"){let r=xe.get(t),o=r&&this.getAppBoundKey?.(r.chromeDir,r.browser);return o?re(e,o):"<app-bound encryption unavailable>"}return Ae(e,t)},clearCache(){Be.clear(),ve.clear(),xe=new WeakMap}};import{execFileSync as jr}from"node:child_process";import{homedir as Vr}from"node:os";import{join as We}from"node:path";import{pbkdf2Sync as zr}from"node:crypto";var qr=1,Yr=16,Jr=Buffer.from("saltysalt"),Xr="peanuts",be=new Map;function Qr(e){let t=ye();if(t)return t(e);try{let r=jr("secret-tool",["lookup","application",e],{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim();if(r)return r}catch{}return Xr}var je={name:"linux",getDefaultChromeDir(e=v()){let t=process.env.XDG_CONFIG_HOME||We(Vr(),".config");return We(t,...e.dirs.linux.split("/"))},getDecryptionKey(e,t=v()){let r=t.linuxSecretApp||"chrome",o=be.get(r);if(o!==void 0)return o;let n=zr(Qr(r),Jr,qr,Yr,"sha1");return be.set(r,n),n},decrypt(e,t){return ee(e,t)},clearCache(){be.clear()}};var G=null;function W(){if(G)return G;switch(process.platform){case"darwin":G=Me;break;case"win32":G=Ge;break;case"linux":G=je;break;default:throw new Error(`Unsupported platform: ${process.platform}. chrome-tools supports macOS, Windows, and Linux.`)}return G}function De(e){return W().getDefaultChromeDir(Pe(e))}function Zr(e,t){return W().getDecryptionKey(e,Pe(t))}function Ve(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e);return W().decrypt(r,t)}function et(e,t){let r=Ve(e,t);return Buffer.isBuffer(r)?r.toString("utf-8"):r}function rt(){W().clearCache()}function Pe(e){return e?typeof e=="string"?M(e):e:v()}function j(e,t,r,o,n,s){let i=Pe(t),c=r,a,f=new Set;return l=>{let p;try{let u=W();u.getAppBoundKey&&l.subarray(0,3).toString()==="v20"?(a===void 0&&(a=u.getAppBoundKey(e,i)??null),p=a?re(l,a):"<app-bound encryption unavailable>"):(c??=u.getDecryptionKey(e,i),p=u.decrypt(l,c))}catch(u){throw new h("decryption_unavailable",u instanceof Error?u.message:String(u),{cause:u})}return typeof p=="string"&&!f.has(p)&&(f.add(p),w(o,n,s,new h("decryption_unavailable",p))),p}}var qe=["Login Data","History","Bookmarks","Cookies","Web Data","Local Storage","LocalStorage","Preferences"];function oe(e){let t=A(e,"Network","Cookies");return k(t)?t:A(e,"Cookies")}function ze(e){return qe.some(t=>k(A(e,t)))||k(oe(e))}function F(e){return De(e)}function st({includeMissing:e=!1}={}){let t=[];for(let r of $()){let o=F(r),n=k(o);!n&&!e||t.push({browser:r,chromeDir:o,installed:n,profileCount:n?V(o).length:0})}return t}function V(e,{reportAccessDenied:t=!1}={}){let r=e||F();if(!r)return[];try{let o=tt(r,{withFileTypes:!0}),n=[];for(let s of o){if(!s.isDirectory()||s.name==="Network")continue;let i=A(r,s.name);ze(i)&&n.push({name:s.name,path:i})}if(n.length===0&&ze(r)){let s=nt(r)||"Default";n.push({name:s,path:r})}return n}catch(o){let n=o.code;if(t&&(n==="EACCES"||n==="EPERM")){let s=process.platform==="darwin"?" Try Terminal.app if it already has access, or review the current app's permissions in System Settings \u2192 Privacy & Security.":" Check that your user has permission to read this directory.";throw new Error(`Permission denied reading the browser profile directory "${r}" (${n}).${s}`,{cause:o})}return[]}}function Ye(e){let t=e||F(),r=A(t,"Local State");if(!k(r))return[];try{let o=ot(r,"utf-8"),s=JSON.parse(o)?.profile?.info_cache;return!s||typeof s!="object"?[]:Object.entries(s).map(([i,c])=>{let a=c;return{directory:i,name:a.name||i,gaiaName:a.gaia_name||"",userName:a.user_name||"",email:a.user_name||"",avatarIcon:a.avatar_icon||"",isUsingDefaultName:a.is_using_default_name??!0,isEphemeral:a.is_ephemeral??!1,activeTime:a.active_time||0}})}catch{return[]}}function it(e){let t=e||F(),r=V(t),o=Ye(t),n=new Map;for(let s of o)n.set(s.directory,s);return r.map(s=>{let i=n.get(s.name),c=s.path,a={};for(let f of qe)a[f.replace(/\s+/g,"_").toLowerCase()]=k(A(c,f));return a.cookies=k(oe(c)),a.top_sites=k(A(c,"Top Sites")),a.extensions=k(A(c,"Extensions")),{directory:s.name,path:c,displayName:i?.name||s.name,gaiaName:i?.gaiaName||"",email:i?.email||"",avatarIcon:i?.avatarIcon||"",isEphemeral:i?.isEphemeral??!1,activeTime:i?.activeTime||0,dataFiles:a}})}function at(e,t){let r=e||F(),o=A(r,t);return k(o)?o:null}function S({profilePath:e,chromeDir:t,profile:r,browser:o,onDiagnostic:n}={}){let s=o?M(o):void 0,i=e||t||F(s),c;try{c=V(i,{reportAccessDenied:!!n})}catch(a){n?.({profile:r??"",store:"User Data",code:"unreadable",message:a instanceof Error?a.message:String(a)}),c=[]}if(r){let a=c.filter(f=>f.name===r);if(a.length===0)throw new Error(`Profile "${r}" not found in ${i}`);return a}return c}import{copyFileSync as gt,rmSync as yt}from"node:fs";import{basename as ie,dirname as Xe,join as ht}from"node:path";import{DatabaseSync as wt}from"node:sqlite";import{lstatSync as ct,mkdtempSync as ft,realpathSync as Je}from"node:fs";import{tmpdir as lt}from"node:os";import{isAbsolute as ut,join as pt,relative as dt,sep as mt}from"node:path";function T(e){try{let t=ct(e,{bigint:!0});if(!t.isFile())throw new h("unreadable",`Expected a regular store file: ${e}`);return t}catch(t){if(t.code==="ENOENT")return;throw t}}function ne(e,t){return!e||!t?e===t:e.dev===t.dev&&e.ino===t.ino&&e.size===t.size&&e.mtimeNs===t.mtimeNs&&e.ctimeNs===t.ctimeNs}function se(e,t){let r=Je(lt()),o=Je(e),n=dt(o,r);if(!ut(n)&&n!==".."&&!n.startsWith(".."+mt))throw new h("snapshot_unavailable","The temporary directory is inside the source profile. Set it to a directory outside the profile.");return ft(pt(r,t))}function St(e){return e.map(t=>{let r={};for(let o of Object.keys(t)){let n=t[o];typeof n=="bigint"?r[o]=Number(n):n instanceof Uint8Array&&!Buffer.isBuffer(n)?r[o]=Buffer.from(n.buffer,n.byteOffset,n.byteLength):r[o]=n}return r})}function _t(e,t){let r=["","-wal","-journal"],o=r.map(n=>T(e+n));if(!o[0])throw new h("missing_store",`Database file not found: ${e}`);try{for(let[n,s]of r.entries())o[n]&&gt(e+s,t+s)}catch(n){let s=n.code;throw["EBUSY","EPERM","EACCES","ENOENT"].includes(s??"")?new h("snapshot_unavailable",`Could not copy ${ie(e)} and its journals. Close the browser and retry if it is open.`,{cause:n}):n}if(r.some((n,s)=>!ne(o[s],T(e+n))))throw new h("snapshot_unavailable",`${ie(e)} changed during the copy. Close the browser and retry.`)}function Ce(e,t){let r=Xe(e),o=ie(r)==="Network"?Xe(r):r,n=se(o,"chrome-tools-"),s=ht(n,"snapshot.sqlite"),i;try{_t(e,s),i=new wt(s,{timeout:0}),i.exec("PRAGMA trusted_schema = OFF; PRAGMA query_only = ON;");let c=i;return t((a,f=[])=>{let l=a.replace(/^(?:\s+|--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+/,"");if(!/^(SELECT|WITH|VALUES|EXPLAIN|PRAGMA)\b/i.test(l))throw new h("unreadable","Only read queries are supported.");let p=c.prepare(l);return p.setReadBigInts(!0),St(p.all(...f))})}catch(c){if(c instanceof h)throw c;let a=c instanceof Error?c.message:String(c),f=/no such (table|column)/i.test(a)?"unsupported_schema":"unreadable";throw new h(f,`Database query failed on '${ie(e)}': ${a}`,{cause:c})}finally{try{i?.close()}finally{yt(n,{recursive:!0,force:!0,maxRetries:3})}}}function B(e,t,r=[]){return Ce(e,o=>o(t,r))}function Et(e,t){try{return B(e,"SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = ?",[t]).length>0}catch{return!1}}import{existsSync as Bt,readFileSync as vt}from"node:fs";import{homedir as Qe}from"node:os";import{join as ae}from"node:path";var Ze=[{file:"Login Data",source:"device"},{file:"Login Data For Account",source:"account"}],xt=ae(Qe(),".chrome_cdp_profile"),bt=ae(Qe(),".config","chrome-cdp-manager","config.json"),Dt=["0","off","none","false"];function Pt(){let e=process.env.CHROME_AUTOMATION_DIR?.trim();if(e&&Dt.includes(e.toLowerCase()))return;let t=e||Ct()||xt;return V(t).length>0?t:void 0}function Ct(){try{let e=JSON.parse(vt(bt,"utf-8"));return typeof e.profileDir=="string"&&e.profileDir?e.profileDir:void 0}catch{return}}function er(e,t){let r=[],o=e||t?void 0:Pt();return o&&r.push(o),r.push(e),r}function Rt({chromeDir:e,profilePath:t,profile:r,browser:o}={}){let n=t||e,s=[];for(let i of er(n,o)){let c;try{c=S({chromeDir:i,profile:r,browser:o})}catch(a){s.push({root:i??"default",profile:r??"*",file:"*",source:"device",exists:!1,rows:null,error:a instanceof Error?a.message:String(a)});continue}for(let a of c)for(let f of Ze){let l=ae(a.path,f.file),p={root:i??"default",profile:a.name,file:f.file,source:f.source,exists:Bt(l),rows:null};try{p.rows=B(l,"SELECT COUNT(*) AS n FROM logins")[0]?.n??0}catch(u){p.error=u instanceof Error?u.message:String(u)}s.push(p)}}return s}function kt({chromeDir:e,profilePath:t,profile:r,search:o,browser:n,decryptionKey:s,onDiagnostic:i}={}){let c=t||e,a=n??v().id,f=er(c,n),l=[],p=o?.toLowerCase(),u,g=!1;for(let m of f){let d;try{d=S({chromeDir:m,profile:r,browser:a,onDiagnostic:i})}catch(y){u??=y;continue}g=!0;for(let y of d)for(let _ of Ze){let O=ae(y.path,_.file),le=j(m??y.path,a,s,i,y.name,_.file);try{let P=B(O,`SELECT origin_url, username_value, password_value, date_last_used
20
- FROM logins ORDER BY origin_url`);for(let b of P){if(p&&!(b.origin_url&&b.origin_url.toLowerCase().includes(p))&&!(b.username_value&&b.username_value.toLowerCase().includes(p)))continue;let N=b.password_value?.length>0?le(b.password_value):"";l.push({profile:y.name,source:_.source,url:b.origin_url,username:b.username_value,password:Buffer.isBuffer(N)?N.toString("utf8"):N,lastUsed:E(b.date_last_used||0)})}}catch(P){w(i,y.name,_.file,P)}}}if(!g&&u)throw u;return l}import{readFileSync as Lt}from"node:fs";import{join as Ot}from"node:path";function rr(e,t=""){let r=[];if(!e)return r;let o=t?`${t}/${e.name||""}`:e.name||"";if(e.type==="url"&&r.push({title:e.name||"",url:e.url||"",folder:t,dateAdded:E(e.date_added),dateLastUsed:E(e.date_last_used),id:e.id,guid:e.guid||""}),e.children&&Array.isArray(e.children))for(let n of e.children)r.push(...rr(n,o));return r}function At({chromeDir:e,profilePath:t,profile:r,folder:o,search:n,browser:s,onDiagnostic:i}={}){let c=S({chromeDir:e,profilePath:t,profile:r,browser:s,onDiagnostic:i}),a=[];for(let l of c){let p=Ot(l.path,"Bookmarks");try{let u=Lt(p,"utf-8"),m=JSON.parse(u).roots;if(!m)continue;let d=["bookmark_bar","other","synced"];for(let y of d)if(m[y]){let _=rr(m[y],"");for(let O of _)O.profile=l.name,a.push(O)}}catch(u){w(i,l.name,"Bookmarks",u instanceof SyntaxError?new Error("Invalid Bookmarks JSON."):u)}}let f=a;if(o){let l=o.toLowerCase();f=f.filter(p=>p.folder.toLowerCase().includes(l))}if(n){let l=n.toLowerCase();f=f.filter(p=>p.title.toLowerCase().includes(l)||p.url.toLowerCase().includes(l))}return f}import{join as tr}from"node:path";function L(e){if(e===void 0)return;let t=Math.trunc(Number(e));return Number.isFinite(t)&&t>0?t:void 0}function R(e,t){let r=L(t);return r===void 0?e:e.slice(0,r)}function z(e){return`%${e.replace(/([%_\\])/g,"\\$1")}%`}function Tt({chromeDir:e,profilePath:t,profile:r,search:o,limit:n=100,browser:s,onDiagnostic:i}={}){let c=S({chromeDir:e,profilePath:t,profile:r,browser:s,onDiagnostic:i}),a=[],f=L(n);for(let l of c){let p=tr(l.path,"History");try{let u="SELECT url, title, visit_count, last_visit_time FROM urls",g=[];if(o){u+=" WHERE url LIKE ? ESCAPE '\\' OR IFNULL(title, '') LIKE ? ESCAPE '\\'";let d=z(o);g.push(d,d)}u+=" ORDER BY last_visit_time DESC",f&&(u+=` LIMIT ${f}`);let m=B(p,u,g);for(let d of m)a.push({profile:l.name,url:d.url,title:d.title||"",visitCount:d.visit_count||0,lastVisit:E(d.last_visit_time||0)})}catch(u){w(i,l.name,"History",u)}}return R(a,n)}function It({chromeDir:e,profilePath:t,profile:r,limit:o=100,browser:n,onDiagnostic:s}={}){let i=S({chromeDir:e,profilePath:t,profile:r,browser:n,onDiagnostic:s}),c=[],a=L(o);for(let f of i){let l=tr(f.path,"History");try{let p=`SELECT kst.term, u.url
18
+ (powershell: ${o?.message??o})`)}return Buffer.from(r.trim(),"base64")}function Pe(e){let t=Wr(e),r=He(t);return H(b(t,"Local State"))?t:r!==t&&H(b(r,"Local State"))?r:t}function We(e,t,r){try{let o=De(e,[r],{input:t.toString("base64"),encoding:"utf8",timeout:1e4,windowsHide:!0,stdio:["pipe","pipe","pipe"],cwd:He(e)}),n=Buffer.from(o.trim(),"base64");return n.length===32?{key:n}:{error:"Unexpected App-Bound Encryption key length."}}catch(o){return{error:o?.stderr?.toString?.("utf8")?.trim()||o?.message||"App-Bound Encryption helper failed."}}}function qr(){return process.platform==="win32"&&process.env.CHROME_TOOLS_NO_ELEVATE!=="1"&&!!(process.stdin.isTTY||process.stdout.isTTY)}function zr(e,t,r,o){try{let n=De(process.execPath,["--input-type=commonjs","-e",Gr,e,b(t,"Temp"),o],{input:r.toString("base64"),encoding:"utf8",timeout:65e3,windowsHide:!0,stdio:["pipe","pipe","pipe"]}),i=Buffer.from(n.trim(),"base64");return i.length===32?{key:i}:{error:"Unexpected App-Bound Encryption key length."}}catch(n){return{error:n?.stderr?.toString?.("utf8")?.trim()||n?.message||"Elevated App-Bound Encryption failed."}}}function Yr(e,t){if(!Hr.has(t.id))return{error:`App-Bound Encryption is not supported for ${t.name}.`};let r=import.meta.dirname,o=[b(r,"chrome_abe_decrypt.exe"),b(r,"../../native/windows/chrome_abe_decrypt.exe")].find(H);if(!o)return{error:"Bundled chrome_abe_decrypt.exe helper was not found."};let n=We(o,e,t.id);if(n.key)return n;let i=t.dirs.win32.split("/").slice(0,-1),s=t.id==="edge"?"msedge.exe":t.id==="brave"?"brave.exe":"chrome.exe",c=new Set([process.env.ProgramW6432,process.env.ProgramFiles,process.env["ProgramFiles(x86)"],process.env.LOCALAPPDATA]),a=[],f=n.error;for(let l of c){if(!l)continue;let p=b(l,...i);if(!H(b(p,"Application",s)))continue;let u=b(p,"Temp"),g=b(u,`chrome-tools-${$r()}.exe`),m=!1,d=!1;try{m=Ur(u,{recursive:!0})!==void 0,Fr(o,g,Nr.COPYFILE_EXCL),d=!0;let y=We(g,e,t.id);if(y.key)return y;f=y.error}catch(y){jr.has(y?.code)?a.push(p):y?.message&&(f=y.message)}finally{if(d)try{Mr(g)}catch{}if(m)try{Kr(u)}catch{}}}if(a.length>0){if(qr())for(let u of a){let g=zr(o,u,e,t.id);if(g.key)return g;f=g.error}let l=b(a[0],"Temp"),p=f?` (${f})`:"";return{error:`Administrator privileges are required to stage the App-Bound Encryption helper under ${l}. Run from an elevated Administrator terminal or approve the UAC prompt${p}.`}}return{error:f}}var je={name:"win32",getDefaultChromeDir(e=_()){let r=e.dirs.win32Base==="roaming"?process.env.APPDATA||(process.env.USERPROFILE?b(process.env.USERPROFILE,"AppData","Roaming"):""):process.env.LOCALAPPDATA||(process.env.USERPROFILE?b(process.env.USERPROFILE,"AppData","Local"):"");if(!r)throw new Error("Could not resolve the Windows application-data directory.");return b(r,...e.dirs.win32.split("/"))},getDecryptionKey(e,t=_()){let r=e||this.getDefaultChromeDir(t),o=Pe(r),n=JSON.stringify([o,t.id]),i=ve.get(n);if(i)return i;let s=b(o,"Local State");if(!H(s))throw new Error(`Could not find Chrome's "Local State" at ${s}.
19
+ Run Google Chrome at least once so it creates the encryption key.`);let c;try{let l=Ke(s,"utf-8");c=JSON.parse(l)?.os_crypt?.encrypted_key}catch(l){throw new Error(`Failed to read os_crypt.encrypted_key from Local State: ${l.message}`)}if(!c)throw new Error(`No os_crypt.encrypted_key found in Local State.
20
+ This profile may predate Chrome's encrypted-key scheme.`);let a=Buffer.from(c,"base64");if(!a.subarray(0,Be.length).equals(Be))throw new Error('Unexpected encrypted_key format (missing "DPAPI" prefix).');let f=Vr(a.subarray(Be.length));return ve.set(n,f),be.set(f,{chromeDir:o,browser:t}),f},getAppBoundKey(e,t=_()){let r=Pe(e||this.getDefaultChromeDir(t)),o=JSON.stringify([r,t.id]),n=xe.get(o);if(n)return n;if(ee.has(o))return;let i=b(r,"Local State");if(!H(i))return;let s;try{let f=Ke(i,"utf-8");s=JSON.parse(f)?.os_crypt?.app_bound_encrypted_key}catch{return}if(!s)return;let c=Buffer.from(s,"base64");if(!c.subarray(0,_e.length).equals(_e))return;let a=Yr(c.subarray(_e.length),t);if(!a.key){a.error&&ee.set(o,a.error);return}return ee.delete(o),xe.set(o,a.key),a.key},getAppBoundError(e,t=_()){let r=Pe(e||this.getDefaultChromeDir(t));return ee.get(JSON.stringify([r,t.id]))},decrypt(e,t){if(e.subarray(0,3).toString()==="v20"){let r=be.get(t),o=r&&this.getAppBoundKey?.(r.chromeDir,r.browser);return o?te(e,o):"<app-bound encryption unavailable>"}return $e(e,t)},clearCache(){ve.clear(),xe.clear(),ee.clear(),be=new WeakMap}};import{execFileSync as Jr}from"node:child_process";import{homedir as Xr}from"node:os";import{join as Ge}from"node:path";import{pbkdf2Sync as Qr}from"node:crypto";var Zr=1,et=16,rt=Buffer.from("saltysalt"),tt="peanuts",Ce=new Map;function ot(e){let t=he();if(t)return t(e);try{let r=Jr("secret-tool",["lookup","application",e],{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim();if(r)return r}catch{}return tt}var Ve={name:"linux",getDefaultChromeDir(e=_()){let t=process.env.XDG_CONFIG_HOME||Ge(Xr(),".config");return Ge(t,...e.dirs.linux.split("/"))},getDecryptionKey(e,t=_()){let r=t.linuxSecretApp||"chrome",o=Ce.get(r);if(o!==void 0)return o;let n=Qr(ot(r),rt,Zr,et,"sha1");return Ce.set(r,n),n},decrypt(e,t){return re(e,t)},clearCache(){Ce.clear()}};var j=null;function F(){if(j)return j;switch(process.platform){case"darwin":j=Me;break;case"win32":j=je;break;case"linux":j=Ve;break;default:throw new Error(`Unsupported platform: ${process.platform}. chrome-tools supports macOS, Windows, and Linux.`)}return j}function Re(e){return F().getDefaultChromeDir(ke(e))}function nt(e,t){return F().getDecryptionKey(e,ke(t))}function qe(e,t){if(!e||e.length===0)return Buffer.alloc(0);let r=Buffer.isBuffer(e)?e:Buffer.from(e);return F().decrypt(r,t)}function it(e,t){let r=qe(e,t);return Buffer.isBuffer(r)?r.toString("utf-8"):r}function st(){F().clearCache()}function ke(e){return e?typeof e=="string"?N(e):e:_()}function G(e,t,r,o,n,i){let s=ke(t),c=r,a,f=new Set;return l=>{let p;try{let u=F();u.getAppBoundKey&&l.subarray(0,3).toString()==="v20"?(a===void 0&&(a=u.getAppBoundKey(e,s)??null),p=a?te(l,a):"<app-bound encryption unavailable>"):(c??=u.getDecryptionKey(e,s),p=u.decrypt(l,c))}catch(u){throw new h("decryption_unavailable",u instanceof Error?u.message:String(u),{cause:u})}if(typeof p=="string"&&!f.has(p)){f.add(p);let u=p==="<app-bound encryption unavailable>"?F().getAppBoundError?.(e,s):void 0;S(o,n,i,new h("decryption_unavailable",u||p))}return p}}var Ye=["Login Data","History","Bookmarks","Cookies","Web Data","Local Storage","LocalStorage","Preferences"];function ne(e){let t=L(e,"Network","Cookies");return k(t)?t:L(e,"Cookies")}function ze(e){return Ye.some(t=>k(L(e,t)))||k(ne(e))}function U(e){return Re(e)}function lt({includeMissing:e=!1}={}){let t=[];for(let r of W()){let o=U(r),n=k(o);!n&&!e||t.push({browser:r,chromeDir:o,installed:n,profileCount:n?V(o).length:0})}return t}function V(e,{reportAccessDenied:t=!1}={}){let r=e||U();if(!r)return[];try{let o=at(r,{withFileTypes:!0}),n=[];for(let i of o){if(!i.isDirectory()||i.name==="Network")continue;let s=L(r,i.name);ze(s)&&n.push({name:i.name,path:s})}if(n.length===0&&ze(r)){let i=ft(r)||"Default";n.push({name:i,path:r})}return n}catch(o){let n=o.code;if(t&&(n==="EACCES"||n==="EPERM")){let i=process.platform==="darwin"?" Try Terminal.app if it already has access, or review the current app's permissions in System Settings \u2192 Privacy & Security.":" Check that your user has permission to read this directory.";throw new Error(`Permission denied reading the browser profile directory "${r}" (${n}).${i}`,{cause:o})}return[]}}function Je(e){let t=e||U(),r=L(t,"Local State");if(!k(r))return[];try{let o=ct(r,"utf-8"),i=JSON.parse(o)?.profile?.info_cache;return!i||typeof i!="object"?[]:Object.entries(i).map(([s,c])=>{let a=c;return{directory:s,name:a.name||s,gaiaName:a.gaia_name||"",userName:a.user_name||"",email:a.user_name||"",avatarIcon:a.avatar_icon||"",isUsingDefaultName:a.is_using_default_name??!0,isEphemeral:a.is_ephemeral??!1,activeTime:a.active_time||0}})}catch{return[]}}function ut(e){let t=e||U(),r=V(t),o=Je(t),n=new Map;for(let i of o)n.set(i.directory,i);return r.map(i=>{let s=n.get(i.name),c=i.path,a={};for(let f of Ye)a[f.replace(/\s+/g,"_").toLowerCase()]=k(L(c,f));return a.cookies=k(ne(c)),a.top_sites=k(L(c,"Top Sites")),a.extensions=k(L(c,"Extensions")),{directory:i.name,path:c,displayName:s?.name||i.name,gaiaName:s?.gaiaName||"",email:s?.email||"",avatarIcon:s?.avatarIcon||"",isEphemeral:s?.isEphemeral??!1,activeTime:s?.activeTime||0,dataFiles:a}})}function pt(e,t){let r=e||U(),o=L(r,t);return k(o)?o:null}function w({profilePath:e,chromeDir:t,profile:r,browser:o,onDiagnostic:n}={}){let i=o?N(o):void 0,s=e||t||U(i),c;try{c=V(s,{reportAccessDenied:!!n})}catch(a){n?.({profile:r??"",store:"User Data",code:"unreadable",message:a instanceof Error?a.message:String(a)}),c=[]}if(r){let a=c.filter(f=>f.name===r);if(a.length===0)throw new Error(`Profile "${r}" not found in ${s}`);return a}return c}import{copyFileSync as Et,rmSync as Bt}from"node:fs";import{basename as ae,dirname as Qe,join as _t}from"node:path";import{DatabaseSync as vt}from"node:sqlite";import{lstatSync as dt,mkdtempSync as mt,realpathSync as Xe}from"node:fs";import{tmpdir as gt}from"node:os";import{isAbsolute as yt,join as ht,relative as St,sep as wt}from"node:path";function T(e){try{let t=dt(e,{bigint:!0});if(!t.isFile())throw new h("unreadable",`Expected a regular store file: ${e}`);return t}catch(t){if(t.code==="ENOENT")return;throw t}}function ie(e,t){return!e||!t?e===t:e.dev===t.dev&&e.ino===t.ino&&e.size===t.size&&e.mtimeNs===t.mtimeNs&&e.ctimeNs===t.ctimeNs}function se(e,t){let r=Xe(gt()),o=Xe(e),n=St(o,r);if(!yt(n)&&n!==".."&&!n.startsWith(".."+wt))throw new h("snapshot_unavailable","The temporary directory is inside the source profile. Set it to a directory outside the profile.");return mt(ht(r,t))}function xt(e){return e.map(t=>{let r={};for(let o of Object.keys(t)){let n=t[o];typeof n=="bigint"?r[o]=Number(n):n instanceof Uint8Array&&!Buffer.isBuffer(n)?r[o]=Buffer.from(n.buffer,n.byteOffset,n.byteLength):r[o]=n}return r})}function bt(e,t){let r=["","-wal","-journal"],o=r.map(n=>T(e+n));if(!o[0])throw new h("missing_store",`Database file not found: ${e}`);try{for(let[n,i]of r.entries())o[n]&&Et(e+i,t+i)}catch(n){let i=n.code;throw["EBUSY","EPERM","EACCES","ENOENT"].includes(i??"")?new h("snapshot_unavailable",`Could not copy ${ae(e)} and its journals. Close the browser and retry if it is open.`,{cause:n}):n}if(r.some((n,i)=>!ie(o[i],T(e+n))))throw new h("snapshot_unavailable",`${ae(e)} changed during the copy. Close the browser and retry.`)}function Oe(e,t){let r=Qe(e),o=ae(r)==="Network"?Qe(r):r,n=se(o,"chrome-tools-"),i=_t(n,"snapshot.sqlite"),s;try{bt(e,i),s=new vt(i,{timeout:0}),s.exec("PRAGMA trusted_schema = OFF; PRAGMA query_only = ON;");let c=s;return t((a,f=[])=>{let l=a.replace(/^(?:\s+|--[^\n]*(?:\n|$)|\/\*[\s\S]*?\*\/)+/,"");if(!/^(SELECT|WITH|VALUES|EXPLAIN|PRAGMA)\b/i.test(l))throw new h("unreadable","Only read queries are supported.");let p=c.prepare(l);return p.setReadBigInts(!0),xt(p.all(...f))})}catch(c){if(c instanceof h)throw c;let a=c instanceof Error?c.message:String(c),f=/no such (table|column)/i.test(a)?"unsupported_schema":"unreadable";throw new h(f,`Database query failed on '${ae(e)}': ${a}`,{cause:c})}finally{try{s?.close()}finally{Bt(n,{recursive:!0,force:!0,maxRetries:3})}}}function v(e,t,r=[]){return Oe(e,o=>o(t,r))}function Pt(e,t){try{return v(e,"SELECT 1 FROM sqlite_schema WHERE type = 'table' AND name = ?",[t]).length>0}catch{return!1}}import{existsSync as Dt,readFileSync as Ct}from"node:fs";import{homedir as Ze}from"node:os";import{join as ce}from"node:path";var er=[{file:"Login Data",source:"device"},{file:"Login Data For Account",source:"account"}],Rt=ce(Ze(),".chrome_cdp_profile"),kt=ce(Ze(),".config","chrome-cdp-manager","config.json"),Ot=["0","off","none","false"];function At(){let e=process.env.CHROME_AUTOMATION_DIR?.trim();if(e&&Ot.includes(e.toLowerCase()))return;let t=e||Lt()||Rt;return V(t).length>0?t:void 0}function Lt(){try{let e=JSON.parse(Ct(kt,"utf-8"));return typeof e.profileDir=="string"&&e.profileDir?e.profileDir:void 0}catch{return}}function rr(e,t){let r=[],o=e||t?void 0:At();return o&&r.push(o),r.push(e),r}function Tt({chromeDir:e,profilePath:t,profile:r,browser:o}={}){let n=t||e,i=[];for(let s of rr(n,o)){let c;try{c=w({chromeDir:s,profile:r,browser:o})}catch(a){i.push({root:s??"default",profile:r??"*",file:"*",source:"device",exists:!1,rows:null,error:a instanceof Error?a.message:String(a)});continue}for(let a of c)for(let f of er){let l=ce(a.path,f.file),p={root:s??"default",profile:a.name,file:f.file,source:f.source,exists:Dt(l),rows:null};try{p.rows=v(l,"SELECT COUNT(*) AS n FROM logins")[0]?.n??0}catch(u){p.error=u instanceof Error?u.message:String(u)}i.push(p)}}return i}function It({chromeDir:e,profilePath:t,profile:r,search:o,browser:n,decryptionKey:i,onDiagnostic:s}={}){let c=t||e,a=n??_().id,f=rr(c,n),l=[],p=o?.toLowerCase(),u,g=!1;for(let m of f){let d;try{d=w({chromeDir:m,profile:r,browser:a,onDiagnostic:s})}catch(y){u??=y;continue}g=!0;for(let y of d)for(let E of er){let A=ce(y.path,E.file),ue=G(m??y.path,a,i,s,y.name,E.file);try{let C=v(A,`SELECT origin_url, username_value, password_value, date_last_used
21
+ FROM logins ORDER BY origin_url`);for(let P of C){if(p&&!(P.origin_url&&P.origin_url.toLowerCase().includes(p))&&!(P.username_value&&P.username_value.toLowerCase().includes(p)))continue;let $=P.password_value?.length>0?ue(P.password_value):"";l.push({profile:y.name,source:E.source,url:P.origin_url,username:P.username_value,password:Buffer.isBuffer($)?$.toString("utf8"):$,lastUsed:B(P.date_last_used||0)})}}catch(C){S(s,y.name,E.file,C)}}}if(!g&&u)throw u;return l}import{readFileSync as $t}from"node:fs";import{join as Nt}from"node:path";function tr(e,t=""){let r=[];if(!e)return r;let o=t?`${t}/${e.name||""}`:e.name||"";if(e.type==="url"&&r.push({title:e.name||"",url:e.url||"",folder:t,dateAdded:B(e.date_added),dateLastUsed:B(e.date_last_used),id:e.id,guid:e.guid||""}),e.children&&Array.isArray(e.children))for(let n of e.children)r.push(...tr(n,o));return r}function Ft({chromeDir:e,profilePath:t,profile:r,folder:o,search:n,browser:i,onDiagnostic:s}={}){let c=w({chromeDir:e,profilePath:t,profile:r,browser:i,onDiagnostic:s}),a=[];for(let l of c){let p=Nt(l.path,"Bookmarks");try{let u=$t(p,"utf-8"),m=JSON.parse(u).roots;if(!m)continue;let d=["bookmark_bar","other","synced"];for(let y of d)if(m[y]){let E=tr(m[y],"");for(let A of E)A.profile=l.name,a.push(A)}}catch(u){S(s,l.name,"Bookmarks",u instanceof SyntaxError?new Error("Invalid Bookmarks JSON."):u)}}let f=a;if(o){let l=o.toLowerCase();f=f.filter(p=>p.folder.toLowerCase().includes(l))}if(n){let l=n.toLowerCase();f=f.filter(p=>p.title.toLowerCase().includes(l)||p.url.toLowerCase().includes(l))}return f}import{join as or}from"node:path";function O(e){if(e===void 0)return;let t=Math.trunc(Number(e));return Number.isFinite(t)&&t>0?t:void 0}function R(e,t){let r=O(t);return r===void 0?e:e.slice(0,r)}function q(e){return`%${e.replace(/([%_\\])/g,"\\$1")}%`}function Ut({chromeDir:e,profilePath:t,profile:r,search:o,limit:n=100,browser:i,onDiagnostic:s}={}){let c=w({chromeDir:e,profilePath:t,profile:r,browser:i,onDiagnostic:s}),a=[],f=O(n);for(let l of c){let p=or(l.path,"History");try{let u="SELECT url, title, visit_count, last_visit_time FROM urls",g=[];if(o){u+=" WHERE url LIKE ? ESCAPE '\\' OR IFNULL(title, '') LIKE ? ESCAPE '\\'";let d=q(o);g.push(d,d)}u+=" ORDER BY last_visit_time DESC",f&&(u+=` LIMIT ${f}`);let m=v(p,u,g);for(let d of m)a.push({profile:l.name,url:d.url,title:d.title||"",visitCount:d.visit_count||0,lastVisit:B(d.last_visit_time||0)})}catch(u){S(s,l.name,"History",u)}}return R(a,n)}function Mt({chromeDir:e,profilePath:t,profile:r,limit:o=100,browser:n,onDiagnostic:i}={}){let s=w({chromeDir:e,profilePath:t,profile:r,browser:n,onDiagnostic:i}),c=[],a=O(o);for(let f of s){let l=or(f.path,"History");try{let p=`SELECT kst.term, u.url
21
22
  FROM keyword_search_terms kst
22
23
  JOIN urls u ON kst.url_id = u.id
23
- ORDER BY u.last_visit_time DESC`;a&&(p+=` LIMIT ${a}`);let u=B(l,p);for(let g of u)c.push({profile:f.name,term:g.term||"",url:g.url||""})}catch(p){w(s,f.name,"History",p)}}return R(c,o)}import{existsSync as Nt}from"node:fs";import{createHash as Mt}from"node:crypto";function Ft(e,t){if(!Buffer.isBuffer(e))return e;let r=Mt("sha256").update(t).digest();return(e.length>=r.length&&e.subarray(0,r.length).equals(r)?e.subarray(r.length):e).toString("utf-8")}function Ut(e){if(!e)return null;try{return new URL(e)}catch{try{if(!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e))return new URL("https://"+e)}catch{}}return null}function Kt(e){let t=new Set;t.add(e),t.add("."+e);let r=e.split(".");for(let o=1;o<r.length;o++){let n=r.slice(o).join(".");t.add(n),t.add("."+n)}return Array.from(t)}function $t(e,t){return!!(e===t||t.startsWith(".")&&(e===t.slice(1)||e.endsWith(t)))}function Ht(e,t){let r=e||"/",o=t||"/";return!!(o==="/"||r===o||r.startsWith(o)&&(o.endsWith("/")||r[o.length]==="/"))}function Gt({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,domain:s,url:i,decrypt:c=!0,limit:a=100,decryptionKey:f}={}){let l=t||e,p=o??v().id,u=S({chromeDir:e,profilePath:t,profile:r,browser:p,onDiagnostic:n}),g=[],m=Ut(i),d=L(a),y;for(let _ of u){let O=oe(_.path);if(!Nt(O)){w(n,_.name,"Cookies",new h("missing_store","Cookies database file not found."));continue}let le=j(l??_.path,p,f,n,_.name,"Cookies");try{let P=`SELECT host_key, name, value, encrypted_value, path,
24
+ ORDER BY u.last_visit_time DESC`;a&&(p+=` LIMIT ${a}`);let u=v(l,p);for(let g of u)c.push({profile:f.name,term:g.term||"",url:g.url||""})}catch(p){S(i,f.name,"History",p)}}return R(c,o)}import{existsSync as Kt}from"node:fs";import{createHash as Wt}from"node:crypto";function Ht(e,t){if(!Buffer.isBuffer(e))return e;let r=Wt("sha256").update(t).digest();return(e.length>=r.length&&e.subarray(0,r.length).equals(r)?e.subarray(r.length):e).toString("utf-8")}function jt(e){if(!e)return null;try{return new URL(e)}catch{try{if(!/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(e))return new URL("https://"+e)}catch{}}return null}function Gt(e){let t=new Set;t.add(e),t.add("."+e);let r=e.split(".");for(let o=1;o<r.length;o++){let n=r.slice(o).join(".");t.add(n),t.add("."+n)}return Array.from(t)}function Vt(e,t){return!!(e===t||t.startsWith(".")&&(e===t.slice(1)||e.endsWith(t)))}function qt(e,t){let r=e||"/",o=t||"/";return!!(o==="/"||r===o||r.startsWith(o)&&(o.endsWith("/")||r[o.length]==="/"))}function zt({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,domain:i,url:s,decrypt:c=!0,limit:a=100,decryptionKey:f}={}){let l=t||e,p=o??_().id,u=w({chromeDir:e,profilePath:t,profile:r,browser:p,onDiagnostic:n}),g=[],m=jt(s),d=O(a),y;for(let E of u){let A=ne(E.path);if(!Kt(A)){S(n,E.name,"Cookies",new h("missing_store","Cookies database file not found."));continue}let ue=G(l??E.path,p,f,n,E.name,"Cookies");try{let C=`SELECT host_key, name, value, encrypted_value, path,
24
25
  expires_utc, is_secure, is_httponly, samesite,
25
26
  creation_utc, last_access_utc
26
- FROM cookies`,b=[],N=[];if(s)b.push("host_key LIKE ?"),N.push(`%${s}%`);else if(m){let x=Kt(m.hostname),J=x.map(()=>"?").join(", ");b.push(`host_key IN (${J})`),N.push(...x)}b.length>0&&(P+=` WHERE ${b.join(" AND ")}`),P+=" ORDER BY host_key, name",d&&!i&&(P+=` LIMIT ${d}`);let Er=B(O,P,N);for(let x of Er){if(m&&(!$t(m.hostname,x.host_key||"")||!Ht(m.pathname||"/",x.path||"/")||x.is_secure&&m.protocol!=="https:"))continue;let J=x.value||"";!J&&x.encrypted_value?.length>0&&c&&(J=Ft(le(x.encrypted_value),x.host_key||"")),g.push({profile:_.name,domain:x.host_key||"",name:x.name||"",value:J,path:x.path||"/",expires:E(x.expires_utc||0),secure:!!x.is_secure,httpOnly:!!x.is_httponly,sameSite:["unspecified","lax","strict","none"][x.samesite]||"unspecified",created:E(x.creation_utc||0),lastAccessed:E(x.last_access_utc||0)})}}catch(P){w(n,_.name,"Cookies",P),y??=new Error(`Could not read cookies for profile "${_.name}" at ${O}: `+(P instanceof Error?P.message:String(P)))}}if(!n&&g.length===0&&y)throw y;return R(g,a)}import{join as mr}from"node:path";import{zstdDecompressSync as Zt}from"node:zlib";function q(e,t){let r=0,o=0;for(let n=t;n<e.length&&n<t+5;n++){let s=e[n];if(r|=(s&127)<<o,(s&128)===0)return{value:r>>>0,nextOffset:n+1};o+=7}return null}var Re=64*1024*1024;function ce(e){let t=q(e,0);if(!t||t.value>Re)throw new Error("Invalid Snappy length");let r=Buffer.alloc(t.value),o=t.nextOffset,n=0;for(;o<e.length&&n<r.length;){let s=e[o++],i=s&3;if(i===0){let f=s>>2;if(f<60)f+=1;else{let l=f-59;if(o+l>e.length)throw new Error("Invalid Snappy literal");f=1;for(let p=0;p<l;p++)f+=e[o++]<<p*8}if(o+f>e.length||n+f>r.length)throw new Error("Invalid Snappy literal length");e.copy(r,n,o,o+f),o+=f,n+=f;continue}let c,a;if(i===1){if(o>=e.length)throw new Error("Invalid Snappy copy");c=(s>>2&7)+4,a=(s&224)<<3|e[o++]}else if(i===2){if(o+2>e.length)throw new Error("Invalid Snappy copy");c=(s>>2)+1,a=e.readUInt16LE(o),o+=2}else{if(o+4>e.length)throw new Error("Invalid Snappy copy");c=(s>>2)+1,a=e.readUInt32LE(o),o+=4}if(a<=0||a>n||n+c>r.length)throw new Error("Invalid Snappy offset");for(let f=0;f<c;f++)r[n]=r[n-a],n++}if(n!==r.length)throw new Error("Truncated Snappy stream");return r}import{copyFileSync as Wt,readFileSync as or,readdirSync as jt,rmSync as Vt}from"node:fs";import{join as Y}from"node:path";function Le(e){return jt(e).filter(t=>/\.(log|ldb|sst)$/i.test(t)).sort()}function ur(e,t){let r=se(t,"chrome-local-storage-");try{let o=Le(e),n=o.map(i=>T(Y(e,i)));try{for(let i of o)Wt(Y(e,i),Y(r,i))}catch(i){throw new h("snapshot_unavailable","Could not copy Local Storage. Close the browser and retry if it is open.",{cause:i})}let s=Le(e);if(s.length!==o.length||o.some((i,c)=>i!==s[c]||!ne(n[c],T(Y(e,i)))))throw new h("snapshot_unavailable","Local Storage changed during the copy. Close the browser and retry.");return qt(r).values()}finally{Vt(r,{recursive:!0,force:!0,maxRetries:3})}}var zt=0xdb4775248b80fb57n,nr=32768,pr=0,dr=1;function qt(e){let t=new Map,r=Le(e);for(let o of r){let n=Y(e,o),s=or(n);if(/\.(ldb|sst)$/i.test(o))for(let i of Jt(s))sr(t,i)}for(let o of r){if(!/\.log$/i.test(o))continue;let n=Y(e,o),s=or(n);for(let i of Yt(s))sr(t,i)}return t}function sr(e,t){let r=t.key.toString("hex"),o=e.get(r);o&&o.sequence>t.sequence||e.set(r,t)}function Yt(e){let t=[],r=0,o=[];for(;r+7<=e.length;){let n=nr-r%nr;if(n<7){r+=n;continue}let s=e.readUInt16LE(r+4),i=e[r+6];if(r+=7,i===0&&s===0){r+=s;continue}if(s>e.length-r||s>n-7)break;let c=e.subarray(r,r+s);r+=s,i===1?(t.push(...ir(c)),o=[]):i===2?o=[Buffer.from(c)]:i===3&&o.length>0?o.push(Buffer.from(c)):i===4&&o.length>0&&(o.push(Buffer.from(c)),t.push(...ir(Buffer.concat(o))),o=[])}return t}function ir(e){if(e.length<12)return[];let t=[],r=Xt(e,0),o=e.readUInt32LE(8),n=12,s=0;for(;n<e.length&&s<o;){let i=e[n++],c=fr(e,n);if(!c)break;n=c.nextOffset;let a=r+BigInt(s);if(i===dr){let f=fr(e,n);if(!f)break;n=f.nextOffset,t.push({key:c.value,value:f.value,sequence:a,deleted:!1})}else if(i===pr)t.push({key:c.value,sequence:a,deleted:!0});else break;s++}return t}function Jt(e){let t=[];if(e.length<48||e.readBigUInt64LE(e.length-8)!==zt)return t;let o=e.subarray(e.length-48,e.length-8),n=ke(o,0);if(!n)return t;let s=ke(o,n.bytesRead);if(!s)return t;let i=ar(e,s);if(!i)return t;for(let c of cr(i)){let a=ke(c.value,0);if(!a)continue;let f=ar(e,a);if(f)for(let l of cr(f)){if(l.key.length<8)continue;let p=l.key,u=p.length-8,g=p[u],m=Qt(p.subarray(u)),d=p.subarray(0,u);g===dr?t.push({key:d,value:l.value,sequence:m,deleted:!1}):g===pr&&t.push({key:d,sequence:m,deleted:!0})}}return t}function ar(e,t){let r=t.offset+t.size;if(t.offset<0||t.size<0||r+5>e.length)return null;let o=e.subarray(t.offset,r),n=e[r];if(n===0)return o;if(n===1)try{return ce(o)}catch{return null}return null}function cr(e){if(e.length<4)return[];let t=e.readUInt32LE(e.length-4),r=t*4+4;if(t<1||r>e.length)return[];let o=e.length-r,n=[],s=0,i=Buffer.alloc(0);for(;s<o;){let c=q(e,s);if(!c)break;s=c.nextOffset;let a=q(e,s);if(!a)break;s=a.nextOffset;let f=q(e,s);if(!f||(s=f.nextOffset,c.value>i.length||s+a.value+f.value>o))break;let l=Buffer.concat([i.subarray(0,c.value),e.subarray(s,s+a.value)]);s+=a.value;let p=Buffer.from(e.subarray(s,s+f.value));s+=f.value,n.push({key:l,value:p}),i=l}return n}function ke(e,t){let r=lr(e,t);if(!r)return null;let o=lr(e,r.nextOffset);return!o||r.value>BigInt(Number.MAX_SAFE_INTEGER)||o.value>BigInt(Number.MAX_SAFE_INTEGER)?null:{offset:Number(r.value),size:Number(o.value),bytesRead:o.nextOffset-t}}function fr(e,t){let r=q(e,t);if(!r)return null;let o=r.nextOffset+r.value;return o>e.length?null:{value:Buffer.from(e.subarray(r.nextOffset,o)),nextOffset:o}}function lr(e,t){let r=0n,o=0n;for(let n=t;n<e.length&&n<t+10;n++){let s=e[n];if(r|=BigInt(s&127)<<o,(s&128)===0)return{value:r,nextOffset:n+1};o+=7n}return null}function Xt(e,t){let r=0n;for(let o=0;o<8;o++)r|=BigInt(e[t+o]||0)<<BigInt(o*8);return r}function Qt(e){let t=0n;for(let r=1;r<8;r++)t|=BigInt(e[r]||0)<<BigInt((r-1)*8);return t}function*gr(e){let t=mr(e,"LocalStorage");if(T(t)){let r=B(t,`SELECT maps.storage_key, map_entries.key,
27
+ FROM cookies`,P=[],$=[];if(i)P.push("host_key LIKE ?"),$.push(`%${i}%`);else if(m){let x=Gt(m.hostname),J=x.map(()=>"?").join(", ");P.push(`host_key IN (${J})`),$.push(...x)}P.length>0&&(C+=` WHERE ${P.join(" AND ")}`),C+=" ORDER BY host_key, name",d&&!s&&(C+=` LIMIT ${d}`);let _r=v(A,C,$);for(let x of _r){if(m&&(!Vt(m.hostname,x.host_key||"")||!qt(m.pathname||"/",x.path||"/")||x.is_secure&&m.protocol!=="https:"))continue;let J=x.value||"";!J&&x.encrypted_value?.length>0&&c&&(J=Ht(ue(x.encrypted_value),x.host_key||"")),g.push({profile:E.name,domain:x.host_key||"",name:x.name||"",value:J,path:x.path||"/",expires:B(x.expires_utc||0),secure:!!x.is_secure,httpOnly:!!x.is_httponly,sameSite:["unspecified","lax","strict","none"][x.samesite]||"unspecified",created:B(x.creation_utc||0),lastAccessed:B(x.last_access_utc||0)})}}catch(C){S(n,E.name,"Cookies",C),y??=new Error(`Could not read cookies for profile "${E.name}" at ${A}: `+(C instanceof Error?C.message:String(C)))}}if(!n&&g.length===0&&y)throw y;return R(g,a)}import{join as gr}from"node:path";import{zstdDecompressSync as no}from"node:zlib";function z(e,t){let r=0,o=0;for(let n=t;n<e.length&&n<t+5;n++){let i=e[n];if(r|=(i&127)<<o,(i&128)===0)return{value:r>>>0,nextOffset:n+1};o+=7}return null}var Ae=64*1024*1024;function fe(e){let t=z(e,0);if(!t||t.value>Ae)throw new Error("Invalid Snappy length");let r=Buffer.alloc(t.value),o=t.nextOffset,n=0;for(;o<e.length&&n<r.length;){let i=e[o++],s=i&3;if(s===0){let f=i>>2;if(f<60)f+=1;else{let l=f-59;if(o+l>e.length)throw new Error("Invalid Snappy literal");f=1;for(let p=0;p<l;p++)f+=e[o++]<<p*8}if(o+f>e.length||n+f>r.length)throw new Error("Invalid Snappy literal length");e.copy(r,n,o,o+f),o+=f,n+=f;continue}let c,a;if(s===1){if(o>=e.length)throw new Error("Invalid Snappy copy");c=(i>>2&7)+4,a=(i&224)<<3|e[o++]}else if(s===2){if(o+2>e.length)throw new Error("Invalid Snappy copy");c=(i>>2)+1,a=e.readUInt16LE(o),o+=2}else{if(o+4>e.length)throw new Error("Invalid Snappy copy");c=(i>>2)+1,a=e.readUInt32LE(o),o+=4}if(a<=0||a>n||n+c>r.length)throw new Error("Invalid Snappy offset");for(let f=0;f<c;f++)r[n]=r[n-a],n++}if(n!==r.length)throw new Error("Truncated Snappy stream");return r}import{copyFileSync as Yt,readFileSync as nr,readdirSync as Jt,rmSync as Xt}from"node:fs";import{join as Y}from"node:path";function Te(e){return Jt(e).filter(t=>/\.(log|ldb|sst)$/i.test(t)).sort()}function pr(e,t){let r=se(t,"chrome-local-storage-");try{let o=Te(e),n=o.map(s=>T(Y(e,s)));try{for(let s of o)Yt(Y(e,s),Y(r,s))}catch(s){throw new h("snapshot_unavailable","Could not copy Local Storage. Close the browser and retry if it is open.",{cause:s})}let i=Te(e);if(i.length!==o.length||o.some((s,c)=>s!==i[c]||!ie(n[c],T(Y(e,s)))))throw new h("snapshot_unavailable","Local Storage changed during the copy. Close the browser and retry.");return Zt(r).values()}finally{Xt(r,{recursive:!0,force:!0,maxRetries:3})}}var Qt=0xdb4775248b80fb57n,ir=32768,dr=0,mr=1;function Zt(e){let t=new Map,r=Te(e);for(let o of r){let n=Y(e,o),i=nr(n);if(/\.(ldb|sst)$/i.test(o))for(let s of ro(i))sr(t,s)}for(let o of r){if(!/\.log$/i.test(o))continue;let n=Y(e,o),i=nr(n);for(let s of eo(i))sr(t,s)}return t}function sr(e,t){let r=t.key.toString("hex"),o=e.get(r);o&&o.sequence>t.sequence||e.set(r,t)}function eo(e){let t=[],r=0,o=[];for(;r+7<=e.length;){let n=ir-r%ir;if(n<7){r+=n;continue}let i=e.readUInt16LE(r+4),s=e[r+6];if(r+=7,s===0&&i===0){r+=i;continue}if(i>e.length-r||i>n-7)break;let c=e.subarray(r,r+i);r+=i,s===1?(t.push(...ar(c)),o=[]):s===2?o=[Buffer.from(c)]:s===3&&o.length>0?o.push(Buffer.from(c)):s===4&&o.length>0&&(o.push(Buffer.from(c)),t.push(...ar(Buffer.concat(o))),o=[])}return t}function ar(e){if(e.length<12)return[];let t=[],r=to(e,0),o=e.readUInt32LE(8),n=12,i=0;for(;n<e.length&&i<o;){let s=e[n++],c=lr(e,n);if(!c)break;n=c.nextOffset;let a=r+BigInt(i);if(s===mr){let f=lr(e,n);if(!f)break;n=f.nextOffset,t.push({key:c.value,value:f.value,sequence:a,deleted:!1})}else if(s===dr)t.push({key:c.value,sequence:a,deleted:!0});else break;i++}return t}function ro(e){let t=[];if(e.length<48||e.readBigUInt64LE(e.length-8)!==Qt)return t;let o=e.subarray(e.length-48,e.length-8),n=Le(o,0);if(!n)return t;let i=Le(o,n.bytesRead);if(!i)return t;let s=cr(e,i);if(!s)return t;for(let c of fr(s)){let a=Le(c.value,0);if(!a)continue;let f=cr(e,a);if(f)for(let l of fr(f)){if(l.key.length<8)continue;let p=l.key,u=p.length-8,g=p[u],m=oo(p.subarray(u)),d=p.subarray(0,u);g===mr?t.push({key:d,value:l.value,sequence:m,deleted:!1}):g===dr&&t.push({key:d,sequence:m,deleted:!0})}}return t}function cr(e,t){let r=t.offset+t.size;if(t.offset<0||t.size<0||r+5>e.length)return null;let o=e.subarray(t.offset,r),n=e[r];if(n===0)return o;if(n===1)try{return fe(o)}catch{return null}return null}function fr(e){if(e.length<4)return[];let t=e.readUInt32LE(e.length-4),r=t*4+4;if(t<1||r>e.length)return[];let o=e.length-r,n=[],i=0,s=Buffer.alloc(0);for(;i<o;){let c=z(e,i);if(!c)break;i=c.nextOffset;let a=z(e,i);if(!a)break;i=a.nextOffset;let f=z(e,i);if(!f||(i=f.nextOffset,c.value>s.length||i+a.value+f.value>o))break;let l=Buffer.concat([s.subarray(0,c.value),e.subarray(i,i+a.value)]);i+=a.value;let p=Buffer.from(e.subarray(i,i+f.value));i+=f.value,n.push({key:l,value:p}),s=l}return n}function Le(e,t){let r=ur(e,t);if(!r)return null;let o=ur(e,r.nextOffset);return!o||r.value>BigInt(Number.MAX_SAFE_INTEGER)||o.value>BigInt(Number.MAX_SAFE_INTEGER)?null:{offset:Number(r.value),size:Number(o.value),bytesRead:o.nextOffset-t}}function lr(e,t){let r=z(e,t);if(!r)return null;let o=r.nextOffset+r.value;return o>e.length?null:{value:Buffer.from(e.subarray(r.nextOffset,o)),nextOffset:o}}function ur(e,t){let r=0n,o=0n;for(let n=t;n<e.length&&n<t+10;n++){let i=e[n];if(r|=BigInt(i&127)<<o,(i&128)===0)return{value:r,nextOffset:n+1};o+=7n}return null}function to(e,t){let r=0n;for(let o=0;o<8;o++)r|=BigInt(e[t+o]||0)<<BigInt(o*8);return r}function oo(e){let t=0n;for(let r=1;r<8;r++)t|=BigInt(e[r]||0)<<BigInt((r-1)*8);return t}function*yr(e){let t=gr(e,"LocalStorage");if(T(t)){let r=v(t,`SELECT maps.storage_key, map_entries.key,
27
28
  map_entries.value, map_entries.value_compression_type
28
- FROM map_entries JOIN maps ON maps.row_id = map_entries.map_id`);for(let o of r){if(!Buffer.isBuffer(o.storage_key)||!Buffer.isBuffer(o.key)||!Buffer.isBuffer(o.value))throw new h("unsupported_schema","Unexpected LocalStorage record encoding.");let n=o.storage_key.toString("utf8");yield{origin:n.includes("^")||n==="file:///"?n:n.replace(/\/$/,""),key:fe(o.key),value:fe(eo(o.value,o.value_compression_type))}}return}for(let r of ur(mr(e,"Local Storage","leveldb"),e)){if(r.deleted||!r.value)continue;let o=ro(r.key,r.value);o&&(yield o)}}function eo(e,t){switch(t){case 0:return e;case 1:return Zt(e,{maxOutputLength:Re});case 2:return ce(e);default:throw new h("unsupported_schema","Unknown LocalStorage value compression type.")}}function ro(e,t){if(e.length<3||e[0]!==95)return null;let r=e.indexOf(0,1);if(r===-1)return null;let o=e.subarray(1,r).toString("utf8"),n=fe(e.subarray(r+1)),s=fe(t);return o?{origin:o,key:n,value:s}:null}function fe(e){if(e.length===0)return"";let t=e[0],r=e.subarray(1);return t===0&&r.length%2===0?r.toString("utf16le"):t===1?r.toString("latin1"):e.toString("utf8")}function to({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,origin:s,url:i,key:c,search:a,limit:f=100}={}){let l=S({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),p=[],u=oo(i||s),g=c?.toLowerCase(),m=a?.toLowerCase();for(let d of l)try{for(let y of gr(d.path)){let _={profile:d.name,...y};u&&!_.origin.toLowerCase().includes(u)||g&&!_.key.toLowerCase().includes(g)||m&&!`${_.origin}
29
- ${_.key}
30
- ${_.value}`.toLowerCase().includes(m)||p.push(_)}}catch(y){w(n,d.name,"Local Storage",y)}return p.sort((d,y)=>d.profile.localeCompare(y.profile)||d.origin.localeCompare(y.origin)||d.key.localeCompare(y.key)),R(p,f)}function oo(e){if(e)try{return new URL(e).origin.toLowerCase()}catch{return e.toLowerCase()}}var D={firstName:3,middleName:4,lastName:5,fullName:7,email:9,phone:14,line1:30,line2:31,city:33,state:34,zipcode:35,countryCode:36,companyName:60,streetAddress:77},yr=["guid","use_count","use_date","date_modified"],hr=["guid","type","value"];function I(e,t,r){let o=new Set(e("SELECT name FROM pragma_table_info(?)",[t]).map(n=>n.name));return r.every(n=>o.has(n))}function Sr(e){return E(e?BigInt(e)*1000000n+11644473600000000n:0)}function wr(e,t,r,o){let n=new Map;for(let s of e("SELECT guid, type, value FROM "+o)){let i=n.get(s.guid);i||(i=new Map,n.set(s.guid,i)),i.set(s.type,s.value)}return e("SELECT guid, use_count, use_date, date_modified FROM "+r).map(s=>{let i=c=>n.get(s.guid)?.get(c)||"";return{useDate:s.use_date,entry:{profile:t,guid:s.guid,fullName:i(D.fullName)||[D.firstName,D.middleName,D.lastName].map(i).filter(Boolean).join(" "),email:i(D.email),phone:i(D.phone),companyName:i(D.companyName),streetAddress:i(D.streetAddress)||[D.line1,D.line2].map(i).filter(Boolean).join(`
31
- `),city:i(D.city),state:i(D.state),zipcode:i(D.zipcode),countryCode:i(D.countryCode),origin:"",useCount:s.use_count||0,dateModified:Sr(s.date_modified)}}})}function no(e,t){let r=I(e,"autofill_profile_names",["guid","first_name","middle_name","last_name","full_name"])?e("SELECT guid, first_name, middle_name, last_name, full_name FROM autofill_profile_names"):[],o=I(e,"autofill_profile_emails",["guid","email"])?e("SELECT guid, email FROM autofill_profile_emails"):[],n=I(e,"autofill_profile_phones",["guid","number"])?e("SELECT guid, number FROM autofill_profile_phones"):[],s=new Map(r.map(a=>[a.guid,a.full_name||[a.first_name,a.middle_name,a.last_name].filter(Boolean).join(" ")])),i=new Map(o.map(a=>[a.guid,a.email])),c=new Map(n.map(a=>[a.guid,a.number]));return e("SELECT * FROM autofill_profiles ORDER BY use_date DESC").map(a=>({profile:t,guid:a.guid||"",fullName:s.get(a.guid)||"",email:i.get(a.guid)||"",phone:c.get(a.guid)||"",companyName:a.company_name||"",streetAddress:a.street_address||"",city:a.city||"",state:a.state||"",zipcode:a.zipcode||"",countryCode:a.country_code||"",origin:a.origin||"",useCount:a.use_count||0,dateModified:Sr(a.date_modified)}))}function _r(e,t){return Ce(e,r=>{if(I(r,"addresses",yr)&&I(r,"address_type_tokens",hr))return wr(r,t,"addresses","address_type_tokens").sort((s,i)=>i.useDate-s.useDate).map(({entry:s})=>s);let n=[["local_addresses","local_addresses_type_tokens"],["contact_info","contact_info_type_tokens"]].filter(([s,i])=>I(r,s,yr)&&I(r,i,hr));if(n.length)return n.flatMap(([s,i])=>wr(r,t,s,i)).sort((s,i)=>i.useDate-s.useDate).map(({entry:s})=>s);if(I(r,"autofill_profiles",["guid","use_date"]))return no(r,t);throw new h("unsupported_schema","Unrecognized saved-address schema in Web Data.")})}import{join as Oe}from"node:path";function so({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,search:s,limit:i=100}={}){let c=S({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),a=[],f=L(i);for(let l of c){let p=Oe(l.path,"Web Data");try{let u="SELECT name, value, date_created, date_last_used, count FROM autofill",g=[];if(s){u+=" WHERE IFNULL(name, '') LIKE ? ESCAPE '\\' OR IFNULL(value, '') LIKE ? ESCAPE '\\'";let d=z(s);g.push(d,d)}u+=" ORDER BY date_last_used DESC",f&&(u+=` LIMIT ${f}`);let m=B(p,u,g);for(let d of m)a.push({profile:l.name,name:d.name||"",value:d.value||"",dateCreated:E(d.date_created?BigInt(d.date_created)*1000000n+11644473600000000n:0),dateLastUsed:E(d.date_last_used?BigInt(d.date_last_used)*1000000n+11644473600000000n:0),count:d.count||0})}catch(u){w(n,l.name,"Web Data",u)}}return R(a,i)}function io({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,decryptionKey:s}={}){let i=t||e,c=o??v().id,a=S({chromeDir:e,profilePath:t,profile:r,browser:c,onDiagnostic:n}),f=[];for(let l of a){let p=Oe(l.path,"Web Data"),u=j(i??l.path,c,s,n,l.name,"Web Data");try{let g=B(p,`SELECT guid, name_on_card, expiration_month, expiration_year,
29
+ FROM map_entries JOIN maps ON maps.row_id = map_entries.map_id`);for(let o of r){if(!Buffer.isBuffer(o.storage_key)||!Buffer.isBuffer(o.key)||!Buffer.isBuffer(o.value))throw new h("unsupported_schema","Unexpected LocalStorage record encoding.");let n=o.storage_key.toString("utf8");yield{origin:n.includes("^")||n==="file:///"?n:n.replace(/\/$/,""),key:le(o.key),value:le(io(o.value,o.value_compression_type))}}return}for(let r of pr(gr(e,"Local Storage","leveldb"),e)){if(r.deleted||!r.value)continue;let o=so(r.key,r.value);o&&(yield o)}}function io(e,t){switch(t){case 0:return e;case 1:return no(e,{maxOutputLength:Ae});case 2:return fe(e);default:throw new h("unsupported_schema","Unknown LocalStorage value compression type.")}}function so(e,t){if(e.length<3||e[0]!==95)return null;let r=e.indexOf(0,1);if(r===-1)return null;let o=e.subarray(1,r).toString("utf8"),n=le(e.subarray(r+1)),i=le(t);return o?{origin:o,key:n,value:i}:null}function le(e){if(e.length===0)return"";let t=e[0],r=e.subarray(1);return t===0&&r.length%2===0?r.toString("utf16le"):t===1?r.toString("latin1"):e.toString("utf8")}function ao({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,origin:i,url:s,key:c,search:a,limit:f=100}={}){let l=w({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),p=[],u=co(s||i),g=c?.toLowerCase(),m=a?.toLowerCase();for(let d of l)try{for(let y of yr(d.path)){let E={profile:d.name,...y};u&&!E.origin.toLowerCase().includes(u)||g&&!E.key.toLowerCase().includes(g)||m&&!`${E.origin}
30
+ ${E.key}
31
+ ${E.value}`.toLowerCase().includes(m)||p.push(E)}}catch(y){S(n,d.name,"Local Storage",y)}return p.sort((d,y)=>d.profile.localeCompare(y.profile)||d.origin.localeCompare(y.origin)||d.key.localeCompare(y.key)),R(p,f)}function co(e){if(e)try{return new URL(e).origin.toLowerCase()}catch{return e.toLowerCase()}}var D={firstName:3,middleName:4,lastName:5,fullName:7,email:9,phone:14,line1:30,line2:31,city:33,state:34,zipcode:35,countryCode:36,companyName:60,streetAddress:77},hr=["guid","use_count","use_date","date_modified"],Sr=["guid","type","value"];function I(e,t,r){let o=new Set(e("SELECT name FROM pragma_table_info(?)",[t]).map(n=>n.name));return r.every(n=>o.has(n))}function Er(e){return B(e?BigInt(e)*1000000n+11644473600000000n:0)}function wr(e,t,r,o){let n=new Map;for(let i of e("SELECT guid, type, value FROM "+o)){let s=n.get(i.guid);s||(s=new Map,n.set(i.guid,s)),s.set(i.type,i.value)}return e("SELECT guid, use_count, use_date, date_modified FROM "+r).map(i=>{let s=c=>n.get(i.guid)?.get(c)||"";return{useDate:i.use_date,entry:{profile:t,guid:i.guid,fullName:s(D.fullName)||[D.firstName,D.middleName,D.lastName].map(s).filter(Boolean).join(" "),email:s(D.email),phone:s(D.phone),companyName:s(D.companyName),streetAddress:s(D.streetAddress)||[D.line1,D.line2].map(s).filter(Boolean).join(`
32
+ `),city:s(D.city),state:s(D.state),zipcode:s(D.zipcode),countryCode:s(D.countryCode),origin:"",useCount:i.use_count||0,dateModified:Er(i.date_modified)}}})}function fo(e,t){let r=I(e,"autofill_profile_names",["guid","first_name","middle_name","last_name","full_name"])?e("SELECT guid, first_name, middle_name, last_name, full_name FROM autofill_profile_names"):[],o=I(e,"autofill_profile_emails",["guid","email"])?e("SELECT guid, email FROM autofill_profile_emails"):[],n=I(e,"autofill_profile_phones",["guid","number"])?e("SELECT guid, number FROM autofill_profile_phones"):[],i=new Map(r.map(a=>[a.guid,a.full_name||[a.first_name,a.middle_name,a.last_name].filter(Boolean).join(" ")])),s=new Map(o.map(a=>[a.guid,a.email])),c=new Map(n.map(a=>[a.guid,a.number]));return e("SELECT * FROM autofill_profiles ORDER BY use_date DESC").map(a=>({profile:t,guid:a.guid||"",fullName:i.get(a.guid)||"",email:s.get(a.guid)||"",phone:c.get(a.guid)||"",companyName:a.company_name||"",streetAddress:a.street_address||"",city:a.city||"",state:a.state||"",zipcode:a.zipcode||"",countryCode:a.country_code||"",origin:a.origin||"",useCount:a.use_count||0,dateModified:Er(a.date_modified)}))}function Br(e,t){return Oe(e,r=>{if(I(r,"addresses",hr)&&I(r,"address_type_tokens",Sr))return wr(r,t,"addresses","address_type_tokens").sort((i,s)=>s.useDate-i.useDate).map(({entry:i})=>i);let n=[["local_addresses","local_addresses_type_tokens"],["contact_info","contact_info_type_tokens"]].filter(([i,s])=>I(r,i,hr)&&I(r,s,Sr));if(n.length)return n.flatMap(([i,s])=>wr(r,t,i,s)).sort((i,s)=>s.useDate-i.useDate).map(({entry:i})=>i);if(I(r,"autofill_profiles",["guid","use_date"]))return fo(r,t);throw new h("unsupported_schema","Unrecognized saved-address schema in Web Data.")})}import{join as Ie}from"node:path";function lo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,search:i,limit:s=100}={}){let c=w({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),a=[],f=O(s);for(let l of c){let p=Ie(l.path,"Web Data");try{let u="SELECT name, value, date_created, date_last_used, count FROM autofill",g=[];if(i){u+=" WHERE IFNULL(name, '') LIKE ? ESCAPE '\\' OR IFNULL(value, '') LIKE ? ESCAPE '\\'";let d=q(i);g.push(d,d)}u+=" ORDER BY date_last_used DESC",f&&(u+=` LIMIT ${f}`);let m=v(p,u,g);for(let d of m)a.push({profile:l.name,name:d.name||"",value:d.value||"",dateCreated:B(d.date_created?BigInt(d.date_created)*1000000n+11644473600000000n:0),dateLastUsed:B(d.date_last_used?BigInt(d.date_last_used)*1000000n+11644473600000000n:0),count:d.count||0})}catch(u){S(n,l.name,"Web Data",u)}}return R(a,s)}function uo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,decryptionKey:i}={}){let s=t||e,c=o??_().id,a=w({chromeDir:e,profilePath:t,profile:r,browser:c,onDiagnostic:n}),f=[];for(let l of a){let p=Ie(l.path,"Web Data"),u=G(s??l.path,c,i,n,l.name,"Web Data");try{let g=v(p,`SELECT guid, name_on_card, expiration_month, expiration_year,
32
33
  card_number_encrypted, date_modified, origin, use_count,
33
34
  nickname
34
- FROM credit_cards ORDER BY use_date DESC`);for(let m of g){let d="";if(m.card_number_encrypted?.length>0){let y=u(m.card_number_encrypted);d=Buffer.isBuffer(y)?y.toString("utf8"):y}f.push({profile:l.name,guid:m.guid||"",nameOnCard:m.name_on_card||"",expirationMonth:m.expiration_month||0,expirationYear:m.expiration_year||0,cardNumber:d,nickname:m.nickname||"",origin:m.origin||"",useCount:m.use_count||0,dateModified:E(m.date_modified?BigInt(m.date_modified)*1000000n+11644473600000000n:0)})}}catch(g){w(n,l.name,"Web Data",g)}}return f}function ao(e={}){let t=[];for(let r of S(e))try{for(let o of _r(Oe(r.path,"Web Data"),r.name))t.push(o)}catch(o){w(e.onDiagnostic,r.name,"Web Data",o)}return t}import{join as co}from"node:path";var fo={0:"in_progress",1:"complete",2:"cancelled",3:"interrupted"},lo={0:"not_dangerous",1:"dangerous_file",2:"dangerous_url",3:"dangerous_content",4:"maybe_dangerous_content",5:"uncommon_content",6:"user_validated",7:"dangerous_host",8:"potentially_unwanted",9:"allowlisted_by_policy"};function uo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,search:s,limit:i=100}={}){let c=S({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),a=[],f=L(i);for(let l of c){let p=co(l.path,"History");try{let u=`SELECT target_path, tab_url, total_bytes, received_bytes,
35
+ FROM credit_cards ORDER BY use_date DESC`);for(let m of g){let d="";if(m.card_number_encrypted?.length>0){let y=u(m.card_number_encrypted);d=Buffer.isBuffer(y)?y.toString("utf8"):y}f.push({profile:l.name,guid:m.guid||"",nameOnCard:m.name_on_card||"",expirationMonth:m.expiration_month||0,expirationYear:m.expiration_year||0,cardNumber:d,nickname:m.nickname||"",origin:m.origin||"",useCount:m.use_count||0,dateModified:B(m.date_modified?BigInt(m.date_modified)*1000000n+11644473600000000n:0)})}}catch(g){S(n,l.name,"Web Data",g)}}return f}function po(e={}){let t=[];for(let r of w(e))try{for(let o of Br(Ie(r.path,"Web Data"),r.name))t.push(o)}catch(o){S(e.onDiagnostic,r.name,"Web Data",o)}return t}import{join as mo}from"node:path";var go={0:"in_progress",1:"complete",2:"cancelled",3:"interrupted"},yo={0:"not_dangerous",1:"dangerous_file",2:"dangerous_url",3:"dangerous_content",4:"maybe_dangerous_content",5:"uncommon_content",6:"user_validated",7:"dangerous_host",8:"potentially_unwanted",9:"allowlisted_by_policy"};function ho({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n,search:i,limit:s=100}={}){let c=w({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),a=[],f=O(s);for(let l of c){let p=mo(l.path,"History");try{let u=`SELECT target_path, tab_url, total_bytes, received_bytes,
35
36
  start_time, end_time, mime_type, original_mime_type,
36
37
  state, danger_type, opened, referrer, site_url
37
- FROM downloads`,g=[];if(s){u+=` WHERE IFNULL(target_path, '') LIKE ? ESCAPE '\\'
38
- OR IFNULL(tab_url, '') LIKE ? ESCAPE '\\'`;let d=z(s);g.push(d,d)}u+=" ORDER BY start_time DESC",f&&(u+=` LIMIT ${f}`);let m=B(p,u,g);for(let d of m)a.push({profile:l.name,targetPath:d.target_path||"",url:d.tab_url||"",siteUrl:d.site_url||"",referrer:d.referrer||"",totalBytes:d.total_bytes||0,receivedBytes:d.received_bytes||0,mimeType:d.mime_type||d.original_mime_type||"",state:fo[d.state]||`unknown(${d.state})`,dangerType:lo[d.danger_type]||`unknown(${d.danger_type})`,opened:!!d.opened,startTime:E(d.start_time||0),endTime:E(d.end_time||0)})}catch(u){w(n,l.name,"History",u)}}return R(a,i)}import{existsSync as po,readFileSync as mo}from"node:fs";import{join as go}from"node:path";function yo({chromeDir:e,profilePath:t,profile:r,search:o,browser:n,onDiagnostic:s}={}){let i=S({chromeDir:e,profilePath:t,profile:r,browser:n,onDiagnostic:s}),c=[];for(let a of i){let f=null;for(let l of["Secure Preferences","Preferences"]){let p=go(a.path,l);if(po(p))try{let g=JSON.parse(mo(p,"utf-8"))?.extensions?.settings;if(g&&typeof g=="object"){f=g;break}}catch(u){w(s,a.name,l,u instanceof SyntaxError?new Error("Invalid preferences JSON."):u)}}if(f)for(let[l,p]of Object.entries(f)){let u=p;if(u.location===5||u.location===10)continue;let g=u.manifest||{},m={profile:a.name,id:l,name:g.name||u.name||l,version:g.version||u.version||"unknown",description:g.description||"",enabled:u.state===1,homepageUrl:g.homepage_url||"",updateUrl:g.update_url||"",installTime:u.install_time||"",fromWebstore:u.from_webstore||!1,location:u.location||0};if(m.name.startsWith("__MSG_")&&(m.name=l),m.description.startsWith("__MSG_")&&(m.description=""),o){let d=o.toLowerCase();if(!(m.name&&m.name.toLowerCase().includes(d))&&!(m.id&&m.id.toLowerCase().includes(d)))continue}c.push(m)}}return c}import{join as ho}from"node:path";function wo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}={}){let s=S({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),i=[];for(let c of s){let a=ho(c.path,"Web Data");try{let f=B(a,`SELECT id, short_name, keyword, url, suggestions_url,
38
+ FROM downloads`,g=[];if(i){u+=` WHERE IFNULL(target_path, '') LIKE ? ESCAPE '\\'
39
+ OR IFNULL(tab_url, '') LIKE ? ESCAPE '\\'`;let d=q(i);g.push(d,d)}u+=" ORDER BY start_time DESC",f&&(u+=` LIMIT ${f}`);let m=v(p,u,g);for(let d of m)a.push({profile:l.name,targetPath:d.target_path||"",url:d.tab_url||"",siteUrl:d.site_url||"",referrer:d.referrer||"",totalBytes:d.total_bytes||0,receivedBytes:d.received_bytes||0,mimeType:d.mime_type||d.original_mime_type||"",state:go[d.state]||`unknown(${d.state})`,dangerType:yo[d.danger_type]||`unknown(${d.danger_type})`,opened:!!d.opened,startTime:B(d.start_time||0),endTime:B(d.end_time||0)})}catch(u){S(n,l.name,"History",u)}}return R(a,s)}import{existsSync as So,readFileSync as wo}from"node:fs";import{join as Eo}from"node:path";function Bo({chromeDir:e,profilePath:t,profile:r,search:o,browser:n,onDiagnostic:i}={}){let s=w({chromeDir:e,profilePath:t,profile:r,browser:n,onDiagnostic:i}),c=[];for(let a of s){let f=null;for(let l of["Secure Preferences","Preferences"]){let p=Eo(a.path,l);if(So(p))try{let g=JSON.parse(wo(p,"utf-8"))?.extensions?.settings;if(g&&typeof g=="object"){f=g;break}}catch(u){S(i,a.name,l,u instanceof SyntaxError?new Error("Invalid preferences JSON."):u)}}if(f)for(let[l,p]of Object.entries(f)){let u=p;if(u.location===5||u.location===10)continue;let g=u.manifest||{},m={profile:a.name,id:l,name:g.name||u.name||l,version:g.version||u.version||"unknown",description:g.description||"",enabled:u.state===1,homepageUrl:g.homepage_url||"",updateUrl:g.update_url||"",installTime:u.install_time||"",fromWebstore:u.from_webstore||!1,location:u.location||0};if(m.name.startsWith("__MSG_")&&(m.name=l),m.description.startsWith("__MSG_")&&(m.description=""),o){let d=o.toLowerCase();if(!(m.name&&m.name.toLowerCase().includes(d))&&!(m.id&&m.id.toLowerCase().includes(d)))continue}c.push(m)}}return c}import{join as _o}from"node:path";function vo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}={}){let i=w({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),s=[];for(let c of i){let a=_o(c.path,"Web Data");try{let f=v(a,`SELECT id, short_name, keyword, url, suggestions_url,
39
40
  favicon_url, prepopulate_id, is_active
40
- FROM keywords ORDER BY short_name`);for(let l of f)i.push({profile:c.name,id:l.id,name:l.short_name||"",keyword:l.keyword||"",url:l.url||"",suggestionsUrl:l.suggestions_url||"",faviconUrl:l.favicon_url||"",isDefault:l.prepopulate_id===1,isActive:l.is_active===1})}catch(f){w(n,c.name,"Web Data",f)}}return i}import{join as So}from"node:path";function _o({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}={}){let s=S({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),i=[];for(let c of s){let a=So(c.path,"Top Sites");try{let f=B(a,`SELECT url, url_rank, title, redirects
41
- FROM top_sites ORDER BY url_rank ASC`);for(let l of f)i.push({profile:c.name,url:l.url||"",title:l.title||"",rank:l.url_rank??0,redirects:l.redirects||""})}catch(f){w(n,c.name,"Top Sites",f)}}return i}export{Z as BROWSERS,E as chromeTimeToDate,rt as clearKeyCache,we as clearKeychainCache,et as decryptValue,Ve as decryptValueBuffer,Zr as deriveEncryptionKey,Rt as describePasswordStores,st as detectInstalledBrowsers,V as discoverProfiles,v as getActiveBrowser,ao as getAddresses,so as getAutofillEntries,At as getBookmarks,Or as getChromeKeychainPassword,Gt as getCookies,io as getCreditCards,F as getDefaultChromeDir,uo as getDownloads,yo as getExtensions,Tt as getHistory,he as getKeychainPassword,ye as getKeychainPasswordProvider,to as getLocalStorage,kt as getPasswords,De as getPlatformChromeDir,Ye as getProfileMetadata,it as getProfileStates,wo as getSearchEngines,It as getSearchTerms,_o as getTopSites,$ as listBrowsers,B as queryDatabase,M as requireBrowser,Se as resolveBrowser,at as resolveProfilePath,S as resolveTargetProfiles,W as selectPlatform,Ne as setActiveBrowser,Lr as setKeychainPasswordProvider,Et as tableExists};
41
+ FROM keywords ORDER BY short_name`);for(let l of f)s.push({profile:c.name,id:l.id,name:l.short_name||"",keyword:l.keyword||"",url:l.url||"",suggestionsUrl:l.suggestions_url||"",faviconUrl:l.favicon_url||"",isDefault:l.prepopulate_id===1,isActive:l.is_active===1})}catch(f){S(n,c.name,"Web Data",f)}}return s}import{join as xo}from"node:path";function bo({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}={}){let i=w({chromeDir:e,profilePath:t,profile:r,browser:o,onDiagnostic:n}),s=[];for(let c of i){let a=xo(c.path,"Top Sites");try{let f=v(a,`SELECT url, url_rank, title, redirects
42
+ FROM top_sites ORDER BY url_rank ASC`);for(let l of f)s.push({profile:c.name,url:l.url||"",title:l.title||"",rank:l.url_rank??0,redirects:l.redirects||""})}catch(f){S(n,c.name,"Top Sites",f)}}return s}export{Z as BROWSERS,B as chromeTimeToDate,st as clearKeyCache,we as clearKeychainCache,it as decryptValue,qe as decryptValueBuffer,nt as deriveEncryptionKey,Tt as describePasswordStores,lt as detectInstalledBrowsers,V as discoverProfiles,_ as getActiveBrowser,po as getAddresses,lo as getAutofillEntries,Ft as getBookmarks,Lr as getChromeKeychainPassword,zt as getCookies,uo as getCreditCards,U as getDefaultChromeDir,ho as getDownloads,Bo as getExtensions,Ut as getHistory,Se as getKeychainPassword,he as getKeychainPasswordProvider,ao as getLocalStorage,It as getPasswords,Re as getPlatformChromeDir,Je as getProfileMetadata,ut as getProfileStates,vo as getSearchEngines,Mt as getSearchTerms,bo as getTopSites,W as listBrowsers,v as queryDatabase,N as requireBrowser,Ee as resolveBrowser,pt as resolveProfilePath,w as resolveTargetProfiles,F as selectPlatform,Ue as setActiveBrowser,Ar as setKeychainPasswordProvider,Pt as tableExists};
@@ -29,5 +29,7 @@ export declare function decryptValueBuffer(blob: Buffer | Uint8Array | null | un
29
29
  export declare function decryptValue(blob: Buffer | Uint8Array | null | undefined, key: Buffer): string;
30
30
  /** Clears the active backend's cached key material. */
31
31
  export declare function clearKeyCache(): void;
32
+ /** Returns the reason App-Bound Encryption failed for this profile/browser, if known. */
33
+ export declare function getAppBoundError(chromeDir?: string, browser?: string | BrowserDescriptor): string | undefined;
32
34
  /** Resolve keys lazily for a single store and its explicit browser profile. */
33
35
  export declare function createProfileDecryptor(chromeDir: string, browser: string | undefined, overrideKey: Buffer | undefined, report: ProfileReadReporter | undefined, profile: string, store: string): (blob: Buffer) => Buffer | string;
@@ -36,6 +36,11 @@ export interface ChromePlatform {
36
36
  * unavailable or unsupported on this platform.
37
37
  */
38
38
  getAppBoundKey?(chromeDir?: string, browser?: BrowserDescriptor): Buffer | undefined;
39
+ /**
40
+ * Returns a human-readable explanation for why App-Bound Encryption failed
41
+ * for the given directory/browser, if known.
42
+ */
43
+ getAppBoundError?(chromeDir?: string, browser?: BrowserDescriptor): string | undefined;
39
44
  /**
40
45
  * Decrypts a single Chrome `v10`/`v11`/`v20` blob using this platform's
41
46
  * scheme (AES-128-CBC on macOS/Linux, AES-256-GCM on Windows).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-tools",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "CLI & Node.js library for chrome",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",