27

There are bunch of interesting files accessible via chrome://resources/* using google chrome.

On linux That the content is in /opt/google/chrome/resources.pak. I know I can get the whole sources from http://chromium.googlecode.com/svn/trunk/ but I would like to unpack the resource.pak file.

file resources.pak reports just junk.

Just to be clear, the question is NOT where to get those resources from. The question is what is the resources.pak file format and how to unpack it?

svick
  • 236,525
  • 50
  • 385
  • 514
Michał Šrajer
  • 30,364
  • 7
  • 62
  • 85

4 Answers4

27

taken from https://groups.google.com/a/chromium.org/forum/?fromgroups=#!topic/chromium-dev/agGjTt4Dmcw

4 byte version number
4 byte number of resources
1 byte encoding

For each resource:
2 byte resource id
4 byte resource offset in file

There is an extra resource entry at the end with ID 0 giving the end of the last resource (which is essentially the length of the file)

This python module can unpack and repack files:
data_pack.py from grit-i18n

mercator
  • 28,290
  • 8
  • 63
  • 72
v1nce
  • 735
  • 9
  • 20
  • 3
    Just replace line 160 in data_pack.py from: `print "%s: %s" % (resource_id, text)` to: `with open(str(resource_id), "wb") as file: file.write(text)`, then run: `python data_pack.py yourfile.pak` and you will get files extracted in the current directory. – niutech Mar 08 '14 at 15:17
  • 1
    @niutech, you make it sound like you only have to download that one file, but in fact, you have to download the entire project or `data_pack.py` won't have its dependencies. :-P – Throw Away Account Jun 04 '16 at 06:06
  • it's not hard, just `git clone https://chromium.googlesource.com/chromium/src/tools/grit` `cd grit` and paste in the source from [data_pack.py](https://chromium.googlesource.com/chromium/src/tools/grit/+/master/grit/format/data_pack.py) as data_pack.py and make it executable. What really sucks, is that there are no filenames in a .pak – Orwellophile Sep 11 '16 at 05:30
  • 4 years later, I'm trying to edit opera's extension to improve the appearance of their videopopout, however all the data_pack.py produces is just datapack1.pak and datapack2.py, which does not contain the resources. Also how would I repack the resources after I have unpacked it? – MrU Dec 02 '18 at 09:31
  • @MrU Same here. The two resulting .pak files are also very small (just some kilobytes), so clearly they're not actually containing anything. I did this on Brave Browser, so clearly it is not just an Opera fork thing. – pileofrocks Dec 13 '18 at 23:22
  • 2
    @pileofrocks I found this https://github.com/myfreeer/chrome-pak-customizer and it can unpack and pack it, but Opera doesn't seem to accept the repacked file. – MrU Dec 14 '18 at 07:20
  • 1
    @MrU I couldn't get that to work (Windows-only?), but this https://github.com/shuax/ChromePAK was at the bottom of the Github page. This one worked and Brave accepts the repacked file. – pileofrocks Dec 14 '18 at 21:26
  • @pileofrocks This looks interesting, but it is in chinese. Could you post an answer with a guide to unpacking and repacking? – MrU Dec 15 '18 at 08:56
  • 1
    @MrU This might be too obscure for an answer... But on top of the Github page there's a link another page and in the middle of that page under "ChromePAK V5" there's a link to "pak_tools_v5.7z", it contains command line tool for all platforms. You'll see usage examples when you call "pak_tools(.exe)". – pileofrocks Dec 17 '18 at 02:28
  • @pileofrocks Someone had made a GUI version at https://bbs.shuax.com/thread-24.htm and the unpacking and repacking works (tested without modifying the file). The GUI is used by dragging the file into the window and click on the bottom right button to start the unpack/repack. Only issue left now is to figure out how to recompress the gzip files in the pak. Opera can use my custom gzip files but will say it is corrupt and forces me to quit Opera. – MrU Dec 17 '18 at 12:40
4

The chrome-pak-customizer (pointed out by MrU in the comments above) seems to work well to unpack Chrome's .pak files. If you're on Windows, you can download and unzip chrome-pak.7z from the releases page. Then drop the .pak file on the unpack.bat script to unpack it.

For other platforms, it looks like you'll need to build the tool from the source.

jdunning
  • 1,356
  • 1
  • 14
  • 26
  • Turns out chrome-pak-customizer isn't compatible with the latest Chrome versions (tested by unpacking and repacking without modifying the pak file) ChromePAK seems to work though! – MrU Dec 18 '18 at 12:45
  • I tried unpacking a pak file in Chrome 70 or 71 on Windows, and the assets were unpacked correctly. I didn't try repacking the files. – jdunning Dec 29 '18 at 02:46
2

I found resource.pak V5 has a new format:

struct header {
    // 5 is the latest version
    uint32_t version;
    // 0 = BINARY, 1 = UTF8, 2 = UTF16
    uint8_t encoding;
    // 3 bytes padding
    uint8_t padding[3];
    uint16_t resource_count;
    uint16_t alias_count;
};

Which is followed by resource_count resources, and alias_count aliases.

struct resource {
    uint16_t resource_id;
    uint32_t file_offset;
};
struct alias {
    uint16_t resource_id;
    uint16_t entry_index;
};

Where uint32_t = 4 bytes, uint16_t = 2 bytes, uint8_t = 1, all little endian integers.

The source is available at https://github.com/chromium/chromium/blob/master/ui/base/resource/data_pack.cc.

yeerk
  • 2,103
  • 18
  • 16
1

This python file in chromium could help. https://source.chromium.org/chromium/chromium/src/+/main:tools/grit/pak_util.py

You need to download the whole directory, and then run it.

example:

pak_util.py extract resources.pak -o /tmp/rescources.out/
Bill.W
  • 21
  • 1
  • 5