binarycookies 2.2.0__tar.gz → 2.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.1
2
2
  Name: binarycookies
3
- Version: 2.2.0
3
+ Version: 2.2.3
4
4
  Summary: Python Binary Cookies (de)serializer
5
5
  Author: Daniel Tom
6
6
  Author-email: d.e.tom89@gmail.com
@@ -10,10 +10,8 @@ Classifier: Programming Language :: Python :: 3.8
10
10
  Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
- Classifier: Programming Language :: Python :: 3.12
14
- Classifier: Programming Language :: Python :: 3.13
15
13
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
16
- Requires-Dist: typer (>=0.12.3,<0.17.0)
14
+ Requires-Dist: typer (>=0.12.3,<0.20.0)
17
15
  Description-Content-Type: text/markdown
18
16
 
19
17
  [![Github Actions Status](https://github.com/dan1elt0m/binary-cookies-reader/workflows/test/badge.svg)](https://github.com/dan1elt0m/binary-cookies-reader/actions/workflows/test.yml)
@@ -24,6 +22,9 @@ Description-Content-Type: text/markdown
24
22
 
25
23
  CLI tool and Python library for reading and writing Binary Cookies.
26
24
 
25
+ ### Documentation
26
+ For detailed documentation, please visit the [Binary Cookies Documentation](https://dan1elt0m.github.io/binarycookies/)
27
+
27
28
  ### Requirements
28
29
 
29
30
  - Python >= 3.9
@@ -61,49 +62,11 @@ Output:
61
62
  }
62
63
  ]
63
64
  ```
64
-
65
-
66
- ### ASCII Output
67
-
68
- `ascii` output is also possible with the --output ascii flag.
69
-
70
- Example usage:
71
- ```sh
72
- bcparser path/to/cookies.binarycookies --output ascii
73
- ```
74
-
75
- Example output ASCII:
76
- ```text
77
- Name: session_id
78
- Value: abc123
79
- URL: https://example.com
80
- Path: /
81
- Created: 2023-10-01T12:34:56+00:00
82
- Expires: 2023-12-31T23:59:59+00:00
83
- Flag: Secure
84
- ----------------------------------------
85
- Name: user_token
86
- Value: xyz789
87
- URL: https://example.com
88
- Path: /account
89
- Created: 2023-10-01T12:34:56+00:00
90
- Expires: 2023-12-31T23:59:59+00:00
91
- Flag: HttpOnly
92
- ----------------------------------------
93
- ```
94
- ### Netscape Output
95
- For `netscape` output use the --output netscape flag.
96
- Example usage:
97
- ```sh
98
- bcparser path/to/cookies.binarycookies --output netscape
99
- ```
100
-
101
- Example output Netscape:
102
- ```netscape
103
- # Netscape HTTP Cookie File
104
- example.com FALSE / TRUE 1704067199 session_id abc123
105
- example.com FALSE /account FALSE 1704067199 user_token xyz789
106
- ```
65
+ #### Output formats
66
+ The CLI supports multiple output formats using the --output flag.
67
+ - `json` (default): Outputs cookies in JSON format.
68
+ - `ascii`: Outputs cookies in a human-readable ASCII format with each cookie property on a separate line.
69
+ - `netscape`: Outputs cookies in the Netscape cookie file format.
107
70
 
108
71
  ### Basic Usage Python
109
72
 
@@ -135,6 +98,18 @@ with open("path/to/cookies.binarycookies", "wb") as f:
135
98
  binarycookies.dump(cookie, f)
136
99
  ```
137
100
 
101
+ ### Ethical Use & Responsible Handling
102
+ This project is intended for lawful, ethical use only. Typical, appropriate uses include:
103
+ - Inspecting Binary Cookies from your own devices or data you are authorized to access
104
+ - DFIR, QA, and security testing performed with explicit, written permission
105
+ - Educational/research work on datasets that are owned by you, anonymized, or publicly released for that purpose
106
+
107
+ You must not use this tool to:
108
+ - Access, extract, modify, or distribute cookies from systems or accounts you do not own or have permission to analyze
109
+ - Bypass authentication, session management, DRM, or other technical controls
110
+ - Enable tracking, stalking, doxxing, fraud, or other privacy-invasive or harmful activities
111
+
112
+
138
113
  ### License
139
114
  This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
140
115
 
@@ -6,6 +6,9 @@
6
6
 
7
7
  CLI tool and Python library for reading and writing Binary Cookies.
8
8
 
9
+ ### Documentation
10
+ For detailed documentation, please visit the [Binary Cookies Documentation](https://dan1elt0m.github.io/binarycookies/)
11
+
9
12
  ### Requirements
10
13
 
11
14
  - Python >= 3.9
@@ -43,49 +46,11 @@ Output:
43
46
  }
44
47
  ]
