[Capture] Heuristic - Fix detection

- Remove false positives because of EOL characters
- First character would always be a digit before as we were handling the int representation of the character
pull/71/head
Camille Barneaud 2 years ago committed by GitHub
parent d319c93b5b
commit 099ddb9d7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -18,11 +18,11 @@ def mitmproxy_dump_file_huristic(file_path: str) -> int:
# read the first 2048 bytes # read the first 2048 bytes
with open(file_path, "rb") as f: with open(file_path, "rb") as f:
data = f.read(2048) data = f.read(2048)
# if file contains non-ascii characters # if file contains non-ascii characters after remove EOL characters
if data.decode("utf-8", "ignore").isprintable() is False: if data.decode("utf-8", "ignore").replace("\r", "").replace("\n", "").isprintable() is False:
val += 50 val += 50
# if first character of the byte array is a digit # if first character of the byte array is a digit
if str(data[0]).isdigit() is True: if data[0:1].decode("utf-8", "ignore").isdigit() is True:
val += 5 val += 5
# if it contains the word status_code # if it contains the word status_code
if b"status_code" in data: if b"status_code" in data:

Loading…
Cancel
Save