Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

Help with Club Penguin's Card-Jitsu Snow .tpk/.kap files

Featured Replies

  • Author
  • Localization

IamEox, posted Tue Mar 23, 2021 7:06 pm (62989)


Hi,
This question has already been asked twice on this forum, but since the answers didn't help me I ask it once again.

Yesterday I spent several hours trying to extract the content of the .tpk files from Club Penguin's Card-Jitsu Snow minigame. Here's what I learned from the other topics:
- The .tpk files are zlib archives and I managed to uncompress them with the command:
Code:
offzip.exe -a file.tpk dest_dir 0`
- The files produced are .kap files. This guy says they contain raw image data. The actual content of the files start with "KAPD" (magic number?), then there's the binary data (image data?) and finally some JSON. For instance:
Code:
{
    "frames": [
        {
            "filename": "rock_mountaintop.png",
            "frame": {
                "x": 0,
                "y": 0,
                "w": 75,
                "h": 69
            },
            "rotated": false,
            "trimmed": false,
            "spriteSourceSize": {
                "x": 0,
                "y": 0,
                "w": 75,
                "h": 69
            },
            "sourceSize": {
                "w": 75,
                "h": 69
            }
        }
    ],
    "meta": {
        "app": "http://www.texturepacker.com",
        "version": "1.0",
        "image": "rock_mountaintop.png",
        "format": "RGBA8888",
        "size": {
            "w": 128,
            "h": 128
        },
        "scale": "1",
        "smartupdate": "$TexturePacker:SmartUpdate:af546ed297e90557d402551245566a2f$"
    }
}
- Following this guy's advice, I tried to play a little bit with TexturePacker to understand where this JSON could come from. Both the images and the JSON were probably generated as separate files and then put together,
- I also played with PVRTexTool and tried the "Wrap Raw Data" menu to open the file. I think the binary data might be compressed because the example rock_mountaintop_small.kap was too small to be a 128x128 image in RGBA8888 format. But if it is, I can't find the correct algorithm in PVRTexTool's list and end up with noise.

So, can anyone help me with this? Is there any tool I can use to extract the .png data in this .kap file?
I don't know if the help given in the other topics was enough. As for me, I am fairly new at this and I need a little more help.

PS: I attached both the untouched .tpk file and the corresponding .kap file I talked about here. Both are in .txt because the actual extensions are not allowed here.
  • Author
  • Localization

IamEox, posted Wed Mar 24, 2021 11:01 pm (63016)


Hi again,

Today I spent several hours trying to reverse Club Penguin's SWF files. Here's what I found:
- The interesting bit that unpacks the .kap files is in the method unpack of the class com.disney.util.DPack in this file. It indicates the files' header format and sections. Here is the code:
Code:
public static function unpack(param1:ByteArray, param2:Boolean = true) : Dictionary {
    var temp:ByteArray = null;
    var magic:uint = 0;
    var numFiles:uint = 0;
    var i:int = 0;
    var lengths:Array = null;
    var names:Array = null;
    var items:Dictionary = null;
    var bytes:ByteArray = null;
    var packedBytes:ByteArray = param1;
    var makeCopy:Boolean = param2;

    if (packedBytes == null) return null;

    if (makeCopy) {
        temp = new ByteArray();
        temp.writeBytes(packedBytes);
        packedBytes = temp;
    }

    try {
        packedBytes.endian = Endian.LITTLE_ENDIAN;
        packedBytes.uncompress();
        magic = packedBytes.readUnsignedInt();

        if (magic != MAGIC_CODE) {
            Log.error("unpack: Invalid magic code " magic);
            return null;
        }

        numFiles = packedBytes.readUnsignedShort();
        lengths = [];
        i = 0;
        while (i < numFiles) {
            lengths.push(packedBytes.readUnsignedInt());
            i ;
        }

        names = [];
        i = 0;
        while (i < numFiles) {
            names[i] = packedBytes.readUTF();
            i ;
        }

        items = new Dictionary();
        i = 0;
        while (i < numFiles) {
            bytes = new ByteArray();
            packedBytes.readBytes(bytes,0,lengths[i]);
            items[names[i]] = bytes;
            i ;
        }

        return items;
   
    } catch(err:Error) {
        Log.error("DPack.unpack: Error unpacking pack file. Error = " err);
        return null;
    }
}
- The files don't contain 2 differents sections as I initially thought, but 4: they are tagged "t" (textures), "j" (json), "i" (interval) and "m" (metadata?),
- The interesting section (the first one) appears to be a JPEG XR image. Editing the hex code of the .kap to keep only the "t" section hex gives a working .jxr image.

I hope this can help those who were, are and will be in the same situation I was yesterday.
I won't mark this post as solved immediately, I need to do/find a few more things (like a script) before that.

PS: I attached my attempt to decode the example .kap file.
  • Author
  • Localization

IamEox, posted Sun Apr 18, 2021 11:29 pm (63447)


I finally had some time to write a little script. Here it is: https://github.com/iameox/tpkator.
This thread can be closed although I don't know how to do it.
  • Author
  • Localization

aluigi, posted Wed May 12, 2021 11:57 am (63938)


Cool, let's keep it open in case other users need help.
  • Author
  • Localization

Monke, posted Tue Apr 19, 2022 5:25 pm (71205)


Were you able to decompile the files?
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.