45
48
  ```
46
-
47
-
48
- ### ASCII Output
49
-
50
- `ascii` output is also possible with the --output ascii flag.
51
-
52
- Example usage:
53
- ```sh
54
- bcparser path/to/cookies.binarycookies --output ascii
55
- ```
56
-
57
- Example output ASCII:
58
- ```text
59
- Name: session_id
60
- Value: abc123
61
- URL: https://example.com
62
- Path: /
63
- Created: 2023-10-01T12:34:56+00:00
64
- Expires: 2023-12-31T23:59:59+00:00
65
- Flag: Secure
66
- ----------------------------------------
67
- Name: user_token
68
- Value: xyz789
69
- URL: https://example.com
70
- Path: /account
71
- Created: 2023-10-01T12:34:56+00:00
72
- Expires: 2023-12-31T23:59:59+00:00
73
- Flag: HttpOnly
74
- ----------------------------------------
75
- ```
76
- ### Netscape Output
77
- For `netscape` output use the --output netscape flag.
78
- Example usage:
79
- ```sh
80
- bcparser path/to/cookies.binarycookies --output netscape
81
- ```
82
-
83
- Example output Netscape:
84
- ```netscape
85
- # Netscape HTTP Cookie File
86
- example.com FALSE / TRUE 1704067199 session_id abc123
87
- example.com FALSE /account FALSE 1704067199 user_token xyz789
88
- ```
49
+ #### Output formats
50
+ The CLI supports multiple output formats using the --output flag.
51
+ - `json` (default): Outputs cookies in JSON format.
52
+ - `ascii`: Outputs cookies in a human-readable ASCII format with each cookie property on a separate line.
53
+ - `netscape`: Outputs cookies in the Netscape cookie file format.
89
54
 
90
55
  ### Basic Usage Python
91
56
 
@@ -117,6 +82,18 @@ with open("path/to/cookies.binarycookies", "wb") as f:
117
82
  binarycookies.dump(cookie, f)
118
83
  ```
119
84
 
85
+ ### Ethical Use & Responsible Handling
86
+ This project is intended for lawful, ethical use only. Typical, appropriate uses include:
87
+ - Inspecting Binary Cookies from your own devices or data you are authorized to access
88
+ - DFIR, QA, and security testing performed with explicit, written permission
89
+ - Educational/research work on datasets that are owned by you, anonymized, or publicly released for that purpose
90
+
91
+ You must not use this tool to:
92
+ - Access, extract, modify, or distribute cookies from systems or accounts you do not own or have permission to analyze
93
+ - Bypass authentication, session management, DRM, or other technical controls
94
+ - Enable tracking, stalking, doxxing, fraud, or other privacy-invasive or harmful activities
95
+
96
+
120
97
  ### License
121
98
  This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
122
99
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "binarycookies"
3
- version = "2.2.0"
3
+ version = "2.2.3"
4
4
  description = "Python Binary Cookies (de)serializer"
5
5
  authors = ["Daniel Tom <d.e.tom89@gmail.com>"]
6
6
  readme = "README.md"
@@ -8,7 +8,7 @@ packages = [{include = "binarycookies", from="src"}]
8
8
 
9
9
  [tool.poetry.dependencies]
10
10
  python = ">=3.8,<4.0"
11
- typer = ">=0.12.3,<0.17.0"
11
+ typer = ">=0.12.3,<0.20.0"
12
12
  pydantic = ">=2.0.0,<3.0.0"
13
13
 
