From 712fb88adc6309de7eb0bdba7e7d9f95f847bdd9 Mon Sep 17 00:00:00 2001 From: Jonn Callahan Date: Fri, 21 Jun 2024 11:11:47 +0000 Subject: [PATCH] fix chrome parsing issue --- SharpChrome/lib/Chrome.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/SharpChrome/lib/Chrome.cs b/SharpChrome/lib/Chrome.cs index dbf562a..57287e5 100644 --- a/SharpChrome/lib/Chrome.cs +++ b/SharpChrome/lib/Chrome.cs @@ -780,15 +780,26 @@ public static void ParseChromeCookies(Dictionary MasterKeys, str public static string GetBase64EncryptedKey(string localStatePath) { // extracts the base64 encoded encrypted chrome AES state key + // quote-wrap the search term in order to handle multiple + // JSON keys with "encrypted_key" (e.g., "app_bound_encrypted_key") string localStateData = File.ReadAllText(localStatePath); - string searchTerm = "encrypted_key"; - + string searchTerm = "\"encrypted_key\""; + int indexPadding = 2; int startIndex = localStateData.IndexOf(searchTerm); + // if we can't find the quote-wrapped variant, fall back to + // the original variant + if (startIndex < 0) + { + searchTerm = "encrypted_key"; + indexPadding = 3; + startIndex = localStateData.IndexOf(searchTerm); + } + if (startIndex < 0) return ""; - int keyIndex = startIndex + searchTerm.Length + 3; + int keyIndex = startIndex + searchTerm.Length + indexPadding; string tempVals = localStateData.Substring(keyIndex); int stopIndex = tempVals.IndexOf('"');