Opening a Chrome Extension (.crx) file

464 views
Skip to first unread message

Luis Furquim

unread,
Nov 9, 2017, 8:11:13 AM11/9/17
to golang-nuts
Hello Gophers!

I am trying to open a chrome extension file to read its manifest.json. It is a zip file with a .crx extension. When I unzip via command line it works like a charm. But, if I try with golang using package archive/zip it gives me the "zip: not a valid zip file" error. It's not the first time I use this package and it always worked fine, including working with Libre Office documents (.odt). I checked with the "file" command and with "od -c | head" commands and realized that the Chrome Extensions files differ in the magic bytes:

The regular zip file:
vuco@azrael ~/Documents $ od -c ./root/prms-minuano.zip | head -n 1 0000000 P K 003 004 024 \0 \0 \0 \b \0 016 210 0 @ 034 255 vuco@azrael ~/Documents $ file ./root/prms-minuano.zip ./root/prms-minuano.zip: Zip archive data, at least v2.0 to extract


The odt file:
vuco@azrael ~/Documents $ od -c ./mpf/v1.ProjetoIntegracao.odt | head -n 1 0000000 P K 003 004 024 \0 \0 \b \0 \0 256 y 026 ? ^ 306 vuco@azrael ~/Documents $ file ./mpf/v1.ProjetoIntegracao.odt ./mpf/v1.ProjetoIntegracao.odt: OpenDocument Text


The crx file:
sherlock@asspadev ~/work/download $ od -c lestrade.crx | head -n 1
0000000 C r 2 4 002 \0 \0 \0 & 001 \0 \0 \0 001 \0 \0
sherlock@asspadev ~/work/download $ file lestrade.crx lestrade.crx: data


Any suggestions on how to open the file?

Thank you in advance
Luis Otavio de Colla Furquim

Tamás Gulácsi

unread,
Nov 9, 2017, 8:39:24 AM11/9/17
to golang-nuts
As "CRX files are ZIP files with a special header and the .crx file extension. ", and ZIP has a "PK\x05\x06" magic sequence,
a working solution is to read all the bytes of the .crx into a []byte, change the "Cr24" to "PK\x05\x06",
then use a bytes.NewBuffer(b) as a ReaderAt.

The problem is that this signature is in every block.

Luis Furquim

unread,
Nov 9, 2017, 11:14:36 AM11/9/17
to golang-nuts
Thank you for the directions! But this was just the first bit of the problem...
I changed locally the archive/zip sources, making it accept both magic sequences on fileHeaderSignature and directoryHeaderSignature. Then I ran in UnexpectedEOF trap!
I think that there is some version/flavor of the zip format that is just unsupported by the archive/zip package (but is supported by the zip command line).
I am using Go1.8.3, I will try to upgrade to current (1.9.2) version. The release notes mention the zip package but only for the Writer type. Anyway I should upgrade sooner or later...

Cheers
Reply all
Reply to author
Forward
0 new messages