Exemple #1
0
 public ecTagMD5(ECTagNames n, string s, bool string_is_hash)
     : base(n, EcTagTypes.EC_TAGTYPE_HASH16)
 {
     if (string_is_hash)
     {
         // in this case hash is passed as hex string
         if (s.Length != 16 * 2)
         {
             throw new Exception("md5 hash of proto version have incorrect length");
         }
         //byte[] hash_str = s.ToCharArray();
         for (int i = 0; i < 16; i++)
         {
             string v = s.Substring(i * 2, 2);
         }
         m_val = new byte[16];
     }
     else
     {
         MD5CryptoServiceProvider p = new MD5CryptoServiceProvider();
         byte[] bs = System.Text.Encoding.UTF8.GetBytes(s);
         m_val = p.ComputeHash(bs);
     }
     m_size = 16;
 }
Exemple #2
0
 public ecTagIPv4(ECTagNames name, BinaryReader br, LinkedList <ecTag> subtags)
     : base(name, EcTagTypes.EC_TAGTYPE_IPV4, subtags)
 {
     m_size = 4 + 2;
     m_addr = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt32());
     m_port = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt16());
 }
Exemple #3
0
            public ecTagString(ECTagNames n, Int32 tag_size, BinaryReader br, LinkedList <ecTag> subtags)
                : base(n, EcTagTypes.EC_TAGTYPE_STRING, subtags)
            {
                byte[] buf = br.ReadBytes(tag_size - 1);
                // discard trailing '0'
                br.ReadBytes(1);

                m_size = tag_size;
                m_val  = buf;
            }
Exemple #4
0
 public ecTag SubTag(ECTagNames name)
 {
     foreach (ecTag t in m_subtags)
     {
         if (t.m_name == name)
         {
             return(t);
         }
     }
     return(null);
 }
Exemple #5
0
            public ecTagInt(ECTagNames n, Int32 tag_size, BinaryReader br, LinkedList <ecTag> subtags)
                : base(n, EcTagTypes.EC_TAGTYPE_UINT8, subtags)
            {
                m_size = tag_size;
                UInt64 raw_val;
                Int32  hi, lo, v32;
                Int16  v16;

                switch (m_size)
                {
                case 8:
                    m_type  = EcTagTypes.EC_TAGTYPE_UINT64;
                    lo      = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt32());
                    hi      = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt32());
                    raw_val = ((UInt64)hi) << 32 | (UInt32)lo;
                    break;

                case 4:
                    m_type  = EcTagTypes.EC_TAGTYPE_UINT32;
                    v32     = (System.Net.IPAddress.NetworkToHostOrder(br.ReadInt32()));
                    raw_val = (UInt32)v32;
                    break;

                case 2:
                    m_type  = EcTagTypes.EC_TAGTYPE_UINT16;
                    v16     = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt16());
                    raw_val = (UInt16)v16;
                    break;

                case 1:
                    m_type  = EcTagTypes.EC_TAGTYPE_UINT8;
                    raw_val = (UInt64)br.ReadByte();
                    break;

                default:
                    throw new Exception("Unexpected size of data in integer tag");
                }
                m_val = (Int64)raw_val;
                if (m_val < 0)
                {
                    throw new Exception("WTF - typecasting is broken?!");
                }
            }
Exemple #6
0
 public ecTag(ECTagNames n, EcTagTypes t)
 {
     m_name    = n;
     m_type    = t;
     m_subtags = new LinkedList <ecTag>();
 }
Exemple #7
0
            //
            // Parsing ctor
            //
            ecTag ReadTag(BinaryReader br)
            {
                ecTag      t            = null;
                Int16      tag_name16   = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt16());
                bool       have_subtags = ((tag_name16 & 1) != 0);
                ECTagNames tag_name     = (ECTagNames)(tag_name16 >> 1);

                byte  tag_type8            = br.ReadByte();
                Int32 tag_size32           = System.Net.IPAddress.NetworkToHostOrder(br.ReadInt32());
                LinkedList <ecTag> subtags = null;

                if (have_subtags)
                {
                    subtags = ReadSubtags(br);
                }
                EcTagTypes tag_type = (EcTagTypes)tag_type8;

                switch (tag_type)
                {
                case EcTagTypes.EC_TAGTYPE_UNKNOWN:
                    break;

                case EcTagTypes.EC_TAGTYPE_CUSTOM:
                    t = new ecTagCustom(tag_name, tag_size32, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_UINT8:
                    t = new ecTagInt(tag_name, 1, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_UINT16:
                    t = new ecTagInt(tag_name, 2, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_UINT32:
                    t = new ecTagInt(tag_name, 4, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_UINT64:
                    t = new ecTagInt(tag_name, 8, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_STRING:
                    t = new ecTagString(tag_name, tag_size32, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_DOUBLE:
                    break;

                case EcTagTypes.EC_TAGTYPE_IPV4:
                    t = new ecTagIPv4(tag_name, br, subtags);
                    break;

                case EcTagTypes.EC_TAGTYPE_HASH16:
                    t = new ecTagMD5(tag_name, br, subtags);
                    break;

                default:
                    break;
                }
                if (t == null)
                {
                    throw new Exception("Unexpected tag type");
                }
                return(t);
            }
Exemple #8
0
 public ecTagString(ECTagNames n, string s)
     : base(n, EcTagTypes.EC_TAGTYPE_STRING)
 {
     m_val  = System.Text.Encoding.UTF8.GetBytes(s);
     m_size = m_val.GetLength(0) + 1;
 }
Exemple #9
0
 public ecTagCustom(ECTagNames n, Int32 tag_size, BinaryReader br, LinkedList <ecTag> subtags)
     : base(n, EcTagTypes.EC_TAGTYPE_CUSTOM, subtags)
 {
     m_val  = br.ReadBytes(tag_size);
     m_size = tag_size;
 }
Exemple #10
0
 public ecTagInt(ECTagNames n, byte v)
     : base(n, EcTagTypes.EC_TAGTYPE_UINT8)
 {
     m_val  = v;
     m_size = 1;
 }
Exemple #11
0
 public ecTagMD5(ECTagNames name, byte[] hash_data)
     : base(name, EcTagTypes.EC_TAGTYPE_HASH16)
 {
     m_val  = hash_data;
     m_size = 16;
 }
Exemple #12
0
 public ecTagMD5(ECTagNames n, ecMD5 value)
     : base(n, EcTagTypes.EC_TAGTYPE_HASH16)
 {
     m_val  = value.ByteValue();
     m_size = 16;
 }
Exemple #13
0
 public ecTagInt(ECTagNames n, Int64 v)
     : base(n, EcTagTypes.EC_TAGTYPE_UINT64)
 {
     m_val  = v;
     m_size = 8;
 }
Exemple #14
0
 public ecTagInt(ECTagNames n, Int32 v)
     : base(n, EcTagTypes.EC_TAGTYPE_UINT32)
 {
     m_val  = v;
     m_size = 4;
 }
Exemple #15
0
 public ecTagInt(ECTagNames n, Int16 v)
     : base(n, EcTagTypes.EC_TAGTYPE_UINT16)
 {
     m_val  = v;
     m_size = 2;
 }
Exemple #16
0
 public ecTag(ECTagNames n, EcTagTypes t, LinkedList <ecTag> subtags)
 {
     m_name    = n;
     m_type    = t;
     m_subtags = subtags;;
 }
Exemple #17
0
 public amuleGenericContainer(ECOpCodes req_cmd, ECTagNames item_tagname, IContainerUI owner)
 {
     m_owner        = owner;
     m_req_cmd      = req_cmd;
     m_item_tagname = item_tagname;
 }
Exemple #18
0
 public ecTagMD5(ECTagNames name, BinaryReader br, LinkedList <ecTag> subtags)
     : base(name, EcTagTypes.EC_TAGTYPE_HASH16, subtags)
 {
     m_size = 16;
     m_val  = br.ReadBytes(16);
 }