how to unpack resources.pak from google chrome?
Asked Answered
M

4

28

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?

Mythological answered 17/5, 2012 at 9:50 Comment(0)
B
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

Beulahbeuthel answered 14/11, 2012 at 21:20 Comment(10)
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.Tufts
@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. :-PMunmro
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 as data_pack.py and make it executable. What really sucks, is that there are no filenames in a .pakIntimacy
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?Blondell
@Blondell 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.Eun
@Eun I found this github.com/myfreeer/chrome-pak-customizer and it can unpack and pack it, but Opera doesn't seem to accept the repacked file.Blondell
@Blondell I couldn't get that to work (Windows-only?), but this github.com/shuax/ChromePAK was at the bottom of the Github page. This one worked and Brave accepts the repacked file.Eun
@Eun This looks interesting, but it is in chinese. Could you post an answer with a guide to unpacking and repacking?Blondell
@Blondell 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)".Eun
@Eun Someone had made a GUI version at 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.Blondell
O
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.

Oklahoma answered 17/12, 2018 at 20:43 Comment(2)
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!Blondell
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.Oklahoma
F
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.

Frigg answered 29/8, 2019 at 15:26 Comment(0)
C
2

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/
Chaney answered 11/1, 2023 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.