Data.Pak creation

07/31/2008 07:08 diegolatigo#1
hey guys im kinda new to dekaron and my skills in hacking is lame but i'm a good researcher LOL. alot of people here has a question in how to re-create the data.pak file from the extracted data.pak file. first of all i would like to give credit to darkinc or the one who created that software for unpacking the data.pak file next is im also giving credit to mr. R. wilson for the TUT.

here it goes

The PAK File Class

I think now would be a good time to introduce the PAK class I am going to use. It is shown below:

class CPakFile
{
private:
// Private Variables
char m_szFolderPath[300];
char m_szPakName[300];
sPakHeader m_Header;
sFileTableEntry* m_FileTable;

// Private Functions
BOOL GenerateHFT();
BOOL WorkOutOffsets();

public:
CPakFile();
~CPakFile();

BOOL CreatePak( char* Path, char* Output);
};

The first two variables m_szFolderPath and m_szPakName will be the absolute paths to a compilation folder and the location / filename of the PAK to be output. The compilation folder will just be a folder containing every file you want to add to the PAK collated together. These two values will be read in from edit boxes in the accompanying compile tool and passed to the Create() method. There is also a file header variable of type sPakHeader and the linked list file-table of type sFileTableEntry which are two structures I will look at below. On instantiation of this class, the constructor defaults the variables and then adds a blank dummy node to the head of the linked list file-table. To save space, I will just let you look at this in the accompanying source code. The other two private functions generate the header and the file table and then works out the individual file offsets for inside the PAK respectively. They are both called by the Create() method, which is currently the only public method.
The File Header

The file header for this PAK can be relatively simple. I am just going to use the following structure outlined below:

struct sPakHeader
{
char szSignature[6];
float fVersion;
DWORD dwNumFTEntries;
BOOL bCipherAddition;
BYTE iCipherValue;
char szUniqueID[10];
DWORD dwReserved;
};

I feel that most of its contents are self-explanatory. The iCipherAddition variable just indicates whether the cipher value is added or subtracted from each BYTE sized element that is encrypted. For those of you who don't know, a Caesar cipher is where you transpose each value that is to be encrypted "left or right" by a certain, consistent value. As a quick example, the letter 'A' encrypted using a +3 Caesar cipher would become the letter 'D'. The dwNumFTEntries variable is the number of file table entries (the number of files) in the PAK.
The File Table

The file table will be a linked list of the following data structure, sFileTableEntry, which is outlined below. Each entry will be descriptive of any one file in the PAK.

struct sFileTableEntry
{
char szFileName[30];
DWORD dwFileSize;
DWORD dwOffset;
sFileTableEntry* Next;

// Constructor
sFileTableEntry()
{
ZeroMemory( szFileName, sizeof(szFileName) );
dwFileSize = 0;
dwOffset = 0;
Next = NULL;
}

// Deconstructor
~sFileTableEntry()
{
ZeroMemory( szFileName, sizeof(szFileName) );
dwFileSize = 0;
dwOffset = 0;
delete Next;
}
};

The offset value will be the first byte of the particular file within the PAK archive. The file name, size and link to another entry are also included.
The Create Method - Part 1

The functions (including private ones) are quite large so I'll leave it in the source for you to look at and just describe them here. I feel that they are well commented though and that you should have no problems keeping up with them.

The Create() method really starts when it calls the function GenerateHFT(). GenerateHFT starts by filling in the header structure. It adds the signature, version number etc and some random results for the cipher value, unique ID and cipher direction (add or subtract). It then looks at the specified compilation directory (a parameter for Create() ) and parses it file by file. With each file that is found in the directory, it creates a new sFileTableEntry() node, fills in the filename and file size variables (with a default offset value) and adds it on to the linked list file-table. With each file found a counter is incremented. When this process is finished, the dwNumFTEntries variable of the header structure is assimilated with this counter.

The next stage of Create() is the calling of the WorkOutOffsets function. The very first file offset is calculated like this:

