Improved exception messages

This commit is contained in:
Tal Aloni 2017-09-25 18:32:25 +03:00
parent e287129571
commit 5e71f927a2
4 changed files with 14 additions and 14 deletions

View file

@ -81,7 +81,7 @@ namespace SMBLibrary.NetBios
case SessionPacketTypeName.SessionKeepAlive:
return new SessionKeepAlivePacket(buffer, offset);
default:
throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + type.ToString("X"));
throw new InvalidDataException("Invalid NetBIOS session packet type: 0x" + type.ToString("X2"));
}
}
}

View file

@ -158,7 +158,7 @@ namespace SMBLibrary.SMB1
case CommandName.SMB_COM_NT_CANCEL:
return new NTCancelRequest(buffer, offset);
default:
throw new NotImplementedException("SMB Command 0x" + commandName.ToString("X"));
throw new InvalidDataException("Invalid SMB command 0x" + commandName.ToString("X2"));
}
}
@ -465,7 +465,7 @@ namespace SMBLibrary.SMB1
}
}
default:
throw new NotImplementedException("SMB Command 0x" + commandName.ToString("X"));
throw new InvalidDataException("Invalid SMB command 0x" + commandName.ToString("X2"));
}
}

View file

@ -64,8 +64,8 @@ namespace SMBLibrary.SMB2
public static SMB2Command ReadRequest(byte[] buffer, int offset)
{
SMB2CommandName command = (SMB2CommandName)LittleEndianConverter.ToUInt16(buffer, offset + 12);
switch (command)
SMB2CommandName commandName = (SMB2CommandName)LittleEndianConverter.ToUInt16(buffer, offset + 12);
switch (commandName)
{
case SMB2CommandName.Negotiate:
return new NegotiateRequest(buffer, offset);
@ -104,7 +104,7 @@ namespace SMBLibrary.SMB2
case SMB2CommandName.SetInfo:
return new SetInfoRequest(buffer, offset);
default:
throw new InvalidDataException("Invalid SMB2 command in buffer");
throw new InvalidDataException("Invalid SMB2 command 0x" + commandName.ToString("X4"));
}
}
@ -178,9 +178,9 @@ namespace SMBLibrary.SMB2
public static SMB2Command ReadResponse(byte[] buffer, int offset)
{
SMB2CommandName command = (SMB2CommandName)LittleEndianConverter.ToUInt16(buffer, offset + 12);
SMB2CommandName commandName = (SMB2CommandName)LittleEndianConverter.ToUInt16(buffer, offset + 12);
ushort structureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
switch (command)
switch (commandName)
{
case SMB2CommandName.Negotiate:
{
@ -471,7 +471,7 @@ namespace SMBLibrary.SMB2
}
}
default:
throw new InvalidDataException("Invalid SMB2 command in buffer");
throw new InvalidDataException("Invalid SMB2 command 0x" + commandName.ToString("X4"));
}
}

View file

@ -220,7 +220,7 @@ namespace SMBLibrary.Win32.Security
}
if (result != SEC_E_OK)
{
throw new Exception("AcquireCredentialsHandle failed, Error code 0x" + result.ToString("X"));
throw new Exception("AcquireCredentialsHandle failed, Error code 0x" + result.ToString("X8"));
}
return credential;
@ -253,7 +253,7 @@ namespace SMBLibrary.Win32.Security
}
else
{
throw new Exception("InitializeSecurityContext failed, Error code 0x" + result.ToString("X"));
throw new Exception("InitializeSecurityContext failed, Error code 0x" + result.ToString("X8"));
}
}
FreeCredentialsHandle(ref credentialsHandle);
@ -290,7 +290,7 @@ namespace SMBLibrary.Win32.Security
}
else
{
throw new Exception("InitializeSecurityContext failed, Error code 0x" + result.ToString("X"));
throw new Exception("InitializeSecurityContext failed, Error code 0x" + result.ToString("X8"));
}
}
byte[] messageBytes = output.GetBufferBytes(0);
@ -329,7 +329,7 @@ namespace SMBLibrary.Win32.Security
}
else
{
throw new Exception("AcceptSecurityContext failed, Error code 0x" + result.ToString("X"));
throw new Exception("AcceptSecurityContext failed, Error code 0x" + result.ToString("X8"));
}
}
FreeCredentialsHandle(ref credentialsHandle);
@ -394,7 +394,7 @@ namespace SMBLibrary.Win32.Security
}
else
{
throw new Exception("AcceptSecurityContext failed, Error code 0x" + result.ToString("X"));
throw new Exception("AcceptSecurityContext failed, Error code 0x" + result.ToString("X8"));
}
}
}