Page 1 of 1

DB4 tbl

Posted: Tue Mar 06, 2012 6:33 am
by finale00
Here's a file table for a game that's encrypted.
Source code is available (C++), but after staring at it for awhile I simply can't follow it at all :o

Maybe someone can look at the source and tell me how the encryption and compression works?

From the header file I guess I can see the general structure of the archive, but it's not obvious how to decrypt it.

Also, would you say the code is written well? lol I've written very little C++ code to be able to say.

btw, this is part of some fairly large model import/render/export tool so that might explain how it is designed.

Re: DB4 tbl

Posted: Tue Mar 06, 2012 9:48 am
by howfie
The code is poorly written, yeah. There is way too much mixing of C and C++. Rolling your own memory-mapped file system? WTF what for? Just use C++ stream classes!

Code: Select all

unsigned char *dbuf = (unsigned char *) malloc (uncompressed_size);
why not

Code: Select all

char *dbuf =  new char[uncompressed_size];
or better yet

Code: Select all

boost::shared_array<char> dbuf(new char[uncompressed_size]);
Also stuff like (where he reads the first 32-bit value in the data stream and xors it to get the compressed size):

Code: Select all

Miletos::u32 uncompressed_size = *((Miletos::u32 *) cdata) ^ 0xa67f54cb;
is better off written in C++ using input streams. This way he doesn't have to use "spos" to keep track of the file pointer.

Code: Select all

// OK if used locally
using Miletos;
using std;

// convert file data to a binary stream
stringstream stream(ios::binary);
stream << cdata << ends;

// first read operation
u32 uncompressed_size;
stream.read((char*)&uncompressed_size, sizeof(u32));
uncompressed_size ^= 0xa67f54cb;

// more read operations on data stream
Looks like to me all the code you need is in readTable and unpack_a67f54cb. But yeah, unless you're good at C and C++, it probably looks like gibberish to you. I didn't analyze the compression method but it looks like some kind of table lookup algorithm.

Re: DB4 tbl

Posted: Tue Mar 06, 2012 10:11 am
by finale00
Think you could write some code to parse out the file entries?
lol then I can just focus on extracting the data.

Re: DB4 tbl

Posted: Tue Mar 06, 2012 10:23 am
by howfie
Well, there's some missing code. The class is supposed to take two sets of data. Seeing some code where the class is used would help. What game is this for?

Re: DB4 tbl

Posted: Tue Mar 06, 2012 6:13 pm
by finale00
Db4, from illusion.

It stores data in another archive with the same name. I think that is what the other data buffer is for?
I could upload all the other code in the folder but most are for other games.

Re: DB4 tbl

Posted: Wed Mar 07, 2012 3:21 am
by finale00
Here's the rest of the source (well, all the ones in the same folder anyways, there's a lot of source...)
Most of them are irrelevant.

I'm not sure which ones you might need lol