wzp
2021-07-28 864986e4cad03f6b9bba9a7e65379db496b62a6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace AsiaINFO.SMS.CMPP2
{
    using System;
    using System.Security.Cryptography;
    using System.Text;
 
    public class CMPP_CONNECT
    {
        private byte[] _AuthenticatorSource;
        private MessageHeader _Header;
        private string _Password;
        private string _Source_Addr;
        private uint _Timestamp;
        private uint _Version;
        public const int BodyLength = 0x1b;
 
        public CMPP_CONNECT(string Source_Addr, string Password, DateTime Timestamp, uint Version, uint Sequence_Id)
        {
            this._Header = new MessageHeader(0x27, CMPP_Command_Id.CMPP_CONNECT, Sequence_Id);
            this._Source_Addr = Source_Addr;
            this._Password = Password;
            string s = Util.Get_MMDDHHMMSS_String(Timestamp);
            this._Timestamp = uint.Parse(s);
            byte[] bytes = Encoding.ASCII.GetBytes(Source_Addr);
            byte[] sourceArray = Encoding.ASCII.GetBytes(Password);
            byte[] buffer3 = Encoding.ASCII.GetBytes(s);
            byte[] destinationArray = new byte[((bytes.Length + 9) + sourceArray.Length) + buffer3.Length];
            Array.Copy(bytes, destinationArray, bytes.Length);
            Array.Copy(sourceArray, 0, destinationArray, bytes.Length + 9, sourceArray.Length);
            Array.Copy(buffer3, 0, destinationArray, (bytes.Length + 9) + sourceArray.Length, buffer3.Length);
            this._AuthenticatorSource = new MD5CryptoServiceProvider().ComputeHash(destinationArray);
            this._Version = Version;
        }
 
        public byte[] ToBytes()
        {
            int dstOffset = 0;
            byte[] dst = new byte[0x27];
            byte[] src = this._Header.ToBytes();
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 12;
            src = Encoding.ASCII.GetBytes(this._Source_Addr);
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 6;
            src = this._AuthenticatorSource;
            Buffer.BlockCopy(src, 0, dst, dstOffset, src.Length);
            dstOffset += 0x10;
            dst[dstOffset++] = (byte) this._Version;
            src = BitConverter.GetBytes(this._Timestamp);
            Array.Reverse(src);
            src.CopyTo(dst, dstOffset);
            return dst;
        }
 
        public override string ToString()
        {
            return string.Format("Header={0}    AuthenticatorSource={1}    Password={2}    Source_Addr={3}    Timestamp={4}    Version={5}", new object[] { this._Header.ToString(), this._AuthenticatorSource, this._Password, this._Source_Addr, this._Timestamp, this._Version });
        }
 
        public byte[] AuthenticatorSource
        {
            get
            {
                return this._AuthenticatorSource;
            }
        }
 
        public MessageHeader Header
        {
            get
            {
                return this._Header;
            }
        }
    }
}