Smile Game Builder archives (sgbpack)

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
wattostudios
Posts: 20
Joined: Fri Jun 02, 2017 2:15 pm

Smile Game Builder archives (sgbpack)

Post by wattostudios »

Wondering if anyone knows enough about encryption to work out how they do it for Smile Game Builder engine archives.

Older versions were just a ZIP file with a funny header and no compression - they're pretty simple to figure out.

Newer archives look very different, to me it looks like the files are XOR'd with a 16-byte repeating key, but each file in the archive might have a different key? In the example archive, the first file looks like it might use this key (\x1E\x20\x45\x1B\x14\x84\xC9\x8C\x53\xA5\x7C\x42\x7B\xA9\x62\xE9) and a file a little further on with this key (\x34\x7C\x25\xD5\xEE\x10\x2C\x2A\x4B\xE7\xE0\xAE\x83\xBB\x2B\x49)

I admit I'm no expert in encryption, so I could be totally wrong.

It looks like there is probably no compression, as there are whole sections of repeating characters that really should be easy to compress.

Is anyone able to help with this?

Sample archive (from game Monarch of Greed - Act 1) - https://drive.google.com/open?id=12A3UhodYRvFjaM9-F_SQQ5JTlmhyO0NC

Thanks for any help!
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Smile Game Builder archives (sgbpack)

Post by aluigi »

It's weird indeed and it's not a xor key since the resulting data is still senseless.
It's not a block cipher too since most of the bytes in these "sequences" are often differents.
Apparently it's necessary to do some reverse engineering and it's not possible to guess it from the file.
lisomn
Posts: 40
Joined: Thu Jan 11, 2018 7:14 am

Re: Smile Game Builder archives (sgbpack)

Post by lisomn »

About sgbpack
First you need to replace the first 8 bytes with
"\x50\x4B\x03\x04\x14\x00\x00\x00"
Then use that algorithm to decrypt

Code: Select all

byte* ptr = 0x02;
int num = 0;
if (0 < buffer.Length)
{
   do
   {
   int num2 = (int)((byte)(num % 16));
   buffer[num] -= (byte)((int)num2[ptr] * num2);
   num++;
   }
   while (num < buffer.Length);
}
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Smile Game Builder archives (sgbpack)

Post by aluigi »

The sample is no longer available, anyone can upload it or another encrypted sgbpack file for testing?
blebloblas
Posts: 1
Joined: Wed Jul 22, 2020 12:13 pm

Re: Smile Game Builder archives (sgbpack)

Post by blebloblas »

lisomn
Posts: 40
Joined: Thu Jan 11, 2018 7:14 am

Re: Smile Game Builder archives (sgbpack)

Post by lisomn »

Decryption tool I made
lisomn
Posts: 40
Joined: Thu Jan 11, 2018 7:14 am

Re: Smile Game Builder archives (sgbpack)

Post by lisomn »

aluigi wrote:The sample is no longer available, anyone can upload it or another encrypted sgbpack file for testing?

hi aluigi Here is the decryption logic, can you create a bms version?
The bms script I made is a bit slow

program logic

Code: Select all

      auto bs=File(file_name,"rb+");
      ulong size=getSize(file_name);
      char[] magic=bs.rawRead(new char[6]);
      ubyte[] key=[72,9,20,154,48,169,84,225,0,8,14,9,20,60,66,70];
      ubyte[] header=[80,75,3,4,20,0,0,0];
      if(magic.dup == "SGBDAT")
      {
         int versionno=(bs.rawRead(new ubyte[1])[0]<<8)+bs.rawRead(new ubyte[1])[0];
         if(versionno!=0)
         {
            int versionno=(bs.rawRead(new ubyte[1])[0]<<8)+bs.rawRead(new ubyte[1])[0];
            auto wbs=File(file_name~".zip","wb");
            wbs.rawWrite(header);
            int num=0;
            ubyte[] buffe=bs.rawRead(new ubyte[(size-8).to!uint]);
            for(int i=0;i<(size-8);i++)
            {
               buffe[num]-=key[num%16];
               num++;
            }
            wbs.rawWrite(buffe);
         }
      }
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Smile Game Builder archives (sgbpack)

Post by aluigi »

Thanks a lot, just made the script :)
http://aluigi.org/bms/sgbpack.bms
gaugsroff2
Posts: 1
Joined: Mon Nov 23, 2020 1:46 pm

Re: Smile Game Builder archives (sgbpack)

Post by gaugsroff2 »

Thank you. Unfortunately both tools extract a zip with lots of files but the png/obj/ogg files inside can't be opened.

Example game: https://syukino.itch.io/euclyca-chronicles-lyla

More details: Seeking smile game builder extractors / Game exe states: SGB RPG Player 1.12.8.4 by SmileBoom Co. Ltd.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Smile Game Builder archives (sgbpack)

Post by aluigi »

Ok I rewrote the script from scratch, it can now be used to dump all the files without creating the ZIP first.

The problem was simply that the extracted files had a second encryption (so after decompression) and needed to be decrypted.
Renneta
Posts: 1
Joined: Tue May 18, 2021 11:13 am

Re: Smile Game Builder archives (sgbpack)

Post by Renneta »

aluigi wrote:Ok I rewrote the script from scratch, it can now be used to dump all the files without creating the ZIP first.

The problem was simply that the extracted files had a second encryption (so after decompression) and needed to be decrypted.


Can you help me? I want to translate one game on the SGB engine, but I'm not a programmer and can't open this type of archives. :cry:

---OK, no need more.