dwOffset = sizeof(sPakHeader) + (m_Header.dwNumFTEntries *
sizeof(sFileTableEntry));

The head entry of the file-table will take this to be the value of its offset member variable. Then the size of the file (already calculated for each entry by GenerateHFT() ) is added to the offset. It is then a case of iterating through the other file table entries and taking the offset value for its member variable and then adding on the particular file sizes. It is much easier to see in the code than it is to describe here!
The Create Method - Part 2

At this stage the header and file table for the PAK are completely filled in. Now we open a file stream, using the second supplied parameter for Create(), and write an unencrypted header.

To write the encrypted file table we need to iterate through the linked list file-table one entry at a time (using a local copy of a file table entry called Current). Once we have checked that we are not on the dummy entry, we create a BYTE array the same size as sFileTableEntry like this:

BYTE* Ptr = NULL;
Ptr = new BYTE [sizeof(sFileTableEntry)];

We then copy the current file table entry in to this BYTE array as follows:

memcpy( Ptr, Current, sizeof(sFileTableEntry) );

We then iterate through each BYTE in this array, encrypt it and write it out to the PAK file. The code for this is:

for( int i = 0; i < sizeof(sFileTableEntry); i++ )
{
// Temporary BYTE variable
BYTE Temp = 0;

// Make equal to the relevant byte of the FT entry
Temp = Ptr[i];

// Encrypt BYTE according to the Caesar cipher
if( m_Header.bCipherAddition == TRUE )
Temp += m_Header.iCypherValue;
else
Temp -= m_Header.iCypherValue;

// Write the FT encrypted BYTE value
fwrite( &Temp, sizeof(BYTE), 1, PAKStream );
}

Once this is done the file stream is closed and the Current variables is set to the head of the linked list file-table again. What we do now is open two file streams. One is for writing to the PAK file and one for reading in each file to be added. These will be used in conjunction with each other.

We set the position in the PAK file (for writing) according to the dwOffset value stored in the current file entries member variable. We then read in a BYTE at a time from the input stream (which was opened using the szFilename variable of the current file entry), encrypt it using the Caesar cipher as before and output it in to the PAK file using the write stream. This is, again, demonstrated in the attached source code.
Conclusion

That's it for just now. A public method could easily be added that loads the header from an existing PAK file and, using that data decrypt and load the contained file-table. With that information you could easily, say, decrypt and extract files to a specified directory and dynamically load them. The way I envision using it would be to dynamically create BYTE arrays within my program the same size as the file I want to utilise and copy the data from the PAK (unencrypted) in to this array. I could then use "load from memory" functions (like D3DXLoadMeshFromXInMemory() or D3DXCreateTextureFromFileInMemory() ) to work with the data. LUA scripts would be perfect here to tell me which files I need to load and, as an example, you could load all the files you need using this method "between levels". I could always write this load function later on if anybody desires it. I hope you find this useful and that it can be a source of inspiration for your own projects.

but still i cant understand half of the word he is saying
maybee someone in the forum know something about it
just in case PM me for news
07/31/2008 07:17 kikichan#2
+#1 reported at 31.07.2008 12:15 gmt-6 cause wrong section.

Please post this in the question area since your asking an question.
07/31/2008 07:30 diegolatigo#3
ooooppppppsssss sorry about that did not notice im in the wrong section im not active in this site so im not familiar with it again sorry.
but hey guys good news i have an update i have a sample program here with me but im not sure it will work. still on the trial stage and im not sure what cipher value is added to the original data.pak so i will not release it yet. wish me luck
07/31/2008 08:35 Jon8c#4
Not to criticize your efforts, but... This issue has already been discussed. Yes, it is possible to recreate a data.pak from unpacked data.pak files, but it's not really sensible. You make the new data.pak, but it most likely won't have the same offsets dekaron.exe reads from. To my knowledge, you would also have to learn how data.hd works. Also, this is going towards a dead end, since dekaron.exe has CRC checks. Plus, .csv editting still works... The problem with data.pak isn't with the fact that no one has repacked it; it's the fact that there CRC checks on it.
07/31/2008 12:54 gambLex#5
Thanks for posting this. It was an extremelly interesting reading. I didn't come up with some new ideas, but now I understand a bit more about the creation of a data.pak and how it works. Thanx again.
08/01/2008 01:34 diegolatigo#6
To Jon8C
hhhhhhhhhhhhhmmmmmmmmmmm that's interesting yah you are right but
i think someone in this site have cracked the dekaron.exe file thats why he was able to make a bot hhhhhhhhhmmmmmmm maybe he can help out.

