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 1/2] [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: From 93a7356fc80baabf94ffca18333766fbf272f78f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 30 Jun 2023 17:59:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mitmproxy2swagger/mitmproxy_capture_reader.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mitmproxy2swagger/mitmproxy_capture_reader.py b/mitmproxy2swagger/mitmproxy_capture_reader.py index fdd0b04..576d32e 100644 --- a/mitmproxy2swagger/mitmproxy_capture_reader.py +++ b/mitmproxy2swagger/mitmproxy_capture_reader.py @@ -19,7 +19,13 @@ def mitmproxy_dump_file_huristic(file_path: str) -> int: with open(file_path, "rb") as f: data = f.read(2048) # if file contains non-ascii characters after remove EOL characters - if data.decode("utf-8", "ignore").replace("\r", "").replace("\n", "").isprintable() is False: + 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 data[0:1].decode("utf-8", "ignore").isdigit() is True: