Skip to content

Commit

Permalink
[BETA] Add heuristic scheme
Browse files Browse the repository at this point in the history
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
FoxRefire committed Aug 25, 2024
1 parent 51d9503 commit 9476dbe
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions python/schemes/Heuristic.py
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)

0 comments on commit 9476dbe

Please sign in to comment.