Join also our Discord channel! Click here.

Astonia - Compressed Archives (.pak/zlib/libpng)

Read or post about compression. And decompression. Or ask questions how to decompress your files.
Post Reply
Posts: 2
Joined: Mon Aug 13, 2018 2:03 pm

Astonia - Compressed Archives (.pak/zlib/libpng)

Post by DJMD713 » Tue Aug 14, 2018 10:09 pm

I have been working on figuring out Astonia's .pak files but have not had much success. The game is now open source (see Github below). So far I have determined the following:
I am trying to learn more about C++ to figure out a way to reverse the process but it is currently beyond what I am capable of. Does anyone have suggested guides or tutorials I can learn from? If anyone else is up to the task of deconstructing the files that would be much appreciated as well :mrgreen:

Edit: There is another thread on the forum (viewtopic.php?f=15&t=2134) but the MexScript did not yield any useful results.

User avatar
Posts: 2564
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1307 times

Re: Astonia - Compressed Archives (.pak/zlib/libpng)

Post by chrrox » Tue Aug 14, 2018 11:56 pm

use offzip
offzip.exe -a c:\file.pak c:\extractDir 0x0

Posts: 2
Joined: Mon Aug 13, 2018 2:03 pm

Re: Astonia - Compressed Archives (.pak/zlib/libpng)

Post by DJMD713 » Wed Aug 15, 2018 2:49 am

chrrox wrote:use offzip
offzip.exe -a c:\file.pak c:\extractDir 0x0

Thanks for the suggestion. It seems to extract the correct number of files but does not get the correct data. Here is a screenshot with the extracted files (left) vs the expected output (right). Not sure what to make of this. Is it an offset issue or is there more to it?


Posts: 1
Joined: Thu Nov 16, 2017 6:03 am

Re: Astonia - Compressed Archives (.pak/zlib/libpng)

Post by honcheon » Tue Aug 21, 2018 9:16 am

[Google Translator]
The contents are very awkward using the translator.

Looking at line 288 of 'gfx.c', there are three types of pak files.
The structure of the pak file can be seen by looking at the 'pakdat' and 'gfxdata' directly below the type.

Let's go some more.
On line 804 we have the function 'gfx_save_pak'.
If you check this function, 'savetime', 'dat_cnt', 'offset', 'totsize', 'dat_id', 'dat_type' etc. exist with the size of the variable.

Code: Select all

# savetime,4
# dat_cnt,4
# offset,4 => 4+4 + dat_cnt*(4+4+4+4)
# totsize,4 => 4+4 + gfxdata[i].compsize +8
# gfxdata[i].dat_id,4
# gfxdata[i].dat_type,4
Let's take an example of this file. (00000000.pak)
The first 4 bytes 'B0 62 9A 46' is 'savetime'. The next 4 bytes '63 00 00 00' are 'dat_cnt'.
This is a separate value up to this point.
From this point, it is repeated by 'dat_cnt' until offset 638h.
The format is 'offset', 'totsize', 'dat_id', and 'dat_type', each of 4 bytes.

Now move to the 'offset' section. (638h)
Looking at the data in this next section, 697h.

The total size is 5F. This is 'totsize'.
This block is also the contents of the for statement on line 841.
If you look carefully at the content, you can see that this data has the following form:

Code: Select all

# gfxdata[i].compsize,4
# gfxdata[i].realsize,4
# gfxdata[i].data, gfxdata[i].compsize
# gfxdata[i].xres,2
# gfxdata[i].yres,2
# gfxdata[i].xoff,2
# gfxdata[i].yoff,2
Now, with 'compsize' and 'realsize', you can output the same result as using offzip.
So far, it's very easy, But what you see now is the most important issue.

This is followed by the image palette value. On line 860.
The last 4 bytes of sample file are '00 00 00 00 '.
In other words, this means that the first three types of data were palette-free.

To extract an image from a pak file, you need to figure out the palette value. (The last 36 bytes of the 00124000.pak file have the same value.)
That is, you have to distinguish the type of the file.
Probably related functions are estimated to be 'gfx_load_image_pak', 'load_gfx_num', 'make_gfx_num' and so on.
And the variables 'xres', 'yres', 'xoff', and 'yoff' also seem to be related.

That's all I've analyzed.
It was beyond my ability to reverse this part.
I hope these contents will help you.

# This script is for a sample file. (same offzip output)

Code: Select all

get savetime long
get dat_cnt long

for i=0 < dat_cnt
    if i == dat_cnt

    get offset long
    get totsize long
    get dat_id long
    get dat_type long
    savepos nextoff

    goto offset
    get compsize long
    get realsize long
    xmath offset "offset + 8"
    clog "" offset compsize realsize

    goto nextoff
next i

Post Reply