C# Class Warcraft.MPQ.Crypto.MPQCrypt

ファイルを表示 Open project: Nihlus/libwarcraft

Public Methods

Method Description
DecryptData ( byte data, uint key ) : byte[]

Decrypts the given input data. Bytes outside of an even 4-byte boundary are not decrypted, and are considered not encrypted.

DecryptSectorOffsetTable ( BinaryReader br, List &sectorOffsets, uint blockSize, uint key ) : void

Decrypts the sector offset table using rolling decryption - it starts where the input BinaryReader is, reads and decrypts offsets until the decrypted offset equals the input block size.

EncryptData ( byte data, uint key ) : byte[]

Encrypts the given input data. Bytes outside of an even 4-byte boundary are not encrypted, and are simply appended at the end of the data block.

GetFileKey ( string fileName, bool isAdjusted = false, uint blockOffset, uint fileSize ) : uint

Calculates the decryption key for a file sector.

Hash ( string inputString, HashType hashType ) : uint

Hashes an input string, given a hash type. This function is case-insensitive, and treats all input as being in ALL UPPER CASE.

VerifySectorChecksum ( byte sector, uint checksum ) : bool

Verifies the integrity of a file sector using an adler32 checksum.

Private Methods

Method Description
InitializeEncryptionTable ( ) : void

Initializes the encryption table.

InternalEncryptDecrypt ( byte data, uint key ) : byte[]

Internal XOR function that encrypts and decrypts a block of data.

MPQCrypt ( ) : System

Method Details

DecryptData() public static method

Decrypts the given input data. Bytes outside of an even 4-byte boundary are not decrypted, and are considered not encrypted.
public static DecryptData ( byte data, uint key ) : byte[]
data byte Data to be decrypted.
key uint The decryption key to use.
return byte[]

DecryptSectorOffsetTable() public static method

Decrypts the sector offset table using rolling decryption - it starts where the input BinaryReader is, reads and decrypts offsets until the decrypted offset equals the input block size.
public static DecryptSectorOffsetTable ( BinaryReader br, List &sectorOffsets, uint blockSize, uint key ) : void
br System.IO.BinaryReader The archive's BinaryReader
sectorOffsets List The output sector offsets.
blockSize uint The size of the block to be decrypted.
key uint The decryption key for the offset table.
return void

EncryptData() public static method

Encrypts the given input data. Bytes outside of an even 4-byte boundary are not encrypted, and are simply appended at the end of the data block.
public static EncryptData ( byte data, uint key ) : byte[]
data byte Data to be encrypted.
key uint The encryption key to use.
return byte[]

GetFileKey() public static method

Calculates the decryption key for a file sector.
public static GetFileKey ( string fileName, bool isAdjusted = false, uint blockOffset, uint fileSize ) : uint
fileName string The name of the file the sector belongs to
isAdjusted bool If set to true, the key is adjusted by the given block offset and file size.
blockOffset uint The block offset of the file.
fileSize uint The size of the file.
return uint

Hash() public static method

Hashes an input string, given a hash type. This function is case-insensitive, and treats all input as being in ALL UPPER CASE.
public static Hash ( string inputString, HashType hashType ) : uint
inputString string Input string.
hashType HashType Hash type.
return uint

VerifySectorChecksum() public static method

Verifies the integrity of a file sector using an adler32 checksum.
public static VerifySectorChecksum ( byte sector, uint checksum ) : bool
sector byte Sector data.
checksum uint Sector checksum.
return bool