vn-tools / arc_unpacker

CLI tool for extracting images and sounds from visual novels.
GNU General Public License v3.0
561 stars 83 forks source link

G-Senjou No Maou (decrypting chunk issue) #185

Closed XutaxKamay closed 3 years ago

XutaxKamay commented 3 years ago

Game info

VNDB link: https://vndb.org/v211 Developer: Akabei Soft2 Release date: 2008 Original title: G-Senjou No Maou English title (if available): The Devil on G-String

Details

Hello there! So I thought it was supported as it said on your game list but I got apparently some issues with unpacking xp3 files (they are still left encrypted), so I went looking on the encryption method used, and it seems a simple XOR algorithm for decrypting the chunk on the TPM dynamic library (called sys.tpm):

int key = *(uint32_t*)hash >> 12;
int iter = 0;

if (bufferSize)
{
    while (iter < bufferSize)
    {
        if (offset + iter > 4)
        {
            buffer[iter] ^= key;
        }

        iter++;
    }
}

I wanted to make my own little tool for it before, but since I saw this just now, I'm thinking to implement it in this tool, but I'm not sure how I should do it, I saw that there is "plugins" but it doesn't seem to accept the hash in a lambda function for the TVPXP3ArchiveExtractionFilter structure?

Do you think you could add it?

If not at worse, a bit of guidance would help me a lot if possible.. So I don't make unnecessary changes inside the tool that may break it since I'm not much used with the source code yet.

Otherwise I'll try to figure out that myself without breaking something inside the tool.

Thank you for your replies!

EDIT:

apparently it was as simple as this;

    plugin_manager.add(
        "gsenjou", "G-Senjou No Maou",
        create_simple_plugin([](bstr &data, u32 key)
        {
            int realKey = key >> 12;

            for (const auto i : algo::range(data.size()))
            {
                if (i > 4)
                {
                    data[i] ^= realKey;
                }
            }
        }));