https://github.com/tatsh/bincookie
Header-only binarycookies parser.
https://github.com/tatsh/bincookie
binarycookies cookies ios library macos parser
Last synced: about 2 months ago
JSON representation
Header-only binarycookies parser.
- Host: GitHub
- URL: https://github.com/tatsh/bincookie
- Owner: Tatsh
- License: mit
- Created: 2015-12-19T20:56:25.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2026-04-28T06:47:30.000Z (about 2 months ago)
- Last Synced: 2026-04-28T08:29:27.519Z (about 2 months ago)
- Topics: binarycookies, cookies, ios, library, macos, parser
- Language: C
- Homepage: https://tatsh.github.io/bincookie/
- Size: 4.47 MB
- Stars: 17
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Citation: CITATION.cff
- Codeowners: CODEOWNERS
- Security: SECURITY.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# bincookie
[]()
[](https://github.com/Tatsh/bincookie/tags)
[](https://github.com/Tatsh/bincookie/blob/master/LICENSE.txt)
[](https://github.com/Tatsh/bincookie/compare/v0.1.8...master)
[](https://github.com/dependabot)
[](https://tatsh.github.io/bincookie/)
[](https://github.com/Tatsh/bincookie/stargazers)
[](https://github.com/pre-commit/pre-commit)
[](https://cmake.org/)
[](https://prettier.io/)
[](https://bsky.app/profile/Tatsh.bsky.social)
[](https://buymeacoffee.com/Tatsh)
[](irc://irc.libera.chat/Tatsh)
[](https://hostux.social/@Tatsh)
[](https://www.patreon.com/Tatsh2)
Apple has their own special binary cookie format, undocumented, in use on both OS X and heavily on iOS.
## How to build
There is no build process for this library on its own. Just include the header:
```c
#include
```
## Installation
### Header-only
Just copy `bincookie.h` to somewhere in your project and include it.
Package maintainers: if you do not want the example binary and do not want to have to install CMake,
you only need to place `bincookie.h` in a standard include directory such as `/usr/include`.
### CMake
Install CMake and make sure it is in `PATH`. Then in your terminal:
1. `git clone https://github.com/Tatsh/bincookie.git`
2. `cd bincookie`
3. `mkdir build`
4. `cmake -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=RelWithDebInfo`
5. `make install`
To build the examples, add `-DWITH_EXAMPLES=ON` to step 4.
To build the documentation with Doxygen, add `-DWITH_DOCS=ON` to step 4.
To run tests, build with `-DWITH_TESTS=ON` and run `ctest` after building. CMocka must be installed
to build tests.
Replace `` with a value like `/usr/local`, `/usr/`, or `/opt/local` (MacPorts).
## Functions
Be sure to `#include ` (which is installed with `make install`).
`bincookie_t *const bincookie_init_path(const char *file_path)` - Initialise a `bincookie_t` type.
`bincookie_t *const bincookie_init_file(FILE *fin)` - Initialise a `bincookie_t` type with an open
file handle.
`bincookie_page_t *const bincookie_iter_pages(const bincookie_t *bc, bincookie_iter_state_t *const state)`
Iterate pages of a file.
`bincookie_cookie_t *const bincookie_iter_cookies(const bincookie_page_t *page, unsigned int *cookie_index)`
Iterate cookies contained within a page. `cookie_index` must be set to 0 before calling this
(including in between iteration of pages).
## Macros
`bool bincookie_is_secure(bincookie_cookie_t *cookie)` - Test if a cookie has secure bit set.
`bool bincookie_domain_access_full(bincookie_cookie_t *cookie)` - Test if a cookie can be used by all
subdomains.
`char *bincookie_domain(bincookie_cookie_t *cookie)` - Get the domain name for a cookie.
`char *bincookie_path(bincookie_cookie_t *cookie)` - Get the path for a cookie.
`char *bincookie_name(bincookie_cookie_t *cookie)` - Get the name of a cookie.
`char *bincookie_value(bincookie_cookie_t *cookie)` - Get the value of a cookie.
`double bincookie_expiration_time(bincookie_cookie_t *cookie)` - Get the expiration time of a cookie
as UNIX timestamp.
`double bincookie_creation_time(bincookie_cookie_t *cookie)` - Get the creation time of a cookie as
a UNIX timestamp.
`void bincookie_iter_state_init(bincookie_iter_state_t s)` - Use this to zero a
`bincookie_iter_state_t` structure.
## Flag enum
```c
typedef enum {
secure,
http_only,
} bincookie_flag;
```
The value that stores whether or not a cookie is secure, HTTP-only, or any of these combinations is
a single 32-bit integer, with 0 or more values OR'd together (`0` is the default value). To test for
a particular property, such as HTTP-only, use the `&` operator: `cookie->flags & http_only`.
## Example use
### Access all the cookie names in a file
```c
bincookie_t *bc = bincookie_init_path("Cookies.binarycookies");
unsigned int i, j;
bincookie_page_t *page;
bincookie_cookie_t *cookie;
bincookie_iter_state_t state;
unsigned int cookie_index = 0;
bincookie_iter_state_init(state);
while ((page = bincookie_iter_pages(bc, &state)) != NULL) {
while ((cookie = bincookie_iter_cookies(page, &cookie_index)) != NULL) {
printf("Name: %s\n", bincookie_name(cookie));
}
cookie_index = 0; // yes this is necessary
}
```