Ejemplo n.º 1
0
Archivo: Name.cs Proyecto: zxz2020/Emby
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            //return "";

            string n = name;

            // fix MSBROWSE name
            if (n == null)
            {
                n = "null";
            }
            else
            {
                if (n[0] == unchecked (0x01))
                {
                    char[] c = n.ToCharArray();
                    c[0]  = '.';
                    c[1]  = '.';
                    c[14] = '.';
                    n     = new string(c);
                }
            }
            sb.Append(n).Append("<").Append(Hexdump.ToHexString(HexCode, 2)).Append(">");
            if (Scope != null)
            {
                sb.Append(".").Append(Scope);
            }
            return(sb.ToString());
        }
Ejemplo n.º 2
0
 public override string ToString()
 {
     return("Trans2QueryPathInformation["
            + base.ToString()
            + ",informationLevel=0x" + Hexdump.ToHexString(_informationLevel, 3)
            + ",filename=" + Path + "]");
 }
Ejemplo n.º 3
0
        public override string ToString()
        {
            string ret = "NtlmContext[auth=" + Auth + ",ntlmsspFlags=0x" + Hexdump.ToHexString
                             (NtlmsspFlags, 8) + ",workstation=" + Workstation + ",isEstablished=" + isEstablished
                         + ",state=" + State + ",serverChallenge=";

            if (ServerChallenge == null)
            {
                ret += "null";
            }
            else
            {
                ret += Hexdump.ToHexString(ServerChallenge, 0, ServerChallenge.Length * 2);
            }
            ret += ",signingKey=";
            if (SigningKey == null)
            {
                ret += "null";
            }
            else
            {
                ret += Hexdump.ToHexString(SigningKey, 0, SigningKey.Length * 2);
            }
            ret += "]";
            return(ret);
        }
Ejemplo n.º 4
0
 public override string ToString()
 {
     return("LM_COMPATIBILITY=" + SmbConstants.LmCompatibility
            + " MacSigningKey=" + Hexdump.ToHexString(_macSigningKey,
                                                      0,
                                                      _macSigningKey.Length));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Return the numeric representation of this sid such as
        /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
        /// </summary>
        /// <remarks>
        /// Return the numeric representation of this sid such as
        /// <tt>S-1-5-21-1496946806-2192648263-3843101252-1029</tt>.
        /// </remarks>
        public override string ToString()
        {
            string ret = "S-" + (Revision & unchecked (0xFF)) + "-";

            if (IdentifierAuthority[0] != unchecked (0) || IdentifierAuthority[1] != unchecked (
                    0))
            {
                ret += "0x";
                ret += Hexdump.ToHexString(IdentifierAuthority, 0, 6);
            }
            else
            {
                int  shift = 0;
                long id    = 0;
                for (int i = 5; i > 1; i--)
                {
                    id    += (IdentifierAuthority[i] & unchecked (0xFFL)) << shift;
                    shift += 8;
                }
                ret += id;
            }
            for (int i1 = 0; i1 < SubAuthorityCount; i1++)
            {
                ret += "-" + (SubAuthority[i1] & unchecked (0xFFFFFFFFL));
            }
            return(ret);
        }
Ejemplo n.º 6
0
 public override string ToString()
 {
     return("Trans2FindNext2[" + base.ToString() + ",sid=" + _sid + ",searchCount="
            + Smb.Trans2FindFirst2.ListSize + ",informationLevel=0x" + Hexdump.ToHexString(_informationLevel
                                                                                           , 3) + ",resumeKey=0x" + Hexdump.ToHexString(_resumeKey, 4) + ",flags=0x" + Hexdump
            .ToHexString(_flags, 2) + ",filename=" + _filename + "]");
 }
Ejemplo n.º 7
0
        internal static string GetMessageByDcerpcError(int errcode)
        {
            int min = 0;
            int max = DcerpcError.DcerpcFaultCodes.Length;

            while (max >= min)
            {
                int mid = (min + max) / 2;
                if (errcode > DcerpcError.DcerpcFaultCodes[mid])
                {
                    min = mid + 1;
                }
                else
                {
                    if (errcode < DcerpcError.DcerpcFaultCodes[mid])
                    {
                        max = mid - 1;
                    }
                    else
                    {
                        return(DcerpcError.DcerpcFaultMessages[mid]);
                    }
                }
            }
            return("0x" + Hexdump.ToHexString(errcode, 8));
        }
 public override string ToString()
 {
     return("NtTransQuerySecurityDesc["
            + base.ToString()
            + ",fid=0x" + Hexdump.ToHexString(Fid, 4)
            + ",securityInformation=0x" + Hexdump.ToHexString(SecurityInformation, 8)
            + "]");
 }
Ejemplo n.º 9
0
 public override string ToString()
 {
     return("SmbComQueryInformationResponse["
            + base.ToString()
            + ",fileAttributes=0x" + Hexdump.ToHexString(_fileAttributes, 4)
            + ",lastWriteTime=" + Extensions.CreateDate(_lastWriteTime)
            + ",fileSize=" + _fileSize + "]");
 }
Ejemplo n.º 10
0
 public override string ToString()
 {
     return("SmbComRename["
            + base.ToString()
            + ",searchAttributes=0x" + Hexdump.ToHexString(_searchAttributes, 4)
            + ",oldFileName=" + _oldFileName
            + ",newFileName=" + _newFileName + "]");
 }
Ejemplo n.º 11
0
 public override string ToString()
 {
     return("Trans2FindFirst2[" + base.ToString() + ",searchAttributes=0x"
            + Hexdump.ToHexString(_searchAttributes, 2) + ",searchCount=" + ListCount + ",flags=0x"
            + Hexdump.ToHexString(_flags, 2) + ",informationLevel=0x" + Hexdump.ToHexString(
                _informationLevel, 3) + ",searchStorageType=" + _searchStorageType + ",filename="
            + Path + "]");
 }
 public override string ToString()
 {
     return("SmbQueryFileBasicInfo[" + "createTime=" + Extensions.CreateDate
                (CreateTime) + ",lastAccessTime=" + Extensions.CreateDate(LastAccessTime
                                                                          ) + ",lastWriteTime=" + Extensions.CreateDate(LastWriteTime) + ",changeTime="
            + Extensions.CreateDate(ChangeTime) + ",attributes=0x" + Hexdump.ToHexString
                (Attributes, 4) + "]");
 }
Ejemplo n.º 13
0
        internal virtual string ReadString(byte[] src, int srcIndex, int maxLen, bool useUnicode
                                           )
        {
            int    len = 0;
            string str = null;

            try
            {
                if (useUnicode)
                {
                    // Unicode requires word alignment
                    if (((srcIndex - HeaderStart) % 2) != 0)
                    {
                        srcIndex++;
                    }
                    while (src[srcIndex + len] != 0x00 || src[srcIndex
                                                              + len + 1] != 0x00)
                    {
                        len += 2;
                        if (len > maxLen)
                        {
                            if (Log.Level > 0)
                            {
                                Hexdump.ToHexdump(LogStream.GetInstance(), src, srcIndex, maxLen < 128 ? maxLen + 8 :
                                                  128);
                            }
                            throw new RuntimeException("zero termination not found");
                        }
                    }
                    str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.UniEncoding);
                }
                else
                {
                    while (src[srcIndex + len] != 0x00)
                    {
                        len++;
                        if (len > maxLen)
                        {
                            if (Log.Level > 0)
                            {
                                Hexdump.ToHexdump(LogStream.GetInstance(), src, srcIndex, maxLen < 128 ? maxLen + 8 :
                                                  128);
                            }
                            throw new RuntimeException("zero termination not found");
                        }
                    }
                    str = Runtime.GetStringForBytes(src, srcIndex, len, SmbConstants.OemEncoding);
                }
            }
            catch (UnsupportedEncodingException uee)
            {
                if (Log.Level > 1)
                {
                    Runtime.PrintStackTrace(uee, Log);
                }
            }
            return(str);
        }
