myfreeer / chrome-pak-customizer

a simple command-line tool to pack and unpack pak files in chrome or chromium-based browser
MIT License
204 stars 36 forks source link

Brotli support? #11

Open ericlaw1979 opened 2 years ago

ericlaw1979 commented 2 years ago

A while back, Chromium started using Brotli compression on textual resources. It doesn't look like the unpacker handles that?

If I strip 8 bytes off the front of the file extracted from unpack.bat, I can then use brotli.exe to uncompress the resource.

myfreeer commented 2 years ago

References: https://github.com/chromium/chromium/blob/c4d3c31083a2e1481253ff2d24298a1dfe19c754/tools/grit/grit/node/base.py#L657 https://github.com/chromium/chromium/blob/c4d3c31083a2e1481253ff2d24298a1dfe19c754/ui/base/resource/resource_bundle.h#L58 https://datatracker.ietf.org/doc/html/rfc7932#page-31

Format of brotli compressed resource: 2 bytes header: {0x1e, 0x9b} 6 bytes decompressed size: truncated to 6 bytes, little-endian. compressed brotli stream

For unpacking we can detect the header bytes and truncate header and decompressed size from output, but for packing we have to parse the brotli stream, iterating all meta blocks, and restore the decompressed size, which takes time to implement.

Update: seems impossible to get uncompressed size without decompression https://github.com/google/brotli/issues/861

Maybe we can make a chromium-specific brotli compression tool for this chromium-specific brotli compression format.

myfreeer commented 2 years ago

See experimental work at https://github.com/myfreeer/chrome-pak-customizer/tree/3.x