14
14
  [tool.poetry.group.dev.dependencies]
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ package_dir = \
5
+ {'': 'src'}
6
+
7
+ packages = \
8
+ ['binarycookies']
9
+
10
+ package_data = \
11
+ {'': ['*']}
12
+
13
+ install_requires = \
14
+ ['pydantic>=2.0.0,<3.0.0', 'typer>=0.12.3,<0.20.0']
15
+
16
+ entry_points = \
17
+ {'console_scripts': ['bcparser = binarycookies.__main__:main']}
18
+
19
+ setup_kwargs = {
20
+ 'name': 'binarycookies',
21
+ 'version': '2.2.3',
22
+ 'description': 'Python Binary Cookies (de)serializer',
23
+ 'long_description': '[![Github Actions Status](https://github.com/dan1elt0m/binary-cookies-reader/workflows/test/badge.svg)](https://github.com/dan1elt0m/binary-cookies-reader/actions/workflows/test.yml)\n<h1>\n <img src="docs/bincook.png" width="30" style="vertical-align: middle; margin-right: 10px;">\n Binary Cookies\n</h1>\n\nCLI tool and Python library for reading and writing Binary Cookies.\n\n### Documentation\nFor detailed documentation, please visit the [Binary Cookies Documentation](https://dan1elt0m.github.io/binarycookies/)\n\n### Requirements\n\n- Python >= 3.9\n\n### Installation\n```bash \npip install binarycookies\n```\n\n### CLI example:\n```sh\nbcparser path/to/cookies.binarycookies\n```\n\nOutput:\n```json\n[\n {\n "name": "session_id",\n "value": "abc123",\n "url": "https://example.com",\n "path": "/",\n "create_datetime": "2023-10-01T12:34:56+00:00",\n "expiry_datetime": "2023-12-31T23:59:59+00:00",\n "flag": "Secure"\n },\n {\n "name": "user_token",\n "value": "xyz789",\n "url": "https://example.com",\n "path": "/account",\n "create_datetime": "2023-10-01T12:34:56+00:00",\n "expiry_datetime": "2023-12-31T23:59:59+00:00",\n "flag": "HttpOnly"\n }\n]\n```\n#### Output formats\nThe CLI supports multiple output formats using the --output flag.\n- `json` (default): Outputs cookies in JSON format.\n- `ascii`: Outputs cookies in a human-readable ASCII format with each cookie property on a separate line.\n- `netscape`: Outputs cookies in the Netscape cookie file format.\n\n### Basic Usage Python\n\n#### Deserialization\n\n```python\nimport binarycookies \n\nwith open("path/to/cookies.binarycookies", "rb") as f:\n cookies = binarycookies.load(f)\n```\n\n#### Serialization\n\n```python\nimport binarycookies \n\ncookie = {\n "name": "session_id",\n "value": "abc123",\n "url": "https://example.com",\n "path": "/",\n "create_datetime": "2023-10-01T12:34:56+00:00",\n "expiry_datetime": "2023-12-31T23:59:59+00:00",\n "flag": "Secure"\n}\n\nwith open("path/to/cookies.binarycookies", "wb") as f:\n binarycookies.dump(cookie, f)\n```\n\n### Ethical Use & Responsible Handling\nThis project is intended for lawful, ethical use only. Typical, appropriate uses include:\n- Inspecting Binary Cookies from your own devices or data you are authorized to access\n- DFIR, QA, and security testing performed with explicit, written permission\n- Educational/research work on datasets that are owned by you, anonymized, or publicly released for that purpose\n\nYou must not use this tool to:\n- Access, extract, modify, or distribute cookies from systems or accounts you do not own or have permission to analyze\n- Bypass authentication, session management, DRM, or other technical controls\n- Enable tracking, stalking, doxxing, fraud, or other privacy-invasive or harmful activities\n\n\n### License\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n### Contributing\nContributions are welcome! If you find a bug or have a feature request, please open an issue on GitHub. Pull requests are also welcome.\n',
24
+ 'author': 'Daniel Tom',
25
+ 'author_email': 'd.e.tom89@gmail.com',
26
+ 'maintainer': 'None',
27
+ 'maintainer_email': 'None',
28
+ 'url': 'None',
29
+ 'package_dir': package_dir,
30
+ 'packages': packages,
31
+ 'package_data': package_data,
32
+ 'install_requires': install_requires,
33
+ 'entry_points': entry_points,
34
+ 'python_requires': '>=3.8,<4.0',
35
+ }
36
+
37
+
38
+ setup(**setup_kwargs)
@@ -1,4 +1,5 @@
1
- from datetime import datetime, timezone
1
+ import sys
2
+ from datetime import datetime, timedelta, timezone
2
3
  from io import BytesIO