plus also the guy who post the unpack program if he could unpack it maybe he, just in case he can also repack it coz he know how to decipher it maybe he know the additional bytes of data added to the original data folder before it was packed
08/01/2008 01:37 Jon8c#7
kiki mentioned you could simply Google it. Don't say 2Moons or anything. Just like ".pak packer" or something. I'm sure 2Moons isn't the only software that uses .pak. More importantly, it's not all about cracking dekaron.exe. Yes, you could remove the CRC checks after decrypting dekaron.exe, but in most cases, that won't rule out the fact that you also need to edit data.hd.
08/01/2008 03:46 diegolatigo#8
yah youre right i'm kinda stuck with that stuff also i wish some one could decode it
hhhhhhhhmmmmmmmmmm still hopin............. hahahahahaha
08/01/2008 09:01 Jon8c#9
Try using Google to figure out what .hd is. Maybe you can also find some editors that support .hd and maybe try to open it and edit it.
08/01/2008 15:52 diegolatigo#10
hhhhhmmmm nice yah that could help i got a lot to do this weekend but first need to crack this exe then the hd then create a program to repack data.pak hhhmmm im wondering where did i put that C++ installer. i just format my pc coz its all mess up. this will keep me busy this weekend.
08/06/2008 03:16 diegolatigo#11
wow guys i have something here by the way thanks to jon8c for some tips im really happy with the result. im still thinking if im going to release this coz it will certainly make a huge change for the game. but hey maybe ill release it but first let me enjoy the fruits of my labor hehehehe. now i dont have to waste my time to grind for dils. wow i just have to stand to any weapon seller then do some buy and sell.
08/06/2008 07:29 unHoly_#12
so u finally made it...? congrats! one thing: please keep it private, dont release. such a hack, will destroy the whole game econemy and the logically consequence will be a big role-back including a fix. seen this in other games when a gold-dupe went public. this wount help no one. u got my tribute. =)
08/08/2008 01:20 diegolatigo#13
yah no problem dekaron will soon launch here in south east asia maybe i will do some dil selling here. That is the main reason why i'm researching for hack bugs and bot programs. just hope they did not noticed the loop hole. thats why i dont do it much just need 50M dil for the wings or maybe 150M for the other two guild member ^^.)
08/08/2008 09:31 Jon8c#14
Erm, what exactly did you make? And, what did I say that helped you... rofl. I'm lost. I don't know what you could possibley do by recreating a new data.pak. Honestly, I believe you should be more focused on dekaron.exe rather than the data.pak itself. As long as you have dekaron.exe taken care of, data.pak will never be a problem. I could explain several scenarios if necessary.
08/08/2008 11:49 unHoly_#15
Quote:
Originally Posted by Jon8c View Post
Erm, what exactly did you make? And, what did I say that helped you... rofl. I'm lost. I don't know what you could possibley do by recreating a new data.pak. Honestly, I believe you should be more focused on dekaron.exe rather than the data.pak itself. As long as you have dekaron.exe taken care of, data.pak will never be a problem. I could explain several scenarios if necessary.
I bet he means that he somehow changed prices of buying and selling stuff. For example: Buy Helm for 1 DIL and sell it for 2 million DIL.. something like that I think. Never thought this could work since its serversided... He probably changed something at data.hd and somehow the .exe, too i guess...
Maybe he thanked you for giving him that advice...
Have seen very similar tries by friends of mine who tried to do the same, then switched to tryin hack the drop-rate but nothing worked... so if he really did it its quite a good work.