Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created September 27, 2017 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yasushi/dcc52f8cba45348d9037d6f8940f52e4 to your computer and use it in GitHub Desktop.
Save Yasushi/dcc52f8cba45348d9037d6f8940f52e4 to your computer and use it in GitHub Desktop.
decode chrome login data
module Main
open System
open System.Security.Cryptography
open System.Text.RegularExpressions
let fromHex (s:string) =
s
|> Seq.windowed 2
|> Seq.mapi (fun i j -> (i,j))
|> Seq.filter (fun (i,j) -> i % 2=0)
|> Seq.map (fun (_,j) -> Byte.Parse(new System.String(j),System.Globalization.NumberStyles.AllowHexSpecifier))
|> Array.ofSeq
let (|QuoteString|_|) (input: string) =
let result = Regex.Match(input, "^'(.*)'$")
if result.Success then
Some (Seq.last [for g in result.Groups -> g.Value])
else
None
let (|ProtectedString|_|) (input: string) =
let result = Regex.Match(input, "^X'([0-9A-F]{2,})'$")
if result.Success then
try
let decode =
[for g in result.Groups -> g.Value]
|> Seq.last
|> (fun (h) -> ProtectedData.Unprotect (fromHex h, null, DataProtectionScope.CurrentUser))
|> System.Text.Encoding.ASCII.GetString
Some (decode |> sprintf "'%s'")
with
| _ as ex -> None
else
None
let decode_r = function
| ProtectedString p -> p
| s -> s
let decode csvfile =
System.IO.File.ReadAllLines csvfile
|> Array.map (fun l -> l.Split(','))
|> Array.map (fun (r:string[]) -> Array.map decode_r r)
|> Array.iter (fun (i:string[]) -> i |> String.concat "," |> printfn "%s")
[<EntryPoint>]
let main (args) =
decode args.[0]
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment