public CReceiveHello(bool bRespuesta, MemoryStream buffer) { int emuleinfo = 0; AllowViewSharedFiles = true; IDClientCompatible = 0; VersionUDP = 0; VersionComments = 0; VersionCompression = 0; VersioneMuleMinor = 0; VersioneMuleRevision = 0; VersioneMuleMajor = 0; VersionExtendedRequests = 0; VersionLphant = 0; VersionSourceExchange = 0; PortUDP = 0; PartnerAllowed = false; SupportsPartner = false; BinaryReader reader = new BinaryReader(buffer); ExtendedInfoComplete = false; if (bRespuesta) HashSize = 16; else HashSize = reader.ReadByte(); Hash = reader.ReadBytes(HashSize); software = (byte)Protocol.Client.eDonkey; if ((Hash[5] == 14) && (Hash[14] == 111)) { software = (byte)Protocol.Client.eMule; } UserID = reader.ReadUInt32(); UserPort = reader.ReadUInt16(); uint nParametros = reader.ReadUInt32(); UserName = ""; Version = 0; for (int i = 0; i != nParametros; i++) { CParameterReader ParameterReader = new CParameterReader(reader); switch ((Protocol.ClientParameter)ParameterReader.id) { case Protocol.ClientParameter.Name: UserName = ParameterReader.valorString; break; case Protocol.ClientParameter.Version: Version = ParameterReader.valorNum; break; case Protocol.ClientParameter.Port: UserPort = (ushort)ParameterReader.valorNum; break; case Protocol.ClientParameter.EmuleVersion: VersioneMuleMajor = ((ParameterReader.valorNum & 0x00FFFFFF) >> 17) & 0x7F; VersioneMuleMinor = ((ParameterReader.valorNum & 0x00FFFFFF) >> 10) & 0x7F; VersioneMuleRevision = ((ParameterReader.valorNum & 0x00FFFFFF) >> 7) & 0x07; //Revision=( (ParameterReader.valorNum & 0x00FFFFFF) >> 7) & 0x07; IDClientCompatible = (ParameterReader.valorNum >> 24); emuleinfo |= 4; break; case Protocol.ClientParameter.EmuleUDPPort: PortUDP = (ushort)ParameterReader.valorNum; emuleinfo |= 1; break; case Protocol.ClientParameter.Emule_MiscOptions1: VersionUDP = (byte)((ParameterReader.valorNum >> 4 * 6) & 0x0f); VersionCompression = (byte)((ParameterReader.valorNum >> 4 * 5) & 0x0f); //m_bySupportSecIdent = ((ParameterReader.valorNum >> 4*4) & 0x0f); VersionSourceExchange = (byte)((ParameterReader.valorNum >> 4 * 3) & 0x0f); VersionExtendedRequests = (byte)((ParameterReader.valorNum >> 4 * 2) & 0x0f); VersionComments = (byte)((ParameterReader.valorNum >> 4 * 1) & 0x0f); AllowViewSharedFiles = ((ParameterReader.valorNum >> 1 * 2) & 0x01) > 0; //m_bMultiPacket = (ParameterReader.valorNum >> 1*1) & 0x01; //m_fSupportsPreview = (ParameterReader.valorNum >> 1*0) & 0x01; emuleinfo |= 2; break; case Protocol.ClientParameter.EmuleCompatOptions: if ((ParameterReader.valorNum & 0x00000001) > 0) SupportsPartner = true; if ((ParameterReader.valorNum & 0x00000002) > 0) PartnerAllowed = true; break; } } ServerIP = reader.ReadUInt32(); ServerPort = reader.ReadUInt16(); if ((emuleinfo & 4) == 4) ExtendedInfoComplete = true; if (buffer.Length - buffer.Position >= 3) { software = (byte)Protocol.Client.eDonkeyHybrid; uint extra = reader.ReadUInt32(); if (extra == 1262767181) software = (byte)Protocol.Client.mlDonkey; } if ((IDClientCompatible == (byte)Protocol.Client.Hathi) && (VersioneMuleMajor > 0)) VersioneMuleMajor--; if (Version > 10000 && Version < 100000) Version = Version - (Version / 10000) * 10000; if (Version > 1000) Version = Version - (Version / 1000) * 1000; if (Version < 100) Version *= 10; reader.Close(); buffer.Close(); reader = null; buffer = null; }
public CMuleHello(MemoryStream buffer) { BinaryReader reader = new BinaryReader(buffer); VersioneMule = reader.ReadByte(); if (VersioneMule == 0x2B) VersioneMule = 0x22; VersionEmuleProtocol = reader.ReadByte(); if (VersionEmuleProtocol == Protocol.EMULE_PROTOCOL_VERSION) { if (VersioneMule < 0x25 && VersioneMule > 0x22) VersionUDP = 1; if (VersioneMule < 0x25 && VersioneMule > 0x21) VersionSourceExchange = 1; if (VersioneMule == 0x24) VersionComments = 1; } PortUDP = 0; VersionCompression = 0; VersionSourceExchange = 1; uint nParametros = reader.ReadUInt32(); if (VersionEmuleProtocol != Protocol.EMULE_PROTOCOL_VERSION) return; for (int i = 0; i != nParametros; i++) { CParameterReader ParameterReader = new CParameterReader(reader); switch (ParameterReader.id) { case Protocol.ET_COMPRESSION: VersionCompression = (byte)ParameterReader.valorNum; break; case Protocol.ET_UDPPORT: PortUDP = (ushort)ParameterReader.valorNum; break; case Protocol.ET_UDPVER: VersionUDP = (byte)ParameterReader.valorNum; break; case Protocol.ET_SOURCEEXCHANGE: VersionSourceExchange = (byte)ParameterReader.valorNum; break; case Protocol.ET_COMMENTS: VersionComments = (byte)ParameterReader.valorNum; break; case Protocol.ET_EXTENDEDREQUEST: VersionExtendedRequests = (byte)ParameterReader.valorNum; break; case Protocol.ET_COMPATIBLECLIENT: IDClientCompatible = ParameterReader.valorNum; break; case Protocol.ET_ELEPHANTVERSION: VersionLphant = ParameterReader.valorNum & 0x00FFFFFF; break; } } if (VersionCompression == 0) { VersionSourceExchange = 0; VersionExtendedRequests = 0; VersionComments = 0; PortUDP = 0; } reader.Close(); buffer.Close(); reader = null; buffer = null; }
/// <summary> /// Reads the server data from an BinaryReader. /// </summary> /// <param name="reader">Specify the BinaryReader to load the server data.</param> public void Load(BinaryReader reader) { uint parameters; CParameterReader parameterReader; parameters=reader.ReadUInt32(); for (uint i=0; i!=parameters; i++) { parameterReader=new CParameterReader(reader); switch ((Protocol.ServerTag)parameterReader.id) { case Protocol.ServerTag.Name: m_Name=parameterReader.valorString; break; case Protocol.ServerTag.Description: m_Description=parameterReader.valorString; break; case Protocol.ServerTag.Preference: m_Preference=(Constants.ServerPriority)parameterReader.valorNum; break; case Protocol.ServerTag.Ping: m_LastPingTime=parameterReader.valorNum; break; case Protocol.ServerTag.DynIP: m_DynamicIP=parameterReader.valorString; break; case Protocol.ServerTag.Fails: m_nFails=parameterReader.valorNum; break; case Protocol.ServerTag.MaxUsers: m_MaxUsers=parameterReader.valorNum; break; default: if (parameterReader.nombreParam==null) break; if (parameterReader.nombreParam.Equals("users")) m_Users=parameterReader.valorNum; else if (parameterReader.nombreParam.Equals("files")) m_Files=parameterReader.valorNum; break; } } }
private void m_LoadMetParameters(BinaryReader reader) { CParameterReader ParameterReader; uint nparameters=reader.ReadUInt32(); for (uint parameter=0; parameter!=nparameters; parameter++) { ParameterReader=new CParameterReader(reader); string parametername; byte parameterid; parametername=ParameterReader.nombreParam; parameterid = ParameterReader.id; switch ( (Protocol.FileTag)ParameterReader.id ) { case Protocol.FileTag.Name: m_FileName=ParameterReader.valorString; break; case Protocol.FileTag.Size: m_FileSize=ParameterReader.valorNum; break; case Protocol.FileTag.Priority: m_DownPriority=(Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.UploadPriority: m_UpPriority=(Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.Transfered: m_Transferred=ParameterReader.valorNum; break; case Protocol.FileTag.LastSeenComplete: m_LastSeenComplete=ParameterReader.valorNum; break; case Protocol.FileTag.State: m_FileStatus=(Protocol.FileState)ParameterReader.valorNum; break; case Protocol.FileTag.Comment: m_MyComment=ParameterReader.valorString; break; case Protocol.FileTag.Rating: m_MyRating=(byte)ParameterReader.valorNum; break; case Protocol.FileTag.CorruptedPart: if (m_CorruptedChunks == null) m_CorruptedChunks=new ArrayList(); m_CorruptedChunks.Add((int)ParameterReader.valorNum); break; case Protocol.FileTag.Category: m_CategoryID=ParameterReader.valorNum; break; default: if (!(ParameterReader.nombreParam == null)) { if ((byte)ParameterReader.nombreParam.ToCharArray()[0] == (byte)Protocol.FileTag.GapStart) { uint inicio_gap; inicio_gap=ParameterReader.valorNum; ParameterReader=new CParameterReader(reader); parameter++; if ((byte)ParameterReader.nombreParam.ToCharArray()[0]!=(byte)Protocol.FileTag.GapEnd) { //TODO: lanzar error en gap } else { uint fin_gap; fin_gap=ParameterReader.valorNum; //TODO: for next revision: m_AddGap(inicio_gap, fin_gap-1); //Debug.WriteLine("Gap:"+inicio_gap.ToString()+" : "+(fin_gap-1).ToString()); if (((byte)m_FileFormat==(byte)Protocol.PartMet.eDonkeyOld)&&(ParameterReader.nombreParam.IndexOf(" ")>0)) continue; m_AddGap(inicio_gap, fin_gap-1); //if (fin_gap>=m_FileSize) fin_gap=m_FileSize-1; //if ((fin_gap>=inicio_gap) && (fin_gap>=0) && (inicio_gap>=0) && (fin_gap<m_FileSize) && (inicio_gap<m_FileSize)) Gaps.Add((uint)inicio_gap, (uint)fin_gap); } } else m_UnknownParameters.Add(ParameterReader); } else m_UnknownParameters.Add(ParameterReader); break; //TODO: faltan los parameters para las estadisticas.... } } }
private uint m_ExtractResult(BinaryReader reader, CSearcher search) { CParameterReader parameterReader; byte[] HashEncontrado = reader.ReadBytes(16); uint ip = reader.ReadUInt32(); ushort port = reader.ReadUInt16(); uint nParametros = reader.ReadUInt32(); string fileName = "?"; uint fileSize = 0; uint nSources = 1; string codec = ""; uint bitrate = 0; string length = ""; bool complete = false; for (uint param = 0; param != nParametros; param++) { parameterReader = new CParameterReader(reader); switch ((Protocol.FileTag)parameterReader.id) { case Protocol.FileTag.Name: fileName = parameterReader.valorString; break; case Protocol.FileTag.Size: fileSize = parameterReader.valorNum; break; case Protocol.FileTag.Sources: nSources = parameterReader.valorNum; break; case Protocol.FileTag.Completed: complete = parameterReader.valorNum > 0; break; default: if (parameterReader.nombreParam == Protocol.FileExtraTags.codec.ToString()) codec = parameterReader.valorString; else if (parameterReader.nombreParam == Protocol.FileExtraTags.length.ToString()) length = parameterReader.valorString; else if (parameterReader.nombreParam == Protocol.FileExtraTags.bitrate.ToString()) bitrate = parameterReader.valorNum; //Debug.WriteLine(parameterReader.id+" name: "+parameterReader.nombreParam+" valString:"+parameterReader.valorString+" valNum: "+parameterReader.valorNum); break; } } if (fileSize < Protocol.PartSize) complete = true; search.AddFileFound(HashEncontrado, fileName, fileSize, nSources, codec, length, bitrate, complete, ip, port); return nSources; }
private bool m_LoadKnownFiles(string filefullpath,bool showErrorMessage) { FileStream knownmet=null; BinaryReader reader=null; if (filefullpath.Length==0) filefullpath=Application.StartupPath + "\\known.met"; try { knownmet=File.OpenRead(filefullpath); reader=new BinaryReader(knownmet); if ( !Enum.IsDefined( typeof(Protocol.KnownMet), reader.ReadByte() ) ) // if (reader.ReadByte() != 0x0E) { reader.Close(); knownmet.Close(); CLog.Log(Constants.Log.Notify,"KNWMET_INVALID"); return false; } int nFiles=reader.ReadInt32(); m_KnownMetList=new Hashtable(nFiles); for (uint i=0; i!=nFiles; i++) { CKnownFileAttributes attributesKnownFile=new CKnownFileAttributes(); attributesKnownFile.Date=new DateTime(((long)reader.ReadUInt32()*10000000L)+621355968000000000L); attributesKnownFile.FileHash=reader.ReadBytes(16); ushort nChunks=reader.ReadUInt16(); attributesKnownFile.HashSet=new ArrayList(nChunks); for (uint chunk=0; chunk!=nChunks; chunk++) { attributesKnownFile.HashSet.Add(reader.ReadBytes(16)); } CParameterReader ParameterReader; uint nparameters=reader.ReadUInt32(); for (uint parameter=0; parameter!=nparameters; parameter++) { ParameterReader=new CParameterReader(reader); switch ( (Protocol.FileTag)ParameterReader.id ) { case Protocol.FileTag.Name: attributesKnownFile.FileName=ParameterReader.valorString; break; case Protocol.FileTag.Size: attributesKnownFile.Size=ParameterReader.valorNum; break; case Protocol.FileTag.Priority: attributesKnownFile.Priority=(Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.Permissions: attributesKnownFile.Permisions=(byte)ParameterReader.valorNum; break; case Protocol.FileTag.Comment: attributesKnownFile.Comment=ParameterReader.valorString; break; case Protocol.FileTag.Rating: attributesKnownFile.Rating=(byte)ParameterReader.valorNum; break; default: break; //faltan los parametros para las estadisticas.... } } if (!m_KnownMetList.ContainsKey(attributesKnownFile.FileName+(attributesKnownFile.Date.Ticks/10000000L).ToString())) m_KnownMetList.Add(attributesKnownFile.FileName+(attributesKnownFile.Date.Ticks/10000000L).ToString(),attributesKnownFile); } reader.Close(); knownmet.Close(); return true; } catch (Exception e) { Debug.WriteLine(e.ToString()); if (showErrorMessage) CLog.Log(Constants.Log.Notify,"Can not load known.met, hashing shared files"); try { if (reader!=null) reader.Close(); if (knownmet!=null) knownmet.Close(); } catch {}; return false; } }