Ejemplo n.º 14
0
        public virtual void Run()
        {
            int nameTrnId;
            NameServicePacket response;

            try
            {
                while (_thread == Thread.CurrentThread())
                {
                    _socket.SoTimeOut = _closeTimeout;

                    int len = _socket.Receive(_rcvBuf, 0, RcvBufSize);

                    if (_log.Level > 3)
                    {
                        _log.WriteLine("NetBIOS: new data read from socket");
                    }
                    nameTrnId = NameServicePacket.ReadNameTrnId(_rcvBuf, 0);
                    response  = (NameServicePacket)_responseTable.Get(nameTrnId);


                    if (response == null || response.Received)
                    {
                        continue;
                    }

                    lock (response)
                    {
                        response.ReadWireFormat(_rcvBuf, 0);

                        if (_log.Level > 3)
                        {
                            _log.WriteLine(response);
                            Hexdump.ToHexdump(_log, _rcvBuf, 0, len);
                        }

                        if (response.IsResponse)
                        {
                            response.Received = true;

                            Runtime.Notify(response);
                        }
                    }
                }
            }
            catch (TimeoutException) { }
            catch (Exception ex)
            {
                if (_log.Level > 2)
                {
                    Runtime.PrintStackTrace(ex, _log);
                }
            }
            finally
            {
                TryClose();
            }
        }
Ejemplo n.º 15
0
        /// <exception cref="SharpCifs.Smb.SmbException"></exception>
        public SigningDigest(SmbTransport transport, NtlmPasswordAuthentication auth)
        {
            try
            {
                _digest = MessageDigest.GetInstance("MD5");
            }
            catch (NoSuchAlgorithmException ex)
            {
                if (Log.Level > 0)
                {
                    Runtime.PrintStackTrace(ex, Log);
                }
                throw new SmbException("MD5", ex);
            }
            try
            {
                switch (SmbConstants.LmCompatibility)
                {
                case 0:
                case 1:
                case 2:
                {
                    _macSigningKey = new byte[40];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
                               , 16, 24);
                    break;
                }

                case 3:
                case 4:
                case 5:
                {
                    _macSigningKey = new byte[16];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    break;
                }

                default:
                {
                    _macSigningKey = new byte[40];
                    auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
                    Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
                               , 16, 24);
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new SmbException(string.Empty, ex);
            }
            if (Log.Level >= 5)
            {
                Log.WriteLine("LM_COMPATIBILITY=" + SmbConstants.LmCompatibility);
                Hexdump.ToHexdump(Log, _macSigningKey, 0, _macSigningKey.Length);
            }
        }
Ejemplo n.º 16
0
        public override string ToString()
        {
            string suppliedDomain      = GetSuppliedDomain();
            string suppliedWorkstation = GetSuppliedWorkstation();

            return("Type1Message[suppliedDomain=" + (suppliedDomain ?? "null")
                   + ",suppliedWorkstation=" + (suppliedWorkstation ?? "null")
                   + ",flags=0x" + Hexdump.ToHexString(GetFlags(), 8) + "]");
        }
Ejemplo n.º 17
0
        /// <exception cref="System.IO.IOException"></exception>
        protected internal override void DoRecv(Response response)
        {
            ServerMessageBlock resp = (ServerMessageBlock)response;

            resp.UseUnicode       = UseUnicode;
            resp.ExtendedSecurity = (Capabilities & SmbConstants.CapExtendedSecurity) == SmbConstants.CapExtendedSecurity;
            lock (Buf)
            {
                Array.Copy(Sbuf, 0, Buf, 0, 4 + SmbConstants.HeaderLength);
                int size = Encdec.Dec_uint16be(Buf, 2) & 0xFFFF;
                if (size < (SmbConstants.HeaderLength + 1) || (4 + size) > RcvBufSize)
                {
                    throw new IOException("Invalid payload size: " + size);
                }
                int errorCode = Encdec.Dec_uint32le(Buf, 9) & unchecked ((int)(0xFFFFFFFF));
                if (resp.Command == ServerMessageBlock.SmbComReadAndx && (errorCode == 0 || errorCode
                                                                          == unchecked ((int)(0x80000005))))
                {
                    // overflow indicator normal for pipe
                    SmbComReadAndXResponse r = (SmbComReadAndXResponse)resp;
                    int off = SmbConstants.HeaderLength;
                    Readn(In, Buf, 4 + off, 27);
                    off += 27;
                    resp.Decode(Buf, 4);
                    int pad = r.DataOffset - off;
                    if (r.ByteCount > 0 && pad > 0 && pad < 4)
                    {
                        Readn(In, Buf, 4 + off, pad);
                    }
                    if (r.DataLength > 0)
                    {
                        Readn(In, r.B, r.Off, r.DataLength);
                    }
                }
                else
                {
                    Readn(In, Buf, 4 + 32, size - 32);
                    resp.Decode(Buf, 4);
                    if (resp is SmbComTransactionResponse)
                    {
                        ((SmbComTransactionResponse)resp).Current();
                    }
                }
                if (Digest != null && resp.ErrorCode == 0)
                {
                    Digest.Verify(Buf, 4, resp);
                }
                if (Log.Level >= 4)
                {
                    Log.WriteLine(response);
                    if (Log.Level >= 6)
                    {
                        Hexdump.ToHexdump(Log, Buf, 4, size);
                    }
                }
            }
        }
Ejemplo n.º 18
0
 public override string ToString()
 {
     return("ServerInfo1["
            + "name=" + Name
            + ",versionMajor=" + VersionMajor
            + ",versionMinor=" + VersionMinor
            + ",type=0x" + Hexdump.ToHexString(Type, 8)
            + ",commentOrMasterBrowser=" + CommentOrMasterBrowser + "]");
 }
Ejemplo n.º 19
0
 public override string ToString()
 {
     return("SmbComOpenAndX[" + base.ToString() + ",flags=0x" + Hexdump.ToHexString
                (flags, 2) + ",desiredAccess=0x" + Hexdump.ToHexString(DesiredAccess, 4) + ",searchAttributes=0x"
            + Hexdump.ToHexString(SearchAttributes, 4) + ",fileAttributes=0x" + Hexdump.ToHexString
                (FileAttributes, 4) + ",creationTime=" + Extensions.CreateDate(CreationTime
                                                                               ) + ",openFunction=0x" + Hexdump.ToHexString(OpenFunction, 2) + ",allocationSize="
            + AllocationSize + ",fileName=" + Path + "]");
 }
Ejemplo n.º 20
0
 internal static string GetMessageByCode(int errcode)
 {
     if (errcode == 0)
     {
         return("NT_STATUS_SUCCESS");
     }
     if ((errcode & unchecked ((int)(0xC0000000))) == unchecked ((int)(0xC0000000)))
     {
         int min = 1;
         int max = NtStatus.NtStatusCodes.Length - 1;
         while (max >= min)
         {
             int mid = (min + max) / 2;
             if (errcode > NtStatus.NtStatusCodes[mid])
             {
                 min = mid + 1;
             }
             else
             {
                 if (errcode < NtStatus.NtStatusCodes[mid])
                 {
                     max = mid - 1;
                 }
                 else
                 {
                     return(NtStatus.NtStatusMessages[mid]);
                 }
             }
         }
     }
     else
     {
         int min = 0;
         int max = DosError.DosErrorCodes.Length - 1;
         while (max >= min)
         {
             int mid = (min + max) / 2;
             if (errcode > DosError.DosErrorCodes[mid][0])
             {
                 min = mid + 1;
             }
             else
             {
                 if (errcode < DosError.DosErrorCodes[mid][0])
                 {
                     max = mid - 1;
                 }
                 else
                 {
                     return(DosError.DosErrorMessages[mid]);
                 }
             }
         }
     }
     return("0x" + Hexdump.ToHexString(errcode, 8));
 }
Ejemplo n.º 21
0
        /// <summary>Return a string represeting this ACE.</summary>
        /// <remarks>
        /// Return a string represeting this ACE.
        /// <p>
        /// Note: This function should probably be changed to return SDDL
        /// fragments but currently it does not.
        /// </remarks>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(IsAllow() ? "Allow " : "Deny  ");
            AppendCol(sb, Sid.ToDisplayString(), 25);
            sb.Append(" 0x").Append(Hexdump.ToHexString(Access, 8)).Append(' ');
            sb.Append(IsInherited() ? "Inherited " : "Direct    ");
            AppendCol(sb, GetApplyToText(), 34);
            return(sb.ToString());
        }
Ejemplo n.º 22
0
 public override string ToString()
 {
     return("SmbComNTCreateAndXResponse[" + base.ToString() + ",oplockLevel="
            + OplockLevel + ",fid=" + Fid + ",createAction=0x" + Hexdump.ToHexString(CreateAction
                                                                                     , 4) + ",creationTime=" + Extensions.CreateDate(CreationTime) + ",lastAccessTime="
            + Extensions.CreateDate(LastAccessTime) + ",lastWriteTime=" + Extensions.CreateDate
                (LastWriteTime) + ",changeTime=" + Extensions.CreateDate(ChangeTime) + ",extFileAttributes=0x"
            + Hexdump.ToHexString(ExtFileAttributes, 4) + ",allocationSize=" + AllocationSize
            + ",endOfFile=" + EndOfFile + ",fileType=" + FileType + ",deviceState=" + DeviceState
            + ",directory=" + Directory + "]");
 }
Ejemplo n.º 23
0
 public override string ToString()
 {
     return(base.ToString() + ",totalParameterCount=" + TotalParameterCount
            + ",totalDataCount=" + TotalDataCount + ",maxParameterCount=" + MaxParameterCount
            + ",maxDataCount=" + MaxDataCount + ",maxSetupCount=" + (int)MaxSetupCount + ",flags=0x"
            + Hexdump.ToHexString(_flags, 2) + ",timeout=" + Timeout + ",parameterCount=" +
            ParameterCount + ",parameterOffset=" + ParameterOffset + ",parameterDisplacement="
            + ParameterDisplacement + ",dataCount=" + DataCount + ",dataOffset=" + DataOffset
            + ",dataDisplacement=" + DataDisplacement + ",setupCount=" + SetupCount + ",pad="
            + _pad + ",pad1=" + _pad1);
 }
Ejemplo n.º 24
0
 public override string ToString()
 {
     return("SmbComNTCreateAndX[" + base.ToString() + ",flags=0x" + Hexdump
            .ToHexString(Flags0, 2) + ",rootDirectoryFid=" + _rootDirectoryFid + ",desiredAccess=0x"
            + Hexdump.ToHexString(DesiredAccess, 4) + ",allocationSize=" + _allocationSize +
            ",extFileAttributes=0x" + Hexdump.ToHexString(_extFileAttributes, 4) + ",shareAccess=0x"
            + Hexdump.ToHexString(_shareAccess, 4) + ",createDisposition=0x" + Hexdump.ToHexString
                (_createDisposition, 4) + ",createOptions=0x" + Hexdump.ToHexString(_createOptions
                                                                                    , 8) + ",impersonationLevel=0x" + Hexdump.ToHexString(_impersonationLevel, 4) + ",securityFlags=0x"
            + Hexdump.ToHexString(_securityFlags, 2) + ",name=" + Path + "]");
 }
Ejemplo n.º 25
0
 public virtual byte[] Digest()
 {
     byte[] b;
     b = _digest.Digest();
     if (Log.Level >= 5)
     {
         Log.WriteLine("digest: ");
         Hexdump.ToHexdump(Log, b, 0, b.Length);
     }
     _updates = 0;
     return(b);
 }
