public static DecrypterV106 Create(IBinaryReader reader) { try { int keyXorOffs7 = (ReadByteAt(reader, 0) ^ ReadByteAt(reader, 2)) + 2; reader.Position = keyXorOffs7 + (ReadByteAt(reader, 1) ^ ReadByteAt(reader, keyXorOffs7)); int sha1DataLen = reader.Read7BitEncodedInt32() + 0x80; int keyXorOffs6 = (int)reader.Position; int encryptedOffs = (int)reader.Position + sha1DataLen; var sha1Data = reader.ReadBytes(sha1DataLen); uint crc32 = CRC32.CheckSum(sha1Data); reader.Position = reader.Length - 0x18; uint origCrc32 = reader.ReadUInt32(); if (crc32 != origCrc32) { return(null); } var key0 = DeobUtils.Sha1Sum(sha1Data); // 1.0.6.0 var key6 = GetKey(reader, key0, keyXorOffs6); // 1.0.6.6 var key7 = GetKey(reader, key0, keyXorOffs7); // 1.0.6.7 return(new DecrypterV106(key0, key6, key7, encryptedOffs)); } catch (IOException) { return(null); } }
public static byte[] DecryptCompressedInt32Data(Arg64ConstantsReader constReader, int exprStart, int exprEnd, IBinaryReader reader, byte[] decrypted) { for (int i = 0; i < decrypted.Length; i++) { constReader.Arg = reader.Read7BitEncodedInt32(); int index = exprStart; long result; if (!constReader.GetInt64(ref index, out result) || index != exprEnd) { throw new ApplicationException("Could not decrypt integer"); } decrypted[i] = (byte)result; } return(decrypted); }
/// <summary> /// Reads a <see cref="string"/> from the current position and increments /// <see cref="IBinaryReader.Position"/> by the length of the string. /// </summary> /// <param name="reader">this</param> /// <param name="encoding">Encoding</param> /// <returns>The string</returns> public static string ReadString(this IBinaryReader reader, Encoding encoding) { int len = reader.Read7BitEncodedInt32(); return(encoding.GetString(reader.ReadBytes(len))); }
public static DecrypterV106 Create(IBinaryReader reader) { try { int keyXorOffs7 = (ReadByteAt(reader, 0) ^ ReadByteAt(reader, 2)) + 2; reader.Position = keyXorOffs7 + (ReadByteAt(reader, 1) ^ ReadByteAt(reader, keyXorOffs7)); int sha1DataLen = reader.Read7BitEncodedInt32() + 0x80; int keyXorOffs6 = (int)reader.Position; int encryptedOffs = (int)reader.Position + sha1DataLen; var sha1Data = reader.ReadBytes(sha1DataLen); uint crc32 = CRC32.CheckSum(sha1Data); reader.Position = reader.Length - 0x18; uint origCrc32 = reader.ReadUInt32(); if (crc32 != origCrc32) return null; var key0 = DeobUtils.Sha1Sum(sha1Data); // 1.0.6.0 var key6 = GetKey(reader, key0, keyXorOffs6); // 1.0.6.6 var key7 = GetKey(reader, key0, keyXorOffs7); // 1.0.6.7 return new DecrypterV106(key0, key6, key7, encryptedOffs); } catch (IOException) { return null; } }
public static byte[] DecryptCompressedInt32Data(Arg64ConstantsReader constReader, int exprStart, int exprEnd, IBinaryReader reader, byte[] decrypted) { for (int i = 0; i < decrypted.Length; i++) { constReader.Arg = reader.Read7BitEncodedInt32(); int index = exprStart; long result; if (!constReader.GetInt64(ref index, out result) || index != exprEnd) throw new ApplicationException("Could not decrypt integer"); decrypted[i] = (byte)result; } return decrypted; }