GithubHelp home page GithubHelp logo

cixtor / binarycookies Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 0.0 802 KB

Go (golang) implementation of an encoder and decoder for the Binary Cookies file format used by Safari and other applications based on WebKit to store HTTP cookies. CLI program also included.

License: MIT License

Go 94.79% Tcl 5.21%

binarycookies's Introduction

Binary Cookies GoReport GoDoc

Go (golang) implementation of an encoder and decoder for the Binary Cookies file format used by Safari and other applications based on WebKit to store HTTP cookies. A CLI program is also included to allow you to inspect and manipulate the binary cookies from the commodity of your Terminal.

Usage

If you are going to use this Go module in your project:

go get github.com/cixtor/binarycookies

If you want to install the command line interface (CLI):

go get github.com/cixtor/binarycookies/cmd/binarycookies

Example

The majority of macOS applications store their web cookies in ~/Library/Cookies/ while others —using containers— do so in ~/Library/Containers/<APP_ID>/Data/Library/Cookies/. We can use simple Unix commands to find all these files and dump their content using the CLI, like so:

find ~/Library/Cookies/ -name "*.binarycookies" -exec binarycookies {} \;

Specification

Binary Cookies are binary files containing several pieces of data that together form an array of objects representing persistent web cookies for different applications in the macOS and iOS application ecosystem. Nowadays, almost every application implements some sort of web view to offer in-app purchases and license validation. All the information transmitted via these web views is stored in these binary files.

Note: BE stands for Big-endian and LE stands for Little-endian.

Variable Size Type Description
signature 4 byte File signature must be equal to []byte{0x636f6f6b} or String("cook")
numPages 4 BE_uint32 Number of pages in the file
pageOffset 4 BE_uint32 Page offset. Repeat this N times where N = numPages
pageStart 4 byte Marks the beginning of a page. Must be equal to []byte{0x00000100}
numCookies 4 LE_uint32 Number of cookies in the page
cookieOffset 4 LE_uint32 Cookie offset. Repeat this N times where N = numCookies
pageEnd 4 byte Marks the end of a page. Must be equal to []byte{0x00000000}

Immediately after pageEnd we can read the page cookies. Repeat the steps below N times where N = numCookies.

Variable Size Type Description
cookieSize 4 LE_uint32 Cookie size. Number of bytes associated to the cookie
unknownOne 4 byte Unknown field possibly related to the cookie flags
cookieFlags 4 LE_uint32 0x0:None - 0x1:Secure - 0x4:HttpOnly - 0x5:Secure+HttpOnly
unknownTwo 4 byte Unknown field possibly related to the cookie flags
domainOffset 4 LE_uint32 Cookie domain offset
nameOffset 4 LE_uint32 Cookie name offset
pathOffset 4 LE_uint32 Cookie path offset
valueOffset 4 LE_uint32 Cookie value offset
commentOffset 4 LE_uint32 Cookie comment offset
endHeader 4 byte Marks the end of a header. Must be equal to []byte{0x00000000}
expires 8 float64 Cookie expiration time in Mac epoch time. Add 978307200 to turn into Unix
creation 8 float64 Cookie creation time in Mac epoch time. Add 978307200 to turn into Unix
comment N LE_uint32 Cookie comment string. N = domainOffset - commentOffset
domain N LE_uint32 Cookie domain string. N = nameOffset - domainOffset
name N LE_uint32 Cookie name string. N = pathOffset - nameOffset
path N LE_uint32 Cookie path string. N = valueOffset - pathOffset
value N LE_uint32 Cookie value string. N = cookieSize - valueOffset

Immediately after the last cookie in the page we can read another page with pageStart.

The last cookie of the last page in the file is followed by an 8-bytes checksum.

An optional number of bytes follow the checksum, these are part of a Binary Property List that contains a dictionary with additional information like the cookie accept policy for all tasks within sessions based on the software configuration. A bplist00 file is a completely different file format we need to decode separately. The first 4-bytes after the checksum are the BE_uint32 representing the size of the binary property list. The remaining bytes represent the data we need to decode using a bplist parser.

binarycookies's People

Contributors

cixtor avatar jpap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.