as0ler / BinaryCookieReader

A tool to read the binarycookie format of Cookies on iOS applications
94 stars 37 forks source link

Had to update for Python 3.12.2 #5

Closed mikelabonte closed 1 month ago

mikelabonte commented 6 months ago

Fast forward to 2024 and this did not work for me out of the box using Python 3.12.2. In general the handling of byte data isn't working, beginning with the file signature check which results in the error: "Not a Cookies.binarycookie file". But also, StringIO didn't work.

I got it working, but actually I had grabbed a different version at https://github.com/ktnjared/BinaryCookieReader . I've never done a pull request before but I'm not sure which version to start with if I were to do so. The core changes I made are (line numbers are off because I made other changes):

16c19 < from io import StringIO

from io import BytesIO 34c37 < if str(file_header) != 'cook':

if file_header != b'cook': 57,59c60,62 < # Converts the string to a file. So that we can use read/write operations easily. < page = StringIO(page) < page.read(4) # page header: 4 bytes: Always 00000100

# Converts the bytes to a file. So that we can use read/write operations easily.
pageio = BytesIO(page)
pageio.read(4)  # page header: 4 bytes: Always 00000100

61c64 < num_cookies = unpack('<i', page.read(4))[0]

num_cookies = unpack('<i', pageio.read(4))[0]

66c69 < cookie_offsets.append(unpack('<i', page.read(4))[0])

    cookie_offsets.append(unpack('<i', pageio.read(4))[0])

68c71 < page.read(4) # end of page header: Always 00000000

pageio.read(4)  # end of page header: Always 00000000

72,74c75,77 < page.seek(offset) # Move the page pointer to the cookie starting point < cookiesize = unpack('<i', page.read(4))[0] # fetch cookie size < cookie = StringIO(page.read(cookiesize)) # read the complete cookie

    pageio.seek(offset)  # Move the page pointer to the cookie starting point
    cookiesize = unpack('<i', pageio.read(4))[0]  # fetch cookie size
    cookie = BytesIO(pageio.read(cookiesize))  # read the complete cookie

90c93 < cookie_flags = 'Unknown'

        cookie_flags = 'Unknown'+str(flags)

123c126 < url = url+str(u)

        url = url+u.decode()

130c133 < name = name+str(n)

        name = name+n.decode()

137c140 < path = path+str(pa)

        path = path+pa.decode()

144c147 < value = value+str(va)

        value = value+va.decode()
dan1elt0m commented 2 months ago

Looks like this project is not maintained anymore. Forked it and updated to work with latest Python: binary-cookies-reader.

Easy to install

pip install binary-cookies-parser

and works from terminal

bcparser <path_to_binary_cookies_file>

or

from binary_cookies_parser.parser import read_binary_cookies_file

cookies = read_binary_cookies_file("path/to/cookies.binarycookies")