3
4
  from struct import unpack
4
5
  from typing import BinaryIO, List, Union
@@ -26,21 +27,35 @@ def interpret_flag(flags: int) -> Flag:
26
27
  return FLAGS.get(flags, Flag.UNKNOWN)
27
28
 
28
29
 
30
+ MAC_UNIX_OFFSET = 978307200 # Seconds from Unix epoch (1970) to Mac epoch (2001)
31
+ INT32_TIME_T_MAX = 2147483647 # Max signed 32-bit time_t (Unix timestamp)
32
+ INT32_CUTOFF_DT = datetime(2038, 1, 19, 3, 14, 7, tzinfo=timezone.utc)
33
+
34
+
29
35
  def mac_epoch_to_date(epoch: int) -> datetime:
30
36
  """
31
- Converts a mac epoch time to a datetime object, handling potential
32
- overflows on both 32-bit and 64-bit systems.
33
- """
34
- # The Mac epoch starts on 2001-01-01, which is 978307200 seconds after the Unix epoch.
35
- unix_epoch = epoch + 978307200
37
+ Convert Mac epoch seconds (since 2001-01-01 UTC) to an aware datetime.
36
38
 
39
+ On 32-bit systems, clamp results that would overflow `time_t` to 2038-01-19T03:14:07Z.
40
+ On 64-bit systems, only clamp if the value exceeds datetime's range (-> datetime.max).
41
+ """
42
+ base = datetime(2001, 1, 1, tzinfo=timezone.utc)
43
+ # Fast path: pure Python arithmetic (independent of C time_t)
37
44
  try:
38
- return datetime.fromtimestamp(unix_epoch, tz=timezone.utc)
39
- except (OverflowError, OSError):
40
- # This handles timestamps that are too large for the system's C library,
41
- # which can happen for non-expiring cookies or on 32-bit systems (Year 2038 problem).
45
+ dt = base + timedelta(seconds=epoch)
46
+ except OverflowError:
47
+ # Beyond datetime range: choose appropriate cap
48
+ if sys.maxsize <= 2**31 - 1:
49
+ return INT32_CUTOFF_DT
42
50
  return datetime.max.replace(tzinfo=timezone.utc)
43
51
 
52
+ # 32-bit clamp logic
53
+ if sys.maxsize <= 2**31 - 1:
54
+ unix_ts = epoch + MAC_UNIX_OFFSET
55
+ if unix_ts > INT32_TIME_T_MAX:
56
+ return INT32_CUTOFF_DT
57
+ return dt
58
+
44
59
 
45
60
  def read_string(data: BytesIO, size: int) -> str:
46
61
  """Reads a string from binary file."""
@@ -68,7 +68,7 @@ def serialize_cookie(cookie: Cookie) -> bytes:
68
68
 
69
69
 
70
70
  def dump(cookies: CookiesCollection, f: Union[BufferedWriter, BytesIO, BinaryIO]):
71
- """Dumps a Binary Cookies object to create a binary cookies file.k
71
+ """Dumps a Binary Cookies object to create a binary cookies file.
72
72
 
73
73
  Args:
74
74
  cookies: A Binary Cookies object to be serialized.
@@ -80,6 +80,7 @@ def dump(cookies: CookiesCollection, f: Union[BufferedWriter, BytesIO, BinaryIO]
80
80
 
81
81
  def dumps(cookies: CookiesCollection) -> bytes:
82
82
  """Dumps a Binary Cookies object to a byte string.
83
+
83
84
  Args:
84
85
  cookies: A Binary Cookies object to be serialized.
85
86
  Returns:
@@ -20,6 +20,18 @@ class Flag(str, Enum):
20
20
 
21
21
 
22
22
  class Cookie(BaseModel):
23
+ """Represents a cookie in the binary cookies format.
24
+
25
+ Attributes:
26
+ name (str): The name of the cookie.
27
+ value (str): The value of the cookie.
28
+ url (str): The URL associated with the cookie.
29
+ path (str): The path for which the cookie is valid.
30
+ create_datetime (datetime): The creation date and time of the cookie.
31
+ expiry_datetime (datetime): The expiration date and time of the cookie.
32
+ flag (Flag): The flags associated with the cookie, such as Secure or HttpOnly.
33
+ """
34
+
23
35
  name: str
24
36
  value: str
25
37
  url: str
File without changes