From 099ddb9d7d9e664094fd45f00382fac1b2c210e8 Mon Sep 17 00:00:00 2001 From: Camille Barneaud <1693643+gadcam@users.noreply.github.com> Date: Fri, 30 Jun 2023 19:59:21 +0200 Subject: [PATCH] [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 --- mitmproxy2swagger/mitmproxy_capture_reader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mitmproxy2swagger/mitmproxy_capture_reader.py b/mitmproxy2swagger/mitmproxy_capture_reader.py index e010698..fdd0b04 100644 --- a/mitmproxy2swagger/mitmproxy_capture_reader.py +++ b/mitmproxy2swagger/mitmproxy_capture_reader.py @@ -18,11 +18,11 @@ def mitmproxy_dump_file_huristic(file_path: str) -> int: # read the first 2048 bytes with open(file_path, "rb") as f: data = f.read(2048) - # if file contains non-ascii characters - if data.decode("utf-8", "ignore").isprintable() is False: + # if file contains non-ascii characters after remove EOL characters + if data.decode("utf-8", "ignore").replace("\r", "").replace("\n", "").isprintable() is False: val += 50 # 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 # if it contains the word status_code if b"status_code" in data: