Newbie Spellweaver
- Joined
- Feb 9, 2011
- Messages
- 11
- Reaction score
- 7
Hello I will show you how the resource file *.res in Flyff works.
First there is one byte: the EncryptionKey. Flyff's standard EncryptionKey is: 0x57
then comes a byte which tells if the files are encrypted in the resource file.
default: 0x01 or 0b00000001 is true = encrypted (0x00 or 0b00000000 false = not encrypted)
then a 4-byte value of the ciphertext: (for encryption look at the bottom)
The first 7 bits of the 4-byte value is the version of the resource file
then the next 2 bytes as an Int16 value, representing a number.
This number tells us how many files are in this resource file.
then for each file in this resourcefile comes this:
2-byte ASCII string -> Filename
4-byte number Int32 -> Filesize
4-byte number Int32 -> not in use anymore
4-byte number Int32 -> offset (Where the file begins)
then the last bytes are the files.
they are encrypted when the value, described above, is true.
For decryption:
Every bit is turned upside down(the "NOT" bitwise operation) on the data byte (0xCD)
for example:
0xCD = 0b11001101 NOT = 0b00110010 all 1's and 0's reversed.
then XOR it with the EncryptionKey (XOR = Exclusive or):
0b00110010 XOR 0b01010111 = 0b01100101
Next, the result is set to the left by 4(Bit shifting):
0b01100101 = 0b01010110(result 1)
Now the previous result by 4 to the right:
0b01100101 = 0b01010110(result 2)
now both are associated with the bitwise operation OR:
0b01010110 OR 0b01010110 = 0b01010110
Encryption:
the same principle, only reversed:
the first data byte is set to the left by 4 (result 1) now the previous result by 4 to the right(result 2)
then result 1 and 2 are associated with the bitwise operation OR
this result is associated with the bitwise operation NOT and then associated with XOR to the EncryptionKey.
now in C++ from the source:
Code:
#No C&P
First there is one byte: the EncryptionKey. Flyff's standard EncryptionKey is: 0x57
then comes a byte which tells if the files are encrypted in the resource file.
default: 0x01 or 0b00000001 is true = encrypted (0x00 or 0b00000000 false = not encrypted)
then a 4-byte value of the ciphertext: (for encryption look at the bottom)
The first 7 bits of the 4-byte value is the version of the resource file
then the next 2 bytes as an Int16 value, representing a number.
Code:
The value of type Int16 represents numbers between -32768 and +32767
then for each file in this resourcefile comes this:
2-byte ASCII string -> Filename
4-byte number Int32 -> Filesize
4-byte number Int32 -> not in use anymore
4-byte number Int32 -> offset (Where the file begins)
then the last bytes are the files.
they are encrypted when the value, described above, is true.
For decryption:
Every bit is turned upside down(the "NOT" bitwise operation) on the data byte (0xCD)
for example:
0xCD = 0b11001101 NOT = 0b00110010 all 1's and 0's reversed.
then XOR it with the EncryptionKey (XOR = Exclusive or):
0b00110010 XOR 0b01010111 = 0b01100101
Next, the result is set to the left by 4(Bit shifting):
0b01100101 = 0b01010110(result 1)
Now the previous result by 4 to the right:
0b01100101 = 0b01010110(result 2)
now both are associated with the bitwise operation OR:
0b01010110 OR 0b01010110 = 0b01010110
Encryption:
the same principle, only reversed:
the first data byte is set to the left by 4 (result 1) now the previous result by 4 to the right(result 2)
then result 1 and 2 are associated with the bitwise operation OR
this result is associated with the bitwise operation NOT and then associated with XOR to the EncryptionKey.
now in C++ from the source:
Code:
Code:
static BYTE Encryption( BYTE byEncryptionKey, BYTE byData )
{
byData = ( byData << 4 ) | ( byData >> 4 );
return ( ~byData ) ^ byEncryptionKey;
}
static BYTE Decryption( BYTE byEncryptionKey, BYTE byData )
{
byData = ~byData ^ byEncryptionKey;
return ( byData << 4 ) | ( byData >> 4 );
}
Last edited: