public RC5(byte[] key) { _bufKey = new uint[Constants.RC5_KEY]; _bufSub = new uint[Constants.RC5_SUB]; fixed(byte *pKey = key) { fixed(uint *pKey2 = _bufKey) { MSVCRT.memcpy(pKey2, pKey, Constants.RC5_16); } } _bufSub[0] = Constants.RC5_PW32; for (var i = 1; i < Constants.RC5_SUB; i++) { _bufSub[i] = _bufSub[i - 1] + Constants.RC5_QW32; } int ii, j; uint x, y; ii = j = 0; x = y = 0; for (var k = 0; k < 3 * Math.Max(Constants.RC5_KEY, Constants.RC5_SUB); k++) { _bufSub[ii] = RotateLeft(_bufSub[ii] + x + y, 3); x = _bufSub[ii]; ii = (ii + 1) % Constants.RC5_SUB; _bufKey[j] = RotateLeft(_bufKey[j] + x + y, (int)(x + y)); y = _bufKey[j]; j = (j + 1) % Constants.RC5_KEY; } }
public static void AppendNetStringPacker(byte *buffer, NetStringPacker packer) { var bufPacker = packer.ToArray(); fixed(byte *ptr = bufPacker) { MSVCRT.memcpy(buffer, ptr, bufPacker.Length); } }
private unsafe static void OnReceive(NetworkClient client, byte[] buffer) { if (client.Owner == null || !(client.Owner is Player)) { return; } var user = client.Owner as Player; user.Crypto.Decrypt(buffer); if (!user.UseThreading) { user.CompleteExchange(buffer); return; } #region Split fixed(byte *ptr = buffer) { var offset = 0; while (offset < buffer.Length) { var size = *((ushort *)(ptr + offset)) + 8; var type = *((ushort *)(ptr + offset + 2)); if (size < buffer.Length) { var sub = new byte[size]; fixed(byte *pSub = sub) { MSVCRT.memcpy(pSub, ptr + offset, size); ProcessPacket(user, pSub, sub, type); } } else if (size > buffer.Length) { user.Disconnect(); break; } else // size == buffer.Length { ProcessPacket(user, ptr, buffer, type); } offset += size; } } #endregion }
private void Receive(IAsyncResult result) { if (Socket != null) { try { SocketError error; int length = Socket.EndReceive(result, out error); if (Alive && error == SocketError.Success) { if (length > 0) { var received = new byte[length]; unsafe { fixed(byte *pReceive = received, pBuf = _buffer) { MSVCRT.memcpy(pReceive, pBuf, length); } } Server.InvokeOnReceive(this, received); BeginReceive(); } else { Server.InvokeOnDisconnect(this); } } } catch (SocketException) { Server.InvokeOnDisconnect(this); } } }
public unsafe byte[] GeneratePacket() { var pad = new byte[PAD_LENGTH]; var junk = new byte[JUNK_LENGTH]; Common.Random.NextBytes(pad); Common.Random.NextBytes(junk); var publicKey = _keyExchange.PublicKey.ToHexString(); var size = 28 + PAD_LENGTH + JUNK_LENGTH + _clientIV.Length + _serverIV.Length + P.Length + G.Length + publicKey.Length + 8; var buffer = new byte[size]; fixed(byte *ptr = buffer, pPad = pad, pJunk = junk, pClientIV = _clientIV, pServerIV = _serverIV) { var offset = 0; MSVCRT.memcpy(ptr + offset, pPad, PAD_LENGTH); offset += PAD_LENGTH; *((int *)(ptr + offset)) = size - PAD_LENGTH; offset += 4; *((int *)(ptr + offset)) = JUNK_LENGTH; offset += 4; MSVCRT.memcpy(ptr + offset, pJunk, JUNK_LENGTH); offset += JUNK_LENGTH; *((int *)(ptr + offset)) = _clientIV.Length; offset += 4; MSVCRT.memcpy(ptr + offset, pClientIV, _clientIV.Length); offset += _clientIV.Length; *((int *)(ptr + offset)) = _serverIV.Length; offset += 4; MSVCRT.memcpy(ptr + offset, pServerIV, _serverIV.Length); offset += _serverIV.Length; *((int *)(ptr + offset)) = P.Length; offset += 4; P.CopyTo(ptr + offset); offset += P.Length; *((int *)(ptr + offset)) = G.Length; offset += 4; G.CopyTo(ptr + offset); offset += G.Length; *((int *)(ptr + offset)) = publicKey.Length; offset += 4; publicKey.CopyTo(ptr + offset); offset += publicKey.Length; TQSERVER.CopyTo(ptr + offset); } return(buffer); }
public static bool VCRuntimeInstalled(MSVCRT version, int sp_level) { bool result = false; string regPath = ""; switch (version) { case MSVCRT.v2005: regPath = REG_VC2005; break; case MSVCRT.v2008: regPath = REG_VC2008; break; default: return(false); } try { RegistryKey key = Registry.LocalMachine; key = key.OpenSubKey(regPath); if (key == null) { return(false); } // Move one subkey down, since the redistributable is localized key = key.OpenSubKey(key.GetSubKeyNames()[0]); // check if installed object value = key.GetValue(REG_VAL_INSTALLED); if (value != null) { if (int.Parse(value.ToString()) == 1) { result = true; } } // check if SP level is equal to/higher than requested if (result && (sp_level > 0)) { value = key.GetValue(REG_VAL_SP); if (value != null) { result = (int.Parse(value.ToString()) >= sp_level); } } } catch (Exception ex) { result = false; System.Windows.Forms.MessageBox.Show( "An error occured while checking if the Visual C++ Runtime " + version.ToString() + " is installed" + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } return(result); }
public static bool VCRuntimeInstalled(MSVCRT version) { return(VCRuntimeInstalled(version, 0)); }
public static bool VCRuntimeInstalled(MSVCRT version, int sp_level) { bool result = false; string regPath = ""; switch (version) { case MSVCRT.v2005: regPath = REG_VC2005; break; case MSVCRT.v2008: regPath = REG_VC2008; break; default: return false; } try { RegistryKey key = Registry.LocalMachine; key = key.OpenSubKey(regPath); if (key == null) return false; // Move one subkey down, since the redistributable is localized key = key.OpenSubKey(key.GetSubKeyNames()[0]); // check if installed object value = key.GetValue(REG_VAL_INSTALLED); if (value != null) if (int.Parse(value.ToString()) == 1) result = true; // check if SP level is equal to/higher than requested if (result && (sp_level > 0)) { value = key.GetValue(REG_VAL_SP); if (value != null) result = (int.Parse(value.ToString()) >= sp_level); } } catch (Exception ex) { result = false; System.Windows.Forms.MessageBox.Show( "An error occured while checking if the Visual C++ Runtime " + version.ToString() + " is installed" + Environment.NewLine + Environment.NewLine + ex.ToString(), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } return result; }
public static bool VCRuntimeInstalled(MSVCRT version) { return VCRuntimeInstalled(version, 0); }