Ejemplo n.º 26
0
        public override string ToString()
        {
            string result = "SmbComTreeConnectAndX["
                            + base.ToString()
                            + ",disconnectTid=" + _disconnectTid
                            + ",passwordLength=" + _passwordLength
                            + ",password="******",path=" + path
                            + ",service=" + _service + "]";

            return(result);
        }
Ejemplo n.º 27
0
        public override string ToString()
        {
            string target = GetTarget();

            byte[] challenge         = GetChallenge();
            byte[] context           = GetContext();
            byte[] targetInformation = GetTargetInformation();
            return("Type2Message[target=" + target + ",challenge=" + (challenge == null ? "null"
                                 : "<" + challenge.Length + " bytes>") + ",context=" + (context == null ? "null"
                                 : "<" + context.Length + " bytes>") + ",targetInformation=" + (targetInformation
                                                                                                == null ? "null" : "<" + targetInformation.Length + " bytes>") + ",flags=0x" +
                   Hexdump.ToHexString(GetFlags(), 8) + "]");
        }
Ejemplo n.º 28
0
 public override string ToString()
 {
     return("SmbComNegotiateResponse[" + base.ToString() + ",wordCount=" +
            WordCount + ",dialectIndex=" + DialectIndex + ",securityMode=0x" + Hexdump.ToHexString
                (Server.SecurityMode, 1) + ",security=" + (Server.Security == SmbConstants.SecurityShare ? "share"
                          : "user") + ",encryptedPasswords=" + Server.EncryptedPasswords + ",maxMpxCount="
            + Server.MaxMpxCount + ",maxNumberVcs=" + Server.MaxNumberVcs + ",maxBufferSize="
            + Server.MaxBufferSize + ",maxRawSize=" + Server.MaxRawSize + ",sessionKey=0x"
            + Hexdump.ToHexString(Server.SessionKey, 8) + ",capabilities=0x" + Hexdump.ToHexString
                (Server.Capabilities, 8) + ",serverTime=" + Extensions.CreateDate(Server
                                                                                  .ServerTime) + ",serverTimeZone=" + Server.ServerTimeZone + ",encryptionKeyLength="
            + Server.EncryptionKeyLength + ",byteCount=" + ByteCount + ",oemDomainName=" +
            Server.OemDomainName + "]");
 }
Ejemplo n.º 29
0
 public virtual void Update(byte[] input, int offset, int len)
 {
     if (Log.Level >= 5)
     {
         Log.WriteLine("update: " + _updates + " " + offset + ":" + len);
         Hexdump.ToHexdump(Log, input, offset, Math.Min(len, 256));
     }
     if (len == 0)
     {
         return;
     }
     _digest.Update(input, offset, len);
     _updates++;
 }
Ejemplo n.º 30
0
 /// <summary>Retrieve all addresses of a host by it's address.</summary>
 /// <remarks>
 /// Retrieve all addresses of a host by it's address. NetBIOS hosts can
 /// have many names for a given IP address. The name and IP address make the
 /// NetBIOS address. This provides a way to retrieve the other names for a
 /// host with the same IP address.
 /// </remarks>
 /// <param name="addr">the address to query</param>
 /// <exception cref="UnknownHostException">if address cannot be resolved</exception>
 public static NbtAddress[] GetAllByAddress(NbtAddress addr)
 {
     try
     {
         NbtAddress[] addrs = Client.GetNodeStatus(addr);
         CacheAddressArray(addrs);
         return(addrs);
     }
     catch (UnknownHostException)
     {
         throw new UnknownHostException("no name with type 0x" + Hexdump.ToHexString(addr.
                                                                                     HostName.HexCode, 2) + (((addr.HostName.Scope == null) || (addr.HostName.Scope.Length
                                                                                                                                                == 0)) ? " with no scope" : " with scope " + addr.HostName.Scope) + " for host "
                                        + addr.GetHostAddress());
     }
 }