mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Merge pull request #37 from ORelio/Indev
Merging changes from Indev for 1.7.2 release
This commit is contained in:
commit
60ee2a3ddb
10 changed files with 415 additions and 136 deletions
|
|
@ -95,29 +95,25 @@ namespace MinecraftClient
|
|||
TranslationRules["commands.message.display.incoming"] = "§7%s whispers to you: %s";
|
||||
TranslationRules["commands.message.display.outgoing"] = "§7You whisper to %s: %s";
|
||||
|
||||
//Use translations from Minecraft assets if translation file is not found but a copy of the game is installed?
|
||||
if (!System.IO.File.Exists(Settings.TranslationsFile) //Try en_GB.lang
|
||||
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
|
||||
{
|
||||
Settings.TranslationsFile = Settings.TranslationsFile_FromMCDir;
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
ConsoleIO.WriteLine("Using en_GB.lang from your Minecraft directory.");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
//Language file in a subfolder, depending on the language setting
|
||||
if (!System.IO.Directory.Exists("lang"))
|
||||
System.IO.Directory.CreateDirectory("lang");
|
||||
|
||||
//Still not found? try downloading en_GB from Mojang's servers?
|
||||
if (!System.IO.File.Exists(Settings.TranslationsFile))
|
||||
string Language_File = "lang\\" + Settings.Language + ".lang";
|
||||
|
||||
//File not found? Try downloading language file from Mojang's servers?
|
||||
if (!System.IO.File.Exists(Language_File))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
ConsoleIO.WriteLine("Downloading en_GB.lang from Mojang's servers...");
|
||||
ConsoleIO.WriteLine("Downloading '" + Settings.Language + ".lang' from Mojang servers...");
|
||||
try
|
||||
{
|
||||
string assets_index = downloadString(Settings.TranslationsFile_Website_Index);
|
||||
string[] tmp = assets_index.Split(new string[] { "lang/en_GB.lang" }, StringSplitOptions.None);
|
||||
string[] tmp = assets_index.Split(new string[] { "lang/" + Settings.Language + ".lang" }, StringSplitOptions.None);
|
||||
tmp = tmp[1].Split(new string[] { "hash\": \"" }, StringSplitOptions.None);
|
||||
string hash = tmp[1].Split('"')[0]; //Translations file identifier on Mojang's servers
|
||||
System.IO.File.WriteAllText(Settings.TranslationsFile, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash));
|
||||
ConsoleIO.WriteLine("Done. File saved as \"" + Settings.TranslationsFile + '"');
|
||||
System.IO.File.WriteAllText(Language_File, downloadString(Settings.TranslationsFile_Website_Download + '/' + hash.Substring(0, 2) + '/' + hash));
|
||||
ConsoleIO.WriteLine("Done. File saved as '" + Language_File + '\'');
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -126,10 +122,20 @@ namespace MinecraftClient
|
|||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
//Load the external dictionnary of translation rules or display an error message
|
||||
if (System.IO.File.Exists(Settings.TranslationsFile))
|
||||
//Download Failed? Defaulting to en_GB.lang if the game is installed
|
||||
if (!System.IO.File.Exists(Language_File) //Try en_GB.lang
|
||||
&& System.IO.File.Exists(Settings.TranslationsFile_FromMCDir))
|
||||
{
|
||||
string[] translations = System.IO.File.ReadAllLines(Settings.TranslationsFile);
|
||||
Language_File = Settings.TranslationsFile_FromMCDir;
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
ConsoleIO.WriteLine("Defaulting to en_GB.lang from your Minecraft directory.");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
//Load the external dictionnary of translation rules or display an error message
|
||||
if (System.IO.File.Exists(Language_File))
|
||||
{
|
||||
string[] translations = System.IO.File.ReadAllLines(Language_File);
|
||||
foreach (string line in translations)
|
||||
{
|
||||
if (line.Length > 0)
|
||||
|
|
@ -149,8 +155,7 @@ namespace MinecraftClient
|
|||
else //No external dictionnary found.
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
ConsoleIO.WriteLine("Translations file not found: \"" + Settings.TranslationsFile + "\""
|
||||
+ "\nYou can pick a translation file from .minecraft\\assets\\lang\\"
|
||||
ConsoleIO.WriteLine("Translations file not found: \"" + Language_File + "\""
|
||||
+ "\nSome messages won't be properly printed without this file.");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,110 +3,211 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Security.Cryptography;
|
||||
using java.security;
|
||||
using java.security.spec;
|
||||
using javax.crypto;
|
||||
using javax.crypto.spec;
|
||||
|
||||
namespace MinecraftClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Cryptographic functions ported from Minecraft Source Code (Java). Decompiled with MCP. Copy, paste, little adjustements.
|
||||
/// Methods for handling all the crypto stuff: RSA (Encryption Key Request), AES (Encrypted Stream), SHA-1 (Server Hash).
|
||||
/// </summary>
|
||||
|
||||
public class Crypto
|
||||
{
|
||||
public static PublicKey GenerateRSAPublicKey(byte[] key)
|
||||
{
|
||||
X509EncodedKeySpec localX509EncodedKeySpec = new X509EncodedKeySpec(key);
|
||||
KeyFactory localKeyFactory = KeyFactory.getInstance("RSA");
|
||||
return localKeyFactory.generatePublic(localX509EncodedKeySpec);
|
||||
}
|
||||
/// <summary>
|
||||
/// Get a cryptographic service for encrypting data using the server's RSA public key
|
||||
/// </summary>
|
||||
/// <param name="key">Byte array containing the encoded key</param>
|
||||
/// <returns>Returns the corresponding RSA Crypto Service</returns>
|
||||
|
||||
public static SecretKey GenerateAESPrivateKey()
|
||||
public static RSACryptoServiceProvider DecodeRSAPublicKey(byte[] x509key)
|
||||
{
|
||||
AesManaged aes = new AesManaged();
|
||||
aes.KeySize = 128; aes.GenerateKey();
|
||||
return new SecretKeySpec(aes.Key, "AES");
|
||||
}
|
||||
/* Code from StackOverflow no. 18091460 */
|
||||
|
||||
public static byte[] getServerHash(String toencode, PublicKey par1PublicKey, SecretKey par2SecretKey)
|
||||
{
|
||||
return digest("SHA-1", new byte[][] { Encoding.GetEncoding("iso-8859-1").GetBytes(toencode), par2SecretKey.getEncoded(), par1PublicKey.getEncoded() });
|
||||
}
|
||||
byte[] SeqOID = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 };
|
||||
|
||||
public static byte[] Encrypt(Key par0Key, byte[] par1ArrayOfByte)
|
||||
{
|
||||
return func_75885_a(1, par0Key, par1ArrayOfByte);
|
||||
}
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream(x509key);
|
||||
System.IO.BinaryReader reader = new System.IO.BinaryReader(ms);
|
||||
|
||||
private static byte[] digest(String par0Str, byte[][] par1ArrayOfByte)
|
||||
{
|
||||
MessageDigest var2 = MessageDigest.getInstance(par0Str);
|
||||
byte[][] var3 = par1ArrayOfByte;
|
||||
int var4 = par1ArrayOfByte.Length;
|
||||
|
||||
for (int var5 = 0; var5 < var4; ++var5)
|
||||
{
|
||||
byte[] var6 = var3[var5];
|
||||
var2.update(var6);
|
||||
}
|
||||
|
||||
return var2.digest();
|
||||
}
|
||||
private static byte[] func_75885_a(int par0, Key par1Key, byte[] par2ArrayOfByte)
|
||||
{
|
||||
try
|
||||
{
|
||||
return cypherencrypt(par0, par1Key.getAlgorithm(), par1Key).doFinal(par2ArrayOfByte);
|
||||
}
|
||||
catch (IllegalBlockSizeException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
}
|
||||
catch (BadPaddingException var5)
|
||||
{
|
||||
var5.printStackTrace();
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("Cipher data failed!");
|
||||
if (reader.ReadByte() == 0x30)
|
||||
ReadASNLength(reader); //skip the size
|
||||
else
|
||||
return null;
|
||||
}
|
||||
private static Cipher cypherencrypt(int par0, String par1Str, Key par2Key)
|
||||
{
|
||||
try
|
||||
{
|
||||
Cipher var3 = Cipher.getInstance(par1Str);
|
||||
var3.init(par0, par2Key);
|
||||
return var3;
|
||||
}
|
||||
catch (InvalidKeyException var4)
|
||||
{
|
||||
var4.printStackTrace();
|
||||
}
|
||||
catch (NoSuchAlgorithmException var5)
|
||||
{
|
||||
var5.printStackTrace();
|
||||
}
|
||||
catch (NoSuchPaddingException var6)
|
||||
{
|
||||
var6.printStackTrace();
|
||||
}
|
||||
|
||||
Console.Error.WriteLine("Cipher creation failed!");
|
||||
int identifierSize = 0; //total length of Object Identifier section
|
||||
if (reader.ReadByte() == 0x30)
|
||||
identifierSize = ReadASNLength(reader);
|
||||
else
|
||||
return null;
|
||||
|
||||
if (reader.ReadByte() == 0x06) //is the next element an object identifier?
|
||||
{
|
||||
int oidLength = ReadASNLength(reader);
|
||||
byte[] oidBytes = new byte[oidLength];
|
||||
reader.Read(oidBytes, 0, oidBytes.Length);
|
||||
if (oidBytes.SequenceEqual(SeqOID) == false) //is the object identifier rsaEncryption PKCS#1?
|
||||
return null;
|
||||
|
||||
int remainingBytes = identifierSize - 2 - oidBytes.Length;
|
||||
reader.ReadBytes(remainingBytes);
|
||||
}
|
||||
|
||||
public static AesStream SwitchToAesMode(System.IO.Stream stream, Key key)
|
||||
if (reader.ReadByte() == 0x03) //is the next element a bit string?
|
||||
{
|
||||
return new AesStream(stream, key.getEncoded());
|
||||
ReadASNLength(reader); //skip the size
|
||||
reader.ReadByte(); //skip unused bits indicator
|
||||
if (reader.ReadByte() == 0x30)
|
||||
{
|
||||
ReadASNLength(reader); //skip the size
|
||||
if (reader.ReadByte() == 0x02) //is it an integer?
|
||||
{
|
||||
int modulusSize = ReadASNLength(reader);
|
||||
byte[] modulus = new byte[modulusSize];
|
||||
reader.Read(modulus, 0, modulus.Length);
|
||||
if (modulus[0] == 0x00) //strip off the first byte if it's 0
|
||||
{
|
||||
byte[] tempModulus = new byte[modulus.Length - 1];
|
||||
Array.Copy(modulus, 1, tempModulus, 0, modulus.Length - 1);
|
||||
modulus = tempModulus;
|
||||
}
|
||||
|
||||
if (reader.ReadByte() == 0x02) //is it an integer?
|
||||
{
|
||||
int exponentSize = ReadASNLength(reader);
|
||||
byte[] exponent = new byte[exponentSize];
|
||||
reader.Read(exponent, 0, exponent.Length);
|
||||
|
||||
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
|
||||
RSAParameters RSAKeyInfo = new RSAParameters();
|
||||
RSAKeyInfo.Modulus = modulus;
|
||||
RSAKeyInfo.Exponent = exponent;
|
||||
RSA.ImportParameters(RSAKeyInfo);
|
||||
return RSA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES
|
||||
/// Subfunction for decrypting ASN.1 (x509) RSA certificate data fields lengths
|
||||
/// </summary>
|
||||
/// <param name="reader">StreamReader containing the stream to decode</param>
|
||||
/// <returns>Return the read length</returns>
|
||||
|
||||
private static int ReadASNLength(System.IO.BinaryReader reader)
|
||||
{
|
||||
//Note: this method only reads lengths up to 4 bytes long as
|
||||
//this is satisfactory for the majority of situations.
|
||||
int length = reader.ReadByte();
|
||||
if ((length & 0x00000080) == 0x00000080) //is the length greater than 1 byte
|
||||
{
|
||||
int count = length & 0x0000000f;
|
||||
byte[] lengthBytes = new byte[4];
|
||||
reader.Read(lengthBytes, 4 - count, count);
|
||||
Array.Reverse(lengthBytes); //
|
||||
length = BitConverter.ToInt32(lengthBytes, 0);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a new random AES key for symmetric encryption
|
||||
/// </summary>
|
||||
/// <returns>Returns a byte array containing the key</returns>
|
||||
|
||||
public static byte[] GenerateAESPrivateKey()
|
||||
{
|
||||
AesManaged AES = new AesManaged();
|
||||
AES.KeySize = 128; AES.GenerateKey();
|
||||
return AES.Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a SHA-1 hash for online-mode session checking
|
||||
/// </summary>
|
||||
/// <param name="serverID">Server ID hash</param>
|
||||
/// <param name="PublicKey">Server's RSA key</param>
|
||||
/// <param name="SecretKey">Secret key chosen by the client</param>
|
||||
/// <returns>Returns the corresponding SHA-1 hex hash</returns>
|
||||
|
||||
public static string getServerHash(string serverID, byte[] PublicKey, byte[] SecretKey)
|
||||
{
|
||||
byte[] hash = digest(new byte[][] { Encoding.GetEncoding("iso-8859-1").GetBytes(serverID), SecretKey, PublicKey });
|
||||
bool negative = (hash[0] & 0x80) == 0x80;
|
||||
if (negative) { hash = TwosComplementLittleEndian(hash); }
|
||||
string result = GetHexString(hash).TrimStart('0');
|
||||
if (negative) { result = "-" + result; }
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a SHA-1 hash using several byte arrays
|
||||
/// </summary>
|
||||
/// <param name="tohash">array of byte arrays to hash</param>
|
||||
/// <returns>Returns the hashed data</returns>
|
||||
|
||||
private static byte[] digest(byte[][] tohash)
|
||||
{
|
||||
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
|
||||
for (int i = 0; i < tohash.Length; i++)
|
||||
sha1.TransformBlock(tohash[i], 0, tohash[i].Length, tohash[i], 0);
|
||||
sha1.TransformFinalBlock(new byte[] { }, 0, 0);
|
||||
return sha1.Hash;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a byte array to its hex string representation
|
||||
/// </summary>
|
||||
/// <param name="p">Byte array to convert</param>
|
||||
/// <returns>Returns the string representation</returns>
|
||||
|
||||
private static string GetHexString(byte[] p)
|
||||
{
|
||||
string result = string.Empty;
|
||||
for (int i = 0; i < p.Length; i++)
|
||||
result += p[i].ToString("x2");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute the two's complement of a little endian byte array
|
||||
/// </summary>
|
||||
/// <param name="p">Byte array to compute</param>
|
||||
/// <returns>Returns the corresponding two's complement</returns>
|
||||
|
||||
private static byte[] TwosComplementLittleEndian(byte[] p)
|
||||
{
|
||||
int i;
|
||||
bool carry = true;
|
||||
for (i = p.Length - 1; i >= 0; i--)
|
||||
{
|
||||
p[i] = (byte)~p[i];
|
||||
if (carry)
|
||||
{
|
||||
carry = p[i] == 0xFF;
|
||||
p[i]++;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for AES stream
|
||||
/// Allows to use any object which has a Read() and Write() method.
|
||||
/// </summary>
|
||||
|
||||
public class AesStream : System.IO.Stream
|
||||
public interface IAesStream
|
||||
{
|
||||
int Read(byte[] buffer, int offset, int count);
|
||||
void Write(byte[] buffer, int offset, int count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
||||
/// This is the regular AesStream class used with the regular .NET framework from Microsoft.
|
||||
/// </summary>
|
||||
|
||||
public class AesStream : System.IO.Stream, IAesStream
|
||||
{
|
||||
CryptoStream enc;
|
||||
CryptoStream dec;
|
||||
|
|
@ -197,5 +298,143 @@ namespace MinecraftClient
|
|||
return cipher;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An encrypted stream using AES, used for encrypting network data on the fly using AES.
|
||||
/// This is a mono-compatible adaptation which only sends and receive 16 bytes at a time, and manually transforms blocks.
|
||||
/// Data is cached before reaching the 128bits block size necessary for mono which is not CFB-8 compatible.
|
||||
/// </summary>
|
||||
|
||||
public class MonoAesStream : System.IO.Stream, IAesStream
|
||||
{
|
||||
ICryptoTransform enc;
|
||||
ICryptoTransform dec;
|
||||
List<byte> dec_cache = new List<byte>();
|
||||
List<byte> tosend_cache = new List<byte>();
|
||||
public MonoAesStream(System.IO.Stream stream, byte[] key)
|
||||
{
|
||||
BaseStream = stream;
|
||||
RijndaelManaged aes = GenerateAES(key);
|
||||
enc = aes.CreateEncryptor();
|
||||
dec = aes.CreateDecryptor();
|
||||
}
|
||||
public System.IO.Stream BaseStream { get; set; }
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
BaseStream.Flush();
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
public override int ReadByte()
|
||||
{
|
||||
byte[] temp = new byte[1];
|
||||
Read(temp, 0, 1);
|
||||
return temp[0];
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
while (dec_cache.Count < count)
|
||||
{
|
||||
byte[] temp_in = new byte[16];
|
||||
byte[] temp_out = new byte[16];
|
||||
int read = 0;
|
||||
while (read < 16)
|
||||
read += BaseStream.Read(temp_in, read, 16 - read);
|
||||
dec.TransformBlock(temp_in, 0, 16, temp_out, 0);
|
||||
foreach (byte b in temp_out)
|
||||
dec_cache.Add(b);
|
||||
}
|
||||
|
||||
for (int i = offset; i - offset < count; i++)
|
||||
{
|
||||
buffer[i] = dec_cache[0];
|
||||
dec_cache.RemoveAt(0);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, System.IO.SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void WriteByte(byte b)
|
||||
{
|
||||
Write(new byte[] { b }, 0, 1);
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
for (int i = offset; i - offset < count; i++)
|
||||
tosend_cache.Add(buffer[i]);
|
||||
|
||||
if (tosend_cache.Count < 16)
|
||||
tosend_cache.AddRange(MinecraftCom.getPaddingPacket());
|
||||
|
||||
while (tosend_cache.Count > 16)
|
||||
{
|
||||
byte[] temp_in = new byte[16];
|
||||
byte[] temp_out = new byte[16];
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
temp_in[i] = tosend_cache[0];
|
||||
tosend_cache.RemoveAt(0);
|
||||
}
|
||||
enc.TransformBlock(temp_in, 0, 16, temp_out, 0);
|
||||
BaseStream.Write(temp_out, 0, 16);
|
||||
}
|
||||
}
|
||||
|
||||
private RijndaelManaged GenerateAES(byte[] key)
|
||||
{
|
||||
RijndaelManaged cipher = new RijndaelManaged();
|
||||
cipher.Mode = CipherMode.CFB;
|
||||
cipher.Padding = PaddingMode.None;
|
||||
cipher.KeySize = 128;
|
||||
cipher.FeedbackSize = 8;
|
||||
cipher.Key = key;
|
||||
cipher.IV = key;
|
||||
return cipher;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,18 +60,6 @@
|
|||
</PropertyGroup>
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Reference Include="IKVM.OpenJDK.Core, Version=7.0.4335.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\IKVM.OpenJDK.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IKVM.OpenJDK.Security, Version=7.0.4335.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\IKVM.OpenJDK.Security.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IKVM.OpenJDK.Util, Version=7.0.4335.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>.\IKVM.OpenJDK.Util.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
|
@ -116,10 +104,6 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="resources\appicon.ico" />
|
||||
<Content Include="lib\IKVM.OpenJDK.Core.dll" />
|
||||
<Content Include="lib\IKVM.OpenJDK.Security.dll" />
|
||||
<Content Include="lib\IKVM.OpenJDK.Util.dll" />
|
||||
<Content Include="lib\IKVM.Runtime.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace MinecraftClient
|
|||
{
|
||||
#region Login to Minecraft.net and get a new session ID
|
||||
|
||||
public enum LoginResult { Error, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
|
||||
public enum LoginResult { OtherError, SSLError, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
|
||||
|
||||
/// <summary>
|
||||
/// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme.
|
||||
|
|
@ -68,7 +68,11 @@ namespace MinecraftClient
|
|||
}
|
||||
else return LoginResult.Blocked;
|
||||
}
|
||||
else return LoginResult.Error;
|
||||
else if (e.Status == WebExceptionStatus.SendFailure)
|
||||
{
|
||||
return LoginResult.SSLError;
|
||||
}
|
||||
else return LoginResult.OtherError;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +103,7 @@ namespace MinecraftClient
|
|||
#endregion
|
||||
|
||||
TcpClient c = new TcpClient();
|
||||
Crypto.AesStream s;
|
||||
Crypto.IAesStream s;
|
||||
|
||||
public bool HasBeenKicked { get { return connectionlost; } }
|
||||
bool connectionlost = false;
|
||||
|
|
@ -236,6 +240,18 @@ namespace MinecraftClient
|
|||
}
|
||||
return i;
|
||||
}
|
||||
public static byte[] getPaddingPacket()
|
||||
{
|
||||
//Will generate a 15-bytes long padding packet
|
||||
byte[] id = getVarInt(0x17); //Plugin Message
|
||||
byte[] channel_name = Encoding.UTF8.GetBytes("MCC|Pad");
|
||||
byte[] channel_name_len = getVarInt(channel_name.Length);
|
||||
byte[] data = new byte[] { 0x00, 0x00, 0x00 };
|
||||
byte[] data_len = BitConverter.GetBytes((short)data.Length); Array.Reverse(data_len);
|
||||
byte[] packet_data = concatBytes(id, channel_name_len, channel_name, data_len, data);
|
||||
byte[] packet_length = getVarInt(packet_data.Length);
|
||||
return concatBytes(packet_length, packet_data);
|
||||
}
|
||||
private static byte[] getVarInt(int paramInt)
|
||||
{
|
||||
List<byte> bytes = new List<byte>();
|
||||
|
|
@ -330,7 +346,7 @@ namespace MinecraftClient
|
|||
|
||||
public void setVersion(int ver) { protocolversion = ver; }
|
||||
public void setClient(TcpClient n) { c = n; }
|
||||
private void setEncryptedClient(Crypto.AesStream n) { s = n; encrypted = true; }
|
||||
private void setEncryptedClient(Crypto.IAesStream n) { s = n; encrypted = true; }
|
||||
private void Receive(byte[] buffer, int start, int offset, SocketFlags f)
|
||||
{
|
||||
if (encrypted)
|
||||
|
|
@ -398,10 +414,17 @@ namespace MinecraftClient
|
|||
{
|
||||
string[] tmp_ver = result.Split(new string[] { "protocol\":" }, StringSplitOptions.None);
|
||||
string[] tmp_name = result.Split(new string[] { "name\":\"" }, StringSplitOptions.None);
|
||||
|
||||
if (tmp_ver.Length >= 2 && tmp_name.Length >= 2)
|
||||
{
|
||||
protocolversion = atoi(tmp_ver[1]);
|
||||
version = tmp_name[1].Split('"')[0];
|
||||
if (result.Contains("modinfo\":"))
|
||||
{
|
||||
//Server is running Forge (which is not supported)
|
||||
version = "Forge " + version;
|
||||
protocolversion = 0;
|
||||
}
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
//Console.WriteLine(result); //Debug: show the full Json string
|
||||
Console.WriteLine("Server version : " + version + " (protocol v" + protocolversion + ").");
|
||||
|
|
@ -455,11 +478,9 @@ namespace MinecraftClient
|
|||
else if (pid == 0x01) //Encryption request
|
||||
{
|
||||
string serverID = readNextString();
|
||||
byte[] Serverkey_RAW = readNextByteArray();
|
||||
byte[] Serverkey = readNextByteArray();
|
||||
byte[] token = readNextByteArray();
|
||||
var PublicServerkey = Crypto.GenerateRSAPublicKey(Serverkey_RAW);
|
||||
var SecretKey = Crypto.GenerateAESPrivateKey();
|
||||
return StartEncryption(uuid, sessionID, token, serverID, PublicServerkey, SecretKey);
|
||||
return StartEncryption(uuid, sessionID, token, serverID, Serverkey);
|
||||
}
|
||||
else if (pid == 0x02) //Login successfull
|
||||
{
|
||||
|
|
@ -470,8 +491,11 @@ namespace MinecraftClient
|
|||
}
|
||||
else return false;
|
||||
}
|
||||
public bool StartEncryption(string uuid, string sessionID, byte[] token, string serverIDhash, java.security.PublicKey serverKey, javax.crypto.SecretKey secretKey)
|
||||
public bool StartEncryption(string uuid, string sessionID, byte[] token, string serverIDhash, byte[] serverKey)
|
||||
{
|
||||
System.Security.Cryptography.RSACryptoServiceProvider RSAService = Crypto.DecodeRSAPublicKey(serverKey);
|
||||
byte[] secretKey = Crypto.GenerateAESPrivateKey();
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
ConsoleIO.WriteLine("Crypto keys & hash generated.");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
|
|
@ -479,15 +503,15 @@ namespace MinecraftClient
|
|||
if (serverIDhash != "-")
|
||||
{
|
||||
Console.WriteLine("Checking Session...");
|
||||
if (!SessionCheck(uuid, sessionID, new java.math.BigInteger(Crypto.getServerHash(serverIDhash, serverKey, secretKey)).toString(16)))
|
||||
if (!SessionCheck(uuid, sessionID, Crypto.getServerHash(serverIDhash, serverKey, secretKey)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Encrypt the data
|
||||
byte[] key_enc = Crypto.Encrypt(serverKey, secretKey.getEncoded());
|
||||
byte[] token_enc = Crypto.Encrypt(serverKey, token);
|
||||
byte[] key_enc = RSAService.Encrypt(secretKey, false);
|
||||
byte[] token_enc = RSAService.Encrypt(token, false);
|
||||
byte[] key_len = BitConverter.GetBytes((short)key_enc.Length); Array.Reverse(key_len);
|
||||
byte[] token_len = BitConverter.GetBytes((short)token_enc.Length); Array.Reverse(token_len);
|
||||
|
||||
|
|
@ -498,7 +522,10 @@ namespace MinecraftClient
|
|||
Send(encryption_response_tosend);
|
||||
|
||||
//Start client-side encryption
|
||||
setEncryptedClient(Crypto.SwitchToAesMode(c.GetStream(), secretKey));
|
||||
Crypto.IAesStream encrypted;
|
||||
if (Program.isUsingMono) { encrypted = new Crypto.MonoAesStream(c.GetStream(), secretKey); }
|
||||
else encrypted = new Crypto.AesStream(c.GetStream(), secretKey);
|
||||
setEncryptedClient(encrypted);
|
||||
|
||||
//Get the next packet
|
||||
readNextVarInt(); //Skip Packet size (not needed)
|
||||
|
|
@ -552,6 +579,7 @@ namespace MinecraftClient
|
|||
}
|
||||
catch (SocketException) { }
|
||||
catch (System.IO.IOException) { }
|
||||
catch (NullReferenceException) { }
|
||||
}
|
||||
|
||||
private List<ChatBot> bots = new List<ChatBot>();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
namespace MinecraftClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Minecraft Console Client by ORelio (c) 2012-2013.
|
||||
/// Minecraft Console Client by ORelio (c) 2012-2014.
|
||||
/// Allows to connect to any Minecraft server, send and receive text, automated scripts.
|
||||
/// This source code is released under the CDDL 1.0 License.
|
||||
/// </summary>
|
||||
|
|
@ -15,7 +15,7 @@ namespace MinecraftClient
|
|||
{
|
||||
private static McTcpClient Client;
|
||||
public static string[] startupargs;
|
||||
public const string Version = "1.7.1";
|
||||
public const string Version = "1.7.2";
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point of Minecraft Console Client
|
||||
|
|
@ -23,7 +23,7 @@ namespace MinecraftClient
|
|||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Console Client for MC 1.7.2 to 1.7.4 - v" + Version + " - By ORelio & Contributors");
|
||||
Console.WriteLine("Console Client for MC 1.7.2 to 1.7.5 - v" + Version + " - By ORelio & Contributors");
|
||||
|
||||
//Basic Input/Output ?
|
||||
if (args.Length >= 1 && args[args.Length - 1] == "BasicIO")
|
||||
|
|
@ -279,7 +279,18 @@ namespace MinecraftClient
|
|||
case MinecraftCom.LoginResult.Blocked: Console.WriteLine("Too many failed logins. Please try again later."); break;
|
||||
case MinecraftCom.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break;
|
||||
case MinecraftCom.LoginResult.NotPremium: Console.WriteLine("User not premium."); break;
|
||||
case MinecraftCom.LoginResult.Error: Console.WriteLine("Network error."); break;
|
||||
case MinecraftCom.LoginResult.OtherError: Console.WriteLine("Network error."); break;
|
||||
case MinecraftCom.LoginResult.SSLError: Console.WriteLine("SSL Error.");
|
||||
if (isUsingMono)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.WriteLine("It appears that you are using Mono to run this program."
|
||||
+ '\n' + "The first time, you have to import HTTPS certificates using:"
|
||||
+ '\n' + "mozroots --import --ask-remove");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
while (Console.KeyAvailable) { Console.ReadKey(false); }
|
||||
if (Settings.SingleCommand == "") { ReadLineReconnect(); }
|
||||
|
|
@ -320,6 +331,18 @@ namespace MinecraftClient
|
|||
else return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect if the user is running Minecraft Console Client through Mono
|
||||
/// </summary>
|
||||
|
||||
public static bool isUsingMono
|
||||
{
|
||||
get
|
||||
{
|
||||
return Type.GetType("Mono.Runtime") != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Private thread for restarting the program. Called through Restart()
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace MinecraftClient
|
|||
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang
|
||||
public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json";
|
||||
public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net";
|
||||
public static string TranslationsFile = "translations.lang";
|
||||
public static string Bots_OwnersFile = "bot-owners.txt";
|
||||
public static string Language = "en_GB";
|
||||
|
||||
//AntiAFK Settings
|
||||
public static bool AntiAFK_Enabled = false;
|
||||
|
|
@ -121,7 +121,7 @@ namespace MinecraftClient
|
|||
case "password": Password = argValue; break;
|
||||
case "serverip": ServerIP = argValue; break;
|
||||
case "singlecommand": SingleCommand = argValue; break;
|
||||
case "translationsfile": TranslationsFile = argValue; break;
|
||||
case "language": Language = argValue; break;
|
||||
case "botownersfile": Bots_OwnersFile = argValue; break;
|
||||
case "consoletitle": ConsoleTitle = argValue; break;
|
||||
}
|
||||
|
|
@ -212,9 +212,9 @@ namespace MinecraftClient
|
|||
+ "\r\n"
|
||||
+ "#Advanced settings\r\n"
|
||||
+ "\r\n"
|
||||
+ "translationsfile=translations.lang\r\n"
|
||||
+ "language=en_GB\r\n"
|
||||
+ "botownersfile=bot-owners.txt\r\n"
|
||||
+ "consoletitle=Minecraft Console Client - %username%\r\n"
|
||||
+ "consoletitle=%username% - Minecraft Console Client\r\n"
|
||||
+ "\r\n"
|
||||
+ "#Bot Settings\r\n"
|
||||
+ "\r\n"
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue