Skip to content

Commit

Permalink
Fixed base64 decoding to have more failure handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed May 9, 2024
1 parent 08133f3 commit 36333b0
Showing 1 changed file with 33 additions and 35 deletions.
68 changes: 33 additions & 35 deletions shuffle-tools/1.2.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,48 +94,46 @@ def base64_conversion(self, string, operation):
return value

elif operation == "decode":
decoded_bytes = ""

# For loop this. It's stupid.
try:
decoded_bytes = base64.b64decode(string)
try:
decoded_bytes = str(decoded_bytes, "utf-8")
except:
pass
except Exception as e:
if "incorrect padding" in str(e).lower():
try:
decoded_bytes = base64.b64decode(string + "=")
except Exception as e:
if "incorrect padding" in str(e).lower():
try:
decoded_bytes = base64.b64decode(string + "==")
except Exception as e:
if "incorrect padding" in str(e).lower():
try:
decoded_bytes = base64.b64decode(string + "===")
except Exception as e:
if "incorrect padding" in str(e).lower():
return "Invalid Base64"

# Check if json
try:
decoded_bytes = json.loads(decoded_bytes)
except:
pass

return decoded_bytes
except Exception as e:
#return string.decode("utf-16")
decoded_bytes = base64.b64decode(string)
try:
decoded_bytes = str(decoded_bytes, "utf-8")
except:
pass

return {
"success": False,
"reason": f"Error decoding the base64: {e}",
}
#newvar = binascii.a2b_base64(string)
#try:
# if str(newvar).startswith("b'") and str(newvar).endswith("'"):
# newvar = newvar[2:-1]
#except Exception as e:
#return newvar

#try:
# return newvar
#except:
# pass
# Check if json
try:
decoded_bytes = json.loads(decoded_bytes)
except:
pass

return {
"success": False,
"reason": "Error decoding the base64",
}
return decoded_bytes

return json.dumps({
return {
"success": False,
"reason": "No base64 to be converted",
})
"reason": "Invalid operation",
}

def parse_list_internal(self, input_list):
if isinstance(input_list, list):
Expand Down Expand Up @@ -565,7 +563,7 @@ def check_wildcard(self, wildcardstring, matching_string):
if wildcardstring in str(matching_string).lower():
return True
else:
wildcardstring = wildcardstring.replace(".", "\.")
wildcardstring = wildcardstring.replace(".", "\\.")
wildcardstring = wildcardstring.replace("*", ".*")

if re.match(wildcardstring, str(matching_string).lower()):
Expand Down

0 comments on commit 36333b0

Please sign in to comment.