-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is not enabled by default. If you wish to use it, add following snippet to popup.html. ``` <option value="Heuristic">Heuristic</option> ```
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import re | ||
def replaceRequest(payload): | ||
challengeB64 = base64.b64encode(challenge).decode() | ||
challengeArr = str(list(challenge)) | ||
|
||
# Trying decode payload, challenge might be raw bytes if it failed | ||
try: | ||
decodedPayload = payload.decode() | ||
except: | ||
return challenge | ||
|
||
# Challenge might be JSON/XML stored B64-encoded string | ||
replaced = decodedPayload.replace(r"(?<=(\"|\'|>))CAES.*?(?=(\"|\'|<))", challengeB64).replace(r"(?<=(\"|\'|>))CAQ=(?=(\"|\'|<))", challengeB64) | ||
if(decodedPayload != replaced): | ||
return replaced | ||
|
||
# Challenge might be raw B64-encoded string | ||
replaced = decodedPayload.replace(r"^CAES.*?=$", challengeB64).replace(r"^CAQ=$", challengeB64) | ||
if(decodedPayload != replaced): | ||
return replaced | ||
|
||
# Challenge might be Uint8Array | ||
replaced = decodedPayload.replace(r"\[0?8 ?, ?0?1 ?, ?[0-9 ,]*?\]", challengeArr).replace(r"\[0?8 ?, ?0?4]", challengeArr) | ||
if(decodedPayload != replaced): | ||
return replaced | ||
|
||
|
||
def findLicense(response): | ||
# Trying decode response, license might be raw bytes if it failed | ||
try: | ||
decodedResponse = response.decode() | ||
except: | ||
return response | ||
|
||
# License might be JSON/XML stored B64-encoded string | ||
try: | ||
return re.search(r"(?<=(\"|\'|>))CAIS.*?(?=(\"|\'|<))", decodedResponse).group() | ||
except: | ||
pass | ||
|
||
# License might be raw B64-encoded string | ||
try: | ||
return re.search(r"^CAIS.*?=$", decodedResponse).group() | ||
except: | ||
pass | ||
|
||
# License might be Uint8Array | ||
try: | ||
foundStr = re.search(r"\[0?8 ?, ?0?2 ?, ?[0-9 ,]*?\]", decodedResponse).group() | ||
return bytes(json.loads(foundStr)) | ||
except: | ||
pass | ||
|
||
|
||
payload = loadBody("blob") | ||
payload = replaceRequest(payload) | ||
|
||
response = await corsFetch(licUrl, "POST", licHeaders, payload, "blob") | ||
licence = findLicense(response) |