Ported .Net Core commits:

hondacrx:
- Initial commit: Switch to .Net Core 2.0
- Fix build and removed not needed files
Fabi:
- Updated solution platforms.
- Changed folder structure.
- Change library target framework to netstandard2.0.
- Updated solution platforms again...
- Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
Fabian
2017-10-26 17:23:44 +02:00
parent 227702e19c
commit a3dc7b3f48
844 changed files with 26064 additions and 1824 deletions
@@ -0,0 +1,99 @@
/*
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Security.Cryptography;
namespace Framework.Cryptography
{
public sealed class WorldCrypt : IDisposable
{
static readonly byte[] ServerEncryptionKey = { 0x08, 0xF1, 0x95, 0x9F, 0x47, 0xE5, 0xD2, 0xDB, 0xA1, 0x3D, 0x77, 0x8F, 0x3F, 0x3E, 0xE7, 0x00 };
static readonly byte[] ServerDecryptionKey = { 0x40, 0xAA, 0xD3, 0x92, 0x26, 0x71, 0x43, 0x47, 0x3A, 0x31, 0x08, 0xA6, 0xE7, 0xDC, 0x98, 0x2A };
public void Initialize(byte[] sessionKey)
{
if (IsInitialized)
throw new InvalidOperationException("PacketCrypt already initialized!");
SARC4Encrypt = new SARC4();
SARC4Decrypt = new SARC4();
var encryptSHA1 = new HMACSHA1(ServerEncryptionKey);
var decryptSHA1 = new HMACSHA1(ServerDecryptionKey);
SARC4Encrypt.PrepareKey(encryptSHA1.ComputeHash(sessionKey));
SARC4Decrypt.PrepareKey(decryptSHA1.ComputeHash(sessionKey));
var PacketEncryptionDummy = new byte[0x400];
var PacketDecryptionDummy = new byte[0x400];
SARC4Encrypt.ProcessBuffer(PacketEncryptionDummy, PacketEncryptionDummy.Length);
SARC4Decrypt.ProcessBuffer(PacketDecryptionDummy, PacketDecryptionDummy.Length);
IsInitialized = true;
}
public void Initialize(byte[] sessionKey, byte[] serverSeed, byte[] clientSeed)
{
if (IsInitialized)
throw new InvalidOperationException("PacketCrypt already initialized!");
SARC4Encrypt = new SARC4();
SARC4Decrypt = new SARC4();
var encryptSHA1 = new HMACSHA1(serverSeed);
var decryptSHA1 = new HMACSHA1(clientSeed);
SARC4Encrypt.PrepareKey(encryptSHA1.ComputeHash(sessionKey));
SARC4Decrypt.PrepareKey(decryptSHA1.ComputeHash(sessionKey));
var PacketEncryptionDummy = new byte[0x400];
var PacketDecryptionDummy = new byte[0x400];
SARC4Encrypt.ProcessBuffer(PacketEncryptionDummy, PacketEncryptionDummy.Length);
SARC4Decrypt.ProcessBuffer(PacketDecryptionDummy, PacketDecryptionDummy.Length);
IsInitialized = true;
}
public void Encrypt(byte[] data, int count)
{
if (!IsInitialized)
throw new InvalidOperationException("PacketCrypt not initialized!");
SARC4Encrypt.ProcessBuffer(data, count);
}
public void Decrypt(byte[] data, int count)
{
if (!IsInitialized)
throw new InvalidOperationException("PacketCrypt not initialized!");
SARC4Decrypt.ProcessBuffer(data, count);
}
public void Dispose()
{
IsInitialized = false;
}
public bool IsInitialized { get; set; }
SARC4 SARC4Encrypt;
SARC4 SARC4Decrypt;
}
}
+117
View File
@@ -0,0 +1,117 @@
/*
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Numerics;
namespace Framework.Cryptography
{
public class RsaCrypt : IDisposable
{
public RsaCrypt()
{
Dispose();
}
public void InitializeEncryption<T>(T p, T q, T dp, T dq, T iq, bool isBigEndian = false)
{
this._p = p.ToBigInteger(isBigEndian);
this._q = q.ToBigInteger(isBigEndian);
this._dp = dp.ToBigInteger(isBigEndian);
this._dq = dq.ToBigInteger(isBigEndian);
this._iq = iq.ToBigInteger(isBigEndian);
if (this._p.IsZero && this._q.IsZero)
throw new InvalidOperationException("'0' isn't allowed for p or q");
else
_isEncryptionInitialized = true;
}
public void InitializeDecryption<T>(T e, T n, bool reverseBytes = false)
{
this._e = e.ToBigInteger(reverseBytes);
this._n = n.ToBigInteger(reverseBytes);
_isDecryptionInitialized = true;
}
public byte[] Encrypt<T>(T data, bool isBigEndian = false)
{
if (!_isEncryptionInitialized)
throw new InvalidOperationException("Encryption not initialized");
var bData = data.ToBigInteger(isBigEndian);
var m1 = BigInteger.ModPow(bData % _p, _dp, _p);
var m2 = BigInteger.ModPow(bData % _q, _dq, _q);
var h = (_iq * (m1 - m2)) % _p;
// Be sure to use the positive remainder
if (h.Sign == -1)
h = _p + h;
var m = m2 + h * _q;
return m.ToByteArray();
}
public byte[] Decrypt<T>(T data, bool isBigEndian = false)
{
if (!_isDecryptionInitialized)
throw new InvalidOperationException("Encryption not initialized");
var c = data.ToBigInteger(isBigEndian);
return BigInteger.ModPow(c, _e, _n).ToByteArray();
}
public void Dispose()
{
this._e = 0;
this._n = 0;
this._p = 0;
this._q = 0;
this._dp = 0;
this._dq = 0;
this._iq = 0;
_isEncryptionInitialized = false;
_isDecryptionInitialized = false;
}
BigInteger _e;
BigInteger _n;
BigInteger _p;
BigInteger _q;
BigInteger _dp;
BigInteger _dq;
BigInteger _iq;
bool _isEncryptionInitialized;
bool _isDecryptionInitialized;
}
public class RsaStore
{
public static byte[] DP = { 0xE1, 0xA6, 0x22, 0xAB, 0xFF, 0x57, 0x83, 0x45, 0x3F, 0x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 0x47, 0xA3, 0xEB, 0xCF, 0x6D, 0xC8, 0x96, 0x3A, 0x1B, 0x02, 0x52 };
public static byte[] P = { 0x7D, 0xBD, 0xB9, 0xE1, 0x2D, 0xAE, 0x42, 0x56, 0x6E, 0x2B, 0xE2, 0x89, 0xD9, 0xBB, 0x0C, 0x1F, 0x67, 0x28, 0xC1, 0x4D, 0x91, 0x3C, 0xAD, 0x5F, 0xF0, 0x43, 0x86, 0x5C, 0x27, 0xDC, 0x58, 0xB3, 0x0E, 0x75, 0x77, 0x78, 0x49, 0x35, 0xE7, 0xE7, 0xDF, 0xFD, 0x74, 0xAB, 0x4E, 0xFE, 0xD3, 0xAB, 0x6B, 0x96, 0xF7, 0x89, 0xB2, 0x5A, 0x6A, 0x25, 0x03, 0x5A, 0x92, 0x1A, 0xF1, 0xFC, 0x05, 0x4E, 0xCE, 0xDD, 0x37, 0xA4, 0x02, 0x53, 0x76, 0xCB, 0xC2, 0xD9, 0x63, 0xCB, 0x51, 0x94, 0xEC, 0x5C, 0x39, 0xCC, 0xB2, 0x17, 0x0C, 0xA3, 0x43, 0x9A, 0xD0, 0x83, 0x27, 0x67, 0x52, 0x64, 0x37, 0x0E, 0x38, 0xB7, 0x9B, 0xF4, 0x2D, 0xB8, 0x0F, 0x30, 0x72, 0xD3, 0x15, 0xF3, 0x2C, 0x39, 0x55, 0x72, 0x2C, 0x55, 0x80, 0x63, 0xA0, 0xA1, 0x6F, 0x28, 0xF3, 0xF3, 0x5A, 0x6F, 0x68, 0x59, 0xB3, 0xF3 };
public static byte[] Q = { 0x0B, 0x1A, 0x13, 0x07, 0x12, 0xEF, 0xDD, 0x97, 0x01, 0x9A, 0x21, 0x7D, 0xFA, 0xA3, 0xB7, 0xE2, 0x39, 0x2E, 0x04, 0x92, 0x96, 0x45, 0x2A, 0xEB, 0x57, 0x03, 0xAC, 0xB1, 0x83, 0xCD, 0x25, 0x4F, 0x2C, 0xA9, 0xA1, 0x54, 0x26, 0x54, 0xCF, 0xE6, 0x1B, 0x53, 0x51, 0x3A, 0xC1, 0x15, 0xF4, 0x17, 0xBB, 0x17, 0x1F, 0x37, 0x66, 0x36, 0x1A, 0xD4, 0xB1, 0x5B, 0x49, 0xA8, 0xF1, 0x02, 0xB0, 0x42, 0xA9, 0x66, 0xA0, 0xE2, 0x52, 0x2C, 0x8C, 0x89, 0xA2, 0xDD, 0xA6, 0xF1, 0xA3, 0xDF, 0xB6, 0x80, 0x63, 0xB8, 0x10, 0xDA, 0xDE, 0x84, 0x56, 0xFA, 0xFB, 0x72, 0x65, 0x5E, 0xA3, 0x9C, 0x78, 0x65, 0xD0, 0x73, 0x07, 0x34, 0x1D, 0xE1, 0x4D, 0x77, 0xE8, 0x00, 0x0F, 0x80, 0x1C, 0x5A, 0x21, 0x55, 0x0A, 0x8C, 0xF4, 0x93, 0xF5, 0xF8, 0x40, 0xF2, 0x40, 0xEA, 0x52, 0x12, 0x40, 0xF0, 0xBF, 0xFA };
public static byte[] WherePacketHmac = { 0x2C, 0x1F, 0x1D, 0x80, 0xC3, 0x8C, 0x23, 0x64, 0xDA, 0x90, 0xCA, 0x8E, 0x2C, 0xFC, 0x0C, 0xCE, 0x09, 0xD3, 0x62, 0xF9, 0xF3, 0x8B, 0xBE, 0x9F, 0x19, 0xEF, 0x58, 0xA1, 0x1C, 0x34, 0x14, 0x41, 0x3F, 0x23, 0xFD, 0xD3, 0xE8, 0x14, 0xEC, 0x2A, 0xFD, 0x4F, 0x95, 0xBA, 0x30, 0x7E, 0x56, 0x5D, 0x83, 0x95, 0x81, 0x69, 0xB0, 0x5A, 0xB4, 0x9D, 0xA8, 0x55, 0xFF, 0xFC, 0xEE, 0x58, 0x0A, 0x2F };
}
}
+68
View File
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2012-2014 Arctium Emulation<http://arctium.org>
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Framework.Cryptography
{
//Thx Fabian over at Arctium.
public sealed class SARC4
{
public SARC4()
{
_s = new byte[0x100];
_tmp = 0;
_tmp2 = 0;
}
public void PrepareKey(byte[] key)
{
for (int i = 0; i < 0x100; i++)
_s[i] = (byte)i;
var j = 0;
for (int i = 0; i < 0x100; i++)
{
j = (byte)((j + key[i % key.Length] + _s[i]) & 255);
var tempS = _s[i];
_s[i] = _s[j];
_s[j] = tempS;
}
}
public void ProcessBuffer(byte[] data, int length)
{
for (int i = 0; i < length; i++)
{
_tmp = (byte)((_tmp + 1) % 0x100);
_tmp2 = (byte)((_tmp2 + _s[_tmp]) % 0x100);
var sTemp = _s[_tmp];
_s[_tmp] = _s[_tmp2];
_s[_tmp2] = sTemp;
data[i] = (byte)(_s[(_s[_tmp] + _s[_tmp2]) % 0x100] ^ data[i]);
}
}
byte[] _s;
byte _tmp;
byte _tmp2;
}
}
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System.Security.Cryptography;
namespace Framework.Cryptography
{
public class SessionKeyGenerator
{
public SessionKeyGenerator(byte[] buff, int size)
{
int halfSize = size / 2;
sh = SHA256.Create();
sh.TransformFinalBlock(buff, 0, halfSize);
o1 = sh.Hash;
sh.Initialize();
sh.TransformFinalBlock(buff, halfSize, size - halfSize);
o2 = sh.Hash;
FillUp();
}
public void Generate(byte[] buf, uint sz)
{
for (uint i = 0; i < sz; ++i)
{
if (taken == 32)
FillUp();
buf[i] = o0[taken];
taken++;
}
}
void FillUp()
{
sh.Initialize();
sh.TransformBlock(o1, 0, 32, o1, 0);
sh.TransformBlock(o0, 0, 32, o0, 0);
sh.TransformFinalBlock(o2, 0, 32);
o0 = sh.Hash;
taken = 0;
}
SHA256 sh;
uint taken;
byte[] o0 = new byte[32];
byte[] o1 = new byte[32];
byte[] o2 = new byte[32];
}
}
+155
View File
@@ -0,0 +1,155 @@
/*
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
* Copyright (C) 2012-2014 Arctium Emulation <http://arctium.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Security.Cryptography;
using System.Text;
namespace Framework.Cryptography
{
public class Sha256
{
public byte[] Digest { get; private set; }
public Sha256()
{
sha.Initialize();
}
public void Process(byte[] data, int length)
{
sha.TransformBlock(data, 0, length, data, 0);
}
public void Process(uint data)
{
var bytes = BitConverter.GetBytes(data);
sha.TransformBlock(bytes, 0, 4, bytes, 0);
}
public void Process(string data)
{
var bytes = Encoding.UTF8.GetBytes(data);
sha.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
}
public void Finish(byte[] data, int length)
{
sha.TransformFinalBlock(data, 0, data.Length);
Digest = sha.Hash;
}
public void Finish(byte[] data, int offset, int length)
{
sha.TransformFinalBlock(data, offset, length);
Digest = sha.Hash;
}
SHA256 sha;
}
public class HmacHash : HMACSHA1
{
public byte[] Digest { get; private set; }
public HmacHash(byte[] key) : base(key, true)
{
Initialize();
}
public void Process(byte[] data, int length)
{
TransformBlock(data, 0, length, data, 0);
}
public void Process(uint data)
{
var bytes = BitConverter.GetBytes(data);
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
}
public void Process(string data)
{
var bytes = Encoding.ASCII.GetBytes(data);
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
}
public void Finish(byte[] data, int length)
{
TransformFinalBlock(data, 0, length);
Digest = Hash;
}
public void Finish(string data)
{
var bytes = Encoding.ASCII.GetBytes(data);
TransformFinalBlock(bytes, 0, bytes.Length);
Digest = Hash;
}
}
public class HmacSha256 : HMACSHA256
{
public HmacSha256() : base()
{
Initialize();
}
public HmacSha256(byte[] key) : base(key)
{
Initialize();
}
public void Process(byte[] data, int length)
{
TransformBlock(data, 0, length, data, 0);
}
public void Process(uint data)
{
var bytes = BitConverter.GetBytes(data);
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
}
public void Process(string data)
{
var bytes = Encoding.ASCII.GetBytes(data);
TransformBlock(bytes, 0, bytes.Length, bytes, 0);
}
public void Finish(byte[] data, int length)
{
TransformFinalBlock(data, 0, length);
Digest = Hash;
}
public byte[] Digest { get; private set